@@ -720,7 +720,7 @@ def __init__(self, model: mip.Model, name: str, sense: str):
720720 # Buffer string for storing names
721721 self ._name_buffer = ffi .new (f"char[{ self ._lib .kHighsMaximumStringLength } ]" )
722722
723- # type conversion maps
723+ # type conversion maps (can not distinguish binary from integer!)
724724 self ._var_type_map = {
725725 mip .CONTINUOUS : self ._lib .kHighsVarTypeContinuous ,
726726 mip .BINARY : self ._lib .kHighsVarTypeInteger ,
@@ -760,8 +760,8 @@ def _get_double_option_value(self: "SolverHighs", name: str) -> float:
760760 )
761761 return value [0 ]
762762
763- def _get_bool_option_value (self : "SolverHighs" , name : str ) -> float :
764- value = ffi .new ("bool *" )
763+ def _get_bool_option_value (self : "SolverHighs" , name : str ) -> int :
764+ value = ffi .new ("int *" )
765765 check (
766766 self ._lib .Highs_getBoolOptionValue (self ._model , name .encode ("UTF-8" ), value )
767767 )
@@ -779,7 +779,7 @@ def _set_double_option_value(self: "SolverHighs", name: str, value: float):
779779 )
780780 )
781781
782- def _set_bool_option_value (self : "SolverHighs" , name : str , value : float ):
782+ def _set_bool_option_value (self : "SolverHighs" , name : str , value : int ):
783783 check (
784784 self ._lib .Highs_setBoolOptionValue (self ._model , name .encode ("UTF-8" ), value )
785785 )
@@ -815,6 +815,8 @@ def add_var(
815815 if name :
816816 check (self ._lib .Highs_passColName (self ._model , col , name .encode ("utf-8" )))
817817 if var_type != mip .CONTINUOUS :
818+ # Note that HiGHS doesn't distinguish binary and integer variables
819+ # by type. There is only a boolean flag for "integrality".
818820 self ._num_int_vars += 1
819821 check (
820822 self ._lib .Highs_changeColIntegrality (
@@ -1035,6 +1037,18 @@ def set_start(self: "SolverHighs", start: List[Tuple["mip.Var", numbers.Real]]):
10351037 self ._lib .Highs_setSolution (self ._model , cval , ffi .NULL , ffi .NULL , ffi .NULL )
10361038
10371039 def set_objective (self : "SolverHighs" , lin_expr : "mip.LinExpr" , sense : str = "" ):
1040+ # first reset old objective (all 0)
1041+ n = self .num_cols ()
1042+ costs = ffi .new ("double[]" , n ) # initialized to 0
1043+ check (
1044+ self ._lib .Highs_changeColsCostByRange (
1045+ self ._model ,
1046+ 0 , # from_col
1047+ n - 1 , # to_col
1048+ costs ,
1049+ )
1050+ )
1051+
10381052 # set coefficients
10391053 for var , coef in lin_expr .expr .items ():
10401054 check (self ._lib .Highs_changeColCost (self ._model , var .idx , coef ))
@@ -1518,7 +1532,11 @@ def remove_vars(self: "SolverHighs", varsList: List[int]):
15181532
15191533 def var_get_index (self : "SolverHighs" , name : str ) -> int :
15201534 idx = ffi .new ("int *" )
1521- self ._lib .Highs_getColByName (self ._model , name .encode ("utf-8" ), idx )
1535+ status = self ._lib .Highs_getColByName (self ._model , name .encode ("utf-8" ), idx )
1536+ if status == STATUS_ERROR :
1537+ # This means that no var with that name was found. Unfortunately,
1538+ # HiGHS::getColByName doesn't assign a value to idx in that case.
1539+ return - 1
15221540 return idx [0 ]
15231541
15241542 def get_problem_name (self : "SolverHighs" ) -> str :
0 commit comments