Skip to content

Commit 6fe5d58

Browse files
committed
getWeightsSOS1
1 parent 401f629 commit 6fe5d58

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/pyscipopt/scip.pxd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,8 +1594,6 @@ cdef extern from "scip/cons_sos1.h":
15941594

15951595
SCIP_Real* SCIPgetWeightsSOS1(SCIP* scip, SCIP_CONS* cons)
15961596

1597-
int SCIPgetNSOS1Vars(SCIP_CONSHDLR* conshdlr)
1598-
15991597
SCIP_RETCODE SCIPmakeSOS1Feasible(SCIP* scip,
16001598
SCIP_CONSHDLR* conshdlr,
16011599
SCIP_SOL* solution,

src/pyscipopt/scip.pxi

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6508,6 +6508,40 @@ cdef class Model:
65086508

65096509
return Constraint.create(scip_cons)
65106510

6511+
def getWeightsSOS1(self, Constraint cons):
6512+
"""
6513+
Retrieve the coefficients of an SOS1 constraint
6514+
6515+
Parameters
6516+
----------
6517+
cons : Constraint
6518+
SOS1 constraint to get the coefficients of
6519+
6520+
Returns
6521+
-------
6522+
dict of str to float
6523+
6524+
"""
6525+
cdef SCIP_VAR** vars
6526+
cdef SCIP_Longint* vals
6527+
cdef int nvars
6528+
cdef int i
6529+
6530+
constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8')
6531+
if not constype == 'SOS1':
6532+
raise Warning("weights not available for constraints of type ", constype)
6533+
6534+
nvars = SCIPgetNVarsSOS1(self._scip, cons.scip_cons)
6535+
vals = SCIPgetWeightsSOS1(self._scip, cons.scip_cons)
6536+
vars = SCIPgetVarsSOS1(self._scip, cons.scip_cons)
6537+
6538+
valsdict = {}
6539+
for i in range(nvars):
6540+
var_name = bytes(SCIPvarGetName(vars[i])).decode('utf-8')
6541+
valsdict[var_name] = vals[i]
6542+
6543+
return valsdict
6544+
65116545
def addConsSOS2(self, vars, weights=None, name="",
65126546
initial=True, separate=True, enforce=True, check=True,
65136547
propagate=True, local=False, dynamic=False,

0 commit comments

Comments
 (0)