Primal task, trying to get simple baseline working #31
-
I'm trying to establish a simple baseline in the primal task by just running SCIP for 1 second in the agents I print the primal bound after calling My code in the
where the
I've gone through and made sure that the I'm not sure what else could be going wrong, and any pointers would be really appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 22 replies
-
Hi! This is because running SCIP for 1 second cannot get any feasible solution. You can try There are two potential methods that come to me. First, you can simply set a longer time limit. Second, you can use an event handler https://imada.sdu.dk/~marco/DM871/PySCIPOpt/event_8pxi.html#details (see the documents here). However, the documents of the event handler are not clearly stated. I have not succeeded yet. |
Beta Was this translation helpful? Give feedback.
-
hi, @kushaltirumala , did you check the variable names?
I also try to solve the model with SCIP in the agents
|
Beta Was this translation helpful? Give feedback.
-
Hi all. Thanks for the discussion ! First of all let me say that this baseline does make a lot of sense, and it will be very helpful to beginners I am sure, so thank you for sharing it :) I would suspect that there is a discrepancy between the ordering of the variables in the duplicated model and in the environment's model, as some of you have pointed out. But it might be also that there is a bug on our side. I will have to dig into it more, but unfortunately I won't be able to do that until Friday. Meanwhile, I would suggest to thoroughly double-check variable names and orderings, as this seems like the obvious explanation. I am not sure though why PySCIPOpt would change the ordering when copying the original model. Best, |
Beta Was this translation helpful? Give feedback.
-
Dear all, I figured the issue, the import ecole as ec
import numpy as np
import pyscipopt
class ObservationFunction():
def __init__(self, problem):
# called once for each problem benchmark
self.problem = problem # to devise problem-specific observations
self.m_copy = None
def seed(self, seed):
# called before each episode
# use this seed to make your code deterministic
pass
def before_reset(self, model):
# called when a new episode is about to start
self.m_copy = None
def extract(self, model, done):
if done:
return None
m = model.as_pyscipopt()
remaining_time_budget = m.getParam("limits/time") - m.getSolvingTime()
# extract (copy) the model only once
if self.m_copy is None:
self.m_copy = pyscipopt.Model(sourceModel=m) # copy the model into a new SCIP instance
m_isfresh = True # freshly created model
else:
m_isfresh = False # not freshly created model
observation = (self.m_copy, remaining_time_budget, m_isfresh)
return observation
class Policy():
def __init__(self, problem):
# called once for each problem benchmark
self.rng = np.random.RandomState()
self.problem = problem # to devise problem-specific policies
def seed(self, seed):
# called before each episode
# use this seed to make your code deterministic
self.rng = np.random.RandomState(seed)
def __call__(self, action_set, observation):
m, max_time_budget, m_isfresh = observation
var_ids = action_set
# reset solution improvement and solving time counters for freshly created models
if m_isfresh:
self.sol_improvements_consumed = 0
self.solving_time_consumed = 0
m.setPresolve(pyscipopt.scip.PY_SCIP_PARAMSETTING.OFF) # presolve has already been done
m.setHeuristics(pyscipopt.scip.PY_SCIP_PARAMSETTING.AGGRESSIVE) # we want to focus on finding feasible solutions
m.setParam('limits/bestsol', self.sol_improvements_consumed + 1) # stop after a new primal bound improvement is found
m.setParam('limits/time', self.solving_time_consumed + max(max_time_budget - 0.01, 0)) # stop the agent before the environment times out
m.optimize()
# keep track of best sol improvements in the copied model to be able to set a limit
if m.getStatus() == 'bestsollimit':
self.sol_improvements_consumed += 1
# keep track of solving time already spedn in the model to be able to increment it appropriately
self.solving_time_consumed = m.getSolvingTime()
assert m.getNSols() > 0
print(f"{m.getSolvingTime()} seconds spend searching, best solution so far {m.getObjVal()}")
sol = m.getBestSol()
sol_vals = np.asarray([m.getSolVal(sol, var) for var in m.getVars(transformed=False)])
action = (var_ids, sol_vals[var_ids])
return action |
Beta Was this translation helpful? Give feedback.
Dear all,
I figured the issue, the
SCIPcopy()
method actually copies the transformed problem from the source SCIP instance into the original problem of the target SCIP instance. So it suffices to extract solution values for theoriginal
variables in the copies instance and then index those values with thevar_ids
(variable indexes in the transformed problem for the environment's SCIP model, which is equivalent to variable indexes in the original problem for the agent's copied SCIP model). The following code seems to work. I think this baseline might be valuable to other participants as well, so maybe what we'll do now is polish it a little and then expose it to other participants by distr…