Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I initialize a partial solution? #621

Closed
fengshaoA opened this issue Nov 3, 2022 · 9 comments
Closed

How can I initialize a partial solution? #621

fengshaoA opened this issue Nov 3, 2022 · 9 comments

Comments

@fengshaoA
Copy link

Let's say x = mode.addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=5.0, pricedVar = False),then I can say that the initial value of x is 5.0?

@Joao-Dionisio
Copy link
Collaborator

No, you cannot say that. The obj parameter is the coefficient of the variable in the objective function. Suppose you had the following:

y = model.addVar(name="y", vtype="C", lb=0.0, pricedVar = False)
model.setObjective(3*y)

Here your objective function is min. 3*y. If you then do

x = model.addVar(name="x", vtype="C", lb=0.0, obj=5.0, pricedVar=False)

You do two things. First, you create and add a new variable x, and then add it to the objective function. So now your new objective function is: min 3y + 5x.

Please let me known if something is not clear.

@fengshaoA
Copy link
Author

Ok, I see, thank you very much, but what if I want to use the solution of the heuristic algorithm as the initial value in the scip solver? i know that in gurobi you can do this: for example, if the heuristic algorithm x[i] has a feasible solution of 5, then in gurobi you can set the initial value of x[i] like this: x[i].Start = 5;

@Joao-Dionisio
Copy link
Collaborator

Joao-Dionisio commented Nov 3, 2022

If I understood correctly you want to initialize a partial solution, right? I have never done this, but I'm fairly certain that I got it. You first need to create a partial solution with model.createPartialSol(), and then add values to the variables you want. This method (createPartialSol) also has an optional parameter for the heuristic you used to find the values.

model = Model()
y = model.addVar(name="y",lb=3)
x = model.addVar(name="x",lb=7)

s = model.createPartialSol()
model.setSolVal(s, x, 50)

model.addCons(x >= y**2)

model.setObjective(x+y)
model.addSol(s)
model.optimize()

I made a non-linear model so that the trivial heuristic couldn't immediately find the solution. If you run this script, you will see that the first line is

feasible solution found by completesol heuristic after 0.0 seconds, objective value 4.870000e+01

And the optimal value is 1.2e+01, so I'm fairly certain that this is the way to do what you want.

PS: I didn't know that this method existed, and I needed something like it for my own work, so thank you very much for the question!

PPS: Can you please change the title of the issue to something like: "How can I initialize a partial solution?" That way, it will be easier for people to find it later.

@fengshaoA fengshaoA changed the title mode.addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=0.0, pricedVar = False) How can I initialize a partial solution? Nov 3, 2022
@fengshaoA
Copy link
Author

Ok, thank you for your advice, I have revised the title, I will try your way, thank you again!

@fengshaoA
Copy link
Author

fengshaoA commented Nov 4, 2022

I'm sorry, I tried to run the model yesterday, but there was an error. Could you please check it again? The error message looks like this:
Traceback (most recent call last): File "D:/project/python/scip_test.py", line 136, in <module> s = model.createPartialSol() AttributeError: 'pyscipopt.scip.Model' object has no attribute 'createPartialSol'
thank you very much!

My version of PySCIPOpt is 6.0.2

@fserra
Copy link
Collaborator

fserra commented Nov 4, 2022

you mean that the version of SCIP that you are using is 6.0.2? You should update to the latest SCIP and the latest version of pyscipopt and try again

@fengshaoA
Copy link
Author

you mean that the version of SCIP that you are using is 6.0.2? You should update to the latest SCIP and the latest version of pyscipopt and try again

Ok, thanks, I've thought of that, and now I've updated to version 7.0.2, which includes createPartialSol,

@fengshaoA
Copy link
Author

When I provide initial values for the model during the solution process, the solver log prompts me with this issue:
WARNING: ignore partial solution (0) because unknown rate is too large (0.996856 > 0.85)
After the prompt for the issue, the initial values I provided did not take effect. Could you please explain what is going on here?
image
image

@sbolusani
Copy link
Member

The completesol heuristic of SCIP, which takes a partial solution as input and completes it, has a maximum threshold of 0.85 (85%) for the number of unknown variable values. Since the provided partial solution seems to have 0.996856 (more than 99.6%) of the unknown variable values, the heuristic printed the above warning message and exited without trying to create a complete solution.

You may either provide a partial solution with more known variable values (recommended option) or change the threshold value of the completesol heuristic by setting the following SCIP parameter. This parameter takes values in the range [0, 1] with a default value of 0.85 (hence, the above warning message with 0.85 in it).

heuristics/completesol/maxunknownrate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants