109
109
HighsInt Highs_changeColBounds(
110
110
void* highs, const HighsInt col, const double lower, const double upper
111
111
);
112
+ HighsInt Highs_changeCoeff(
113
+ void* highs, const HighsInt row, const HighsInt col, const double value
114
+ );
112
115
HighsInt Highs_getRowsByRange(
113
116
const void* highs, const HighsInt from_row, const HighsInt to_row,
114
117
HighsInt* num_row, double* lower, double* upper, HighsInt* num_nz,
@@ -260,6 +263,23 @@ def _set_bool_option_value(self: "SolverHighs", name: str, value: float):
260
263
self ._lib .Highs_setBoolOptionValue (self ._model , name .encode ("UTF-8" ), value )
261
264
)
262
265
266
+ def _change_coef (self : "SolverHighs" , row : int , col : int , value : float ):
267
+ "Overwrite a single coefficient in the matrix."
268
+ check (self ._lib .Highs_changeCoeff (self ._model , row , col , value ))
269
+
270
+ def _set_column (self : "SolverHighs" , col : int , column : "mip.Column" ):
271
+ "Overwrite coefficients of one column."
272
+ # We also have to set to 0 all coefficients of the old column, so we
273
+ # fetch that first.
274
+ var = self .model .vars [col ]
275
+ old_column = self .var_get_column (var )
276
+ coeffs = {cons .idx : 0.0 for cons in old_column .constrs }
277
+ coeffs .update (
278
+ {cons .idx : coef for cons , coef in zip (column .constrs , column .coeffs )}
279
+ )
280
+ for row , coef in coeffs .items ():
281
+ self ._change_coef (row , col , coef )
282
+
263
283
def add_var (
264
284
self : "SolverHighs" ,
265
285
obj : numbers .Real = 0 ,
@@ -269,7 +289,6 @@ def add_var(
269
289
column : "mip.Column" = None ,
270
290
name : str = "" ,
271
291
):
272
- # TODO: handle column data
273
292
col : int = self .num_cols ()
274
293
check (self ._lib .Highs_addVar (self ._model , lb , ub ))
275
294
check (self ._lib .Highs_changeColCost (self ._model , col , obj ))
@@ -280,6 +299,9 @@ def add_var(
280
299
)
281
300
)
282
301
302
+ if column :
303
+ self ._set_column (col , column )
304
+
283
305
# store name & type
284
306
self ._var_name .append (name )
285
307
self ._var_col [name ] = col
@@ -852,8 +874,7 @@ def var_get_column(self: "SolverHighs", var: "mip.Var") -> "mip.Column":
852
874
)
853
875
854
876
def var_set_column (self : "SolverHighs" , var : "mip.Var" , value : "mip.Column" ):
855
- # TODO
856
- raise NotImplementedError ()
877
+ self ._set_column (var .idx , value )
857
878
858
879
def var_get_rc (self : "SolverHighs" , var : "mip.Var" ) -> numbers .Real :
859
880
if self ._rc :
0 commit comments