Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def benderssolvesubconvex(self, solution, probnumber, onlyconvex):
self.model.setupBendersSubproblem(probnumber, self, solution)
self.subprob.solveProbingLP()
subprob = self.model.getBendersSubproblem(probnumber, self)
assert self.subprob.getObjVal() == subprob.getObjVal()
result_dict = {}
objective = subprob.infinity()
result = SCIP_RESULT.DIDNOTRUN
lpsolstat = self.subprob.getLPSolstat()
if lpsolstat == SCIP_LPSOLSTAT.OPTIMAL:
objective = self.subprob.getObjVal()
result = SCIP_RESULT.FEASIBLE
elif lpsolstat == SCIP_LPSOLSTAT.INFEASIBLE:
objective = self.subprob.infinity()
result = SCIP_RESULT.INFEASIBLE
elif lpsolstat == SCIP_LPSOLSTAT.UNBOUNDEDRAY:
objective = self.subprob.infinity()
result = SCIP_RESULT.UNBOUNDED
result_dict["objective"] = objective
result_dict["result"] = result
return result_dict
def benderssolvesubconvex(self, solution, probnumber, onlyconvex):
self.model.setupBendersSubproblem(probnumber, self, solution)
self.subprob.solveProbingLP()
subprob = self.model.getBendersSubproblem(probnumber, self)
assert self.subprob.getObjVal() == subprob.getObjVal()
result_dict = {}
objective = subprob.infinity()
result = SCIP_RESULT.DIDNOTRUN
lpsolstat = self.subprob.getLPSolstat()
if lpsolstat == SCIP_LPSOLSTAT.OPTIMAL:
objective = self.subprob.getObjVal()
result = SCIP_RESULT.FEASIBLE
elif lpsolstat == SCIP_LPSOLSTAT.INFEASIBLE:
objective = self.subprob.infinity()
result = SCIP_RESULT.INFEASIBLE
elif lpsolstat == SCIP_LPSOLSTAT.UNBOUNDEDRAY:
objective = self.subprob.infinity()
result = SCIP_RESULT.UNBOUNDED
result_dict["objective"] = objective
result_dict["result"] = result
return result_dict
def pricerredcost(self):
entering()
# stop pricing if limit for pricing rounds reached
if not self.keep_on_pricing():
print("maxrounds reached, pricing interrupted")
leaving()
return {'lowerbound' : self.lowerbound, 'result' : SCIP_RESULT.DIDNOTRUN }
# get dual solution
pi = {}
for n in self.model.graph.nodes_iter():
pi[n] = self.model.getDualsolLinear(self.model.constraints[n]) #TODO: should we receive model instead of storing it in Pricer?
# get current graph
G = getCurrentGraph(self.model)
# brute force (see NOTE 1) cliques of the complement are stable sets of the original
max_stable_value = 0
max_stable_set = []
for quotients_stable_set in networkx.enumerate_all_cliques(networkx.complement(G)):
# transform quotient's stable set to original's stable set
stable_set = quotient_to_parent(quotients_stable_set)
def branchexeclp(self, allowaddcons):
self.count += 1
if self.count >= 2:
return {"result": SCIP_RESULT.DIDNOTRUN}
assert allowaddcons
assert not self.model.inRepropagation()
assert not self.model.inProbing()
self.model.startProbing()
assert not self.model.isObjChangedProbing()
self.model.fixVarProbing(self.cont, 2.0)
self.model.constructLP()
self.model.solveProbingLP()
self.model.getLPObjVal()
self.model.endProbing()
self.integral = self.model.getLPBranchCands()[0][0]
if self.count == 1:
down, eq, up = self.model.branchVarVal(self.cont, 1.3)
def sepaexeclp(self):
result = SCIP_RESULT.DIDNOTRUN
scip = self.model
if not scip.isLPSolBasic():
return {"result": result}
#TODO: add SCIPgetNLPBranchCands
# get var data ---> this is the same as getVars!
vars = scip.getVars(transformed = True)
# get LP data
cols = scip.getLPColsData()
rows = scip.getLPRowsData()
# exit if LP is trivial
if len(cols) == 0 or len(rows) == 0:
return {"result": result}
def sepaexeclp(self):
result = SCIP_RESULT.DIDNOTRUN
scip = self.model
if not scip.isLPSolBasic():
return {"result": result}
#TODO: add SCIPgetNLPBranchCands
# get var data ---> this is the same as getVars!
vars,_,_,_,_ = scip.getVarsData()
# get LP data
cols = scip.getLPColsData()
rows = scip.getLPRowsData()
# exit if LP is trivial
if len(cols) == 0 or len(rows) == 0:
return {"result": result}
if self.model.getNNodes() == 1:
# initialize root buffer for Khalil features extraction
utilities.extract_khalil_variable_features(self.model, [], self.khalil_root_buffer)
# once in a while, also run the expert policy and record the (state, action) pair
query_expert = self.rng.rand() < self.query_expert_prob
if query_expert:
state = utilities.extract_state(self.model)
cands, *_ = self.model.getPseudoBranchCands()
state_khalil = utilities.extract_khalil_variable_features(self.model, cands, self.khalil_root_buffer)
result = self.model.executeBranchRule('vanillafullstrong', allowaddcons)
cands_, scores, npriocands, bestcand = self.model.getVanillafullstrongData()
assert result == scip.SCIP_RESULT.DIDNOTRUN
assert all([c1.getCol().getLPPos() == c2.getCol().getLPPos() for c1, c2 in zip(cands, cands_)])
action_set = [c.getCol().getLPPos() for c in cands]
expert_action = action_set[bestcand]
data = [state, state_khalil, expert_action, action_set, scores]
# Do not record inconsistent scores. May happen if SCIP was early stopped (time limit).
if not any([s < 0 for s in scores]):
filename = f'{self.out_dir}/sample_{self.episode}_{self.sample_counter}.pkl'
with gzip.open(filename, 'wb') as f:
pickle.dump({
'episode': self.episode,
'instance': self.instance,
'seed': self.seed,
j = int(str(el[0])[-1])
A[j][i] = 1.0
i += 1
polynomial = Polynomial(A,b)
polynomial.clean()
#add constraints to constraint_list with constraints >= 0
_nonnegCons(polynomial, rhs, lhs)
else:
#TODO: what to do with non-polynomial constraints? (possibly linear relaxation)
raise Warning("relaxator not available for constraints of type ", constype)
#No constraints of type expr, quadratic or linear, relaxator not applicable
if optProblem.constraints == []: #constraint_list == []:
return {'result': SCIP_RESULT.DIDNOTRUN}
#get Objective as Polynomial
optProblem.setObjective(ExprToPoly(self.model.getObjective(), nvars))
#use the Variable bounds as linear constraints
#TODO: improve usage of bounds, maybe delete Constraints if same as bounds (for Polynomial)
#TODO: problem if bounds are tightened since it makes completely new polynomial (linear term is changed)
#TODO: 'polynomial unbounded at point ..' appears if variables do not appear in polynomial (possibility to fix them to 0?)
for i,y in enumerate(self.model.getVars()):
if y.getUbLocal() == y.getLbLocal() and y.getUbLocal() == 0:
equ = False
#print(cons)
p = np.zeros(len(self.model.getVars())+1)
p[0]=1
p[i+1]=2
for j in optProblem.constraints: #constraint_list:
for k in range(1,len(j.A[0])):