Extract the original MIP model within the observation function #32
-
Hi all,
However, from the PySCIPOpt API, I do not find the method to fetch the original constraints and reconstruct the original MIP problem. Any help or advice would be greatly appreciated. Best |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
You can check the answers provided here : #18 |
Beta Was this translation helpful? Give feedback.
-
Hi @zhejiangzhoulei , I suppose you are interested in recovering the original MILP for the primal task ? Otherwise the following might not apply. First, I want to point out that what you want is most likely the transformed MILP, that is, the original MILP plus any preprocessing made by SCIP (some constraints might have been simplified or added, some variables might have been removed, merged or added, etc.). The solutions that your agent must provide in the primal task are solutions in the transformed variable space, so you might as well extract the problem formulation directly in that space as well in you observation function to avoid any headache. You should be able to recover the transformed MILP of the current node (i.e., the root node in the primal task) from the PySCIPOpt API by using the following API (as @fsikora also pointed out) : m = model.as_pyscipopt()
cols = [var.getCol() for var in m.getVars(transformed=True) if var.isInLP()] # to get local LP columns
rows = m.getLPRowsData() # to get local LP rows
# for each row in the LP (lhs <= wTx + cst <= rhs)
row.getLhs() # left-hand-side of the row (lhs)
row.getRhs() # right-hand-side of the row (rhs)
row.getConstant() # constant of a row (cst)
row.getCols() # columns with a non-zero entry in the row (i where w_i != 0)
row.getVals() # the corresponding non-zero entries (w_i where w_i != 0)
# for each column in the LP (x_i)
col.getLPPos() # position (id) of the column in the LP
col.getLb() # lower bound of the column (lb <= x_i)
col.getUb() # upper bound of the column (x_i <= ub)
col.getVar().getObj() # objective coefficient of the column (c_i)
col.getVar().vtype() # variable type (BINARY, INTEGER, IMPLINT or CONTINUOUS) Those calls shall allow you to reconstruct the transformed MILP, for example if you want to feed it into another off-the-shelf search method for MILPs. Note: don't forget to extract the variable indexes as well ( Hope that helps. Let us know if you encounter any difficulty. Best, |
Beta Was this translation helpful? Give feedback.
Hi @zhejiangzhoulei ,
I suppose you are interested in recovering the original MILP for the primal task ? Otherwise the following might not apply.
First, I want to point out that what you want is most likely the transformed MILP, that is, the original MILP plus any preprocessing made by SCIP (some constraints might have been simplified or added, some variables might have been removed, merged or added, etc.). The solutions that your agent must provide in the primal task are solutions in the transformed variable space, so you might as well extract the problem formulation directly in that space as well in you observation function to avoid any headache.
You should be able to recover the transf…