-
Notifications
You must be signed in to change notification settings - Fork 252
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
Adding primal solutions of original problem after the model has been transformed #646
Comments
Hello, @SomovMike ! I haven't used SCIP during branching much, but I can take a look. Can you provide a code example of the problem you're having? I don't know if it works, but there is also the method createPartialSol(), where you only provide the values to a subset of variables. EDIT: Maybe you have already seen these, but here is a link to adding Primal Heuristics in SCIP, and a code example of adding a heuristic in PySCIPOpt. EDIT2: Does this question in StackOverflow help? Link |
Thank you for your quick answer! But I do not understand how createPartialSol() should work, this function also create solution with all transformed variables, when I put only values of original variables in it and try to add this solution with addSol() function it always return False, as I understood it means that this solution didn't get new primal bound |
Here is example of output of createPartialSol() function after presolving, I can provide only values of "t_x_i" variables, but as you can see there are a lot of new binreform variables. |
My suggestion with createPartialSol() was that maybe by assigning values to the "t_x_i" variables, the remaining variables would be easily found by SCIP (I have no idea if that is the case, though!). It's strange that you are having problems with createPartialSol() this way. Can you provide a small example of the code you're running, so I can try to reproduce it, please? In the link to StackOverflow I sent above, Gregor says the following:
So it seems that SCIP somehow saves the original problem. Looking at the documentation, I found SCIPgetOrigVars(), that gets the original variables, but I don't think that this method has been brought over to PySCIPOpt yet. |
Create Heuristic which get optimal solution of original variables
Function to create TSP model
Data
Solve model without my heuristic and get optimal soltuion
Then solve model with my heuristic and put optimal solution in it
Try to optimize this model
So I always got "Not accepted" message, but solution is optimal, I guess createPartialSol() also requires values of other variables, or maybe "binreform..." variables are kind of special. |
I've been looking at the code, and I don't think it's a problem with the transformed variables. I changed the code a bit, to reflect what I have encountered around SCIP. I also made a change here, to create a dictionary that maps the variable names to their values in the optimal solution. I find it easier to work with.
And the heuristic:
So, at this moment, the variables in the current model and the model without the heuristic have the same names, but I think you are right that EDIT: If you change the code for the heuristic that I wrote above so that you have I think I might be getting out of my league here... |
Thank you very much for for your help! Maybe I can somehow get values of transformed variables from original variables, and then create full solution with CreateSol() function, but I can't find any function of method that can do that:( |
I think I can already do that, but for some reason SCIP says that the resulting solution is not feasible It says that the solution is accepted. If I use trySol (which checks for feasibility), then he says that the solution is not feasible: Maybe the problem is the way SCIP is trying to deal with your obj_var variable, due to the nonlinear objective function? The infeasibilities are indeed with the transformed variables, so maybe you're right... either way, I don't think I know how to solve your problem, sorry... |
As I understood solution infeasible because of additional variables, they just have default 0 value when you create solution with CreateSol(), but it is really strange that this solution is accepted. Feasible or infeasible, doesn't matter. It will be good for me even it just speed up solution process. |
Thank you anyway! |
Found interesting thing, if we rewrite model like this, just change "obj_var >= ..." on "obj_var + 1 >= ..." in constraint, it actually works! SCIP do not delete "obj_var" variable in transformed problem, and with createSol() and setSolVal() you can also set value of "obj_var" variable. But another thing, when you provide optimal solution SCIP runtime and number of proceeded nodes increase))) However at the output I can see that primal bound changed after providing optimal solution.
EDIT: On problem with more variables it helps, just tried on TSP with 9 cities, and runtime without providing optimal solution 49 sec, and with 40 sec EDIT2: But this "trick" with model actually give a bad performance compare to initial model where "obj_var" deleting. So, it is not the way to solve my problem:( |
Hello, @SomovMike ! I am really sorry for taking so long to answer, I kept delaying and eventually, I forgot... So it turns out that this is really a problem with SCIP, right? And your workaround didn't really solve the issue if I understood correctly. |
Hello, unfortunately yes, I still can't solve this issue( |
Did you manage to do something else, @SomovMike? What is the code you currently have? |
Actually no, except one thing: SCIP made variable "obj var" multi aggregated, I don't know what it exactly means but you can set param in SCIP that it will not do that. And after that you can set value to variable "obj var" as well as other variables, and SCIP accepts such solution. But it works like a "trick" I described above, solution process become slower:( |
When you say the solution process is slower, which process do you mean, @SomovMike? From what I understand, you are solving a TSP instance to optimality, and then providing the optimal solution to a fresh copy of the model and then optimizing again, right? When you say it becomes slower, are you talking about the whole process, or just the second reoptimization? If the entire process is slower, that is to be expected, as you are just repeating unnecessarily. However, just adding a solution to a model, is not a guarantee that it will be faster. One can construct scenarios where "artificially" introducing a solution makes it so other heuristics are called at a different time, or other methods don't work in the same way, and then the gain ends up being minimal or even nonexistent. Maybe this is what is happening. |
No no no, I mean just Bnb process without proving any records. Turn this parameter off -- SCIP begins to solve the problem worse in general. But it is not a surprise, there is a reason why this parameter was originally enabled. But my goal is to provide records to SCIP without loosing in performance) |
I don't think I understand what you are saying... What do you mean provide records in Bnb? Do you mean providing new solutions, updating the current best incumbent? But you managed to solve the original problem, right, @SomovMike? Now it's more an issue related to your heuristic and the way SCIP deals with solutions provided by the user at runtime, yeah? |
Sorry for misleading you. No, I didn't solve the initial issue. I still can't provide any solution to SCIP in a correct way. |
No need to apologize, @SomovMike, I was the one who misunderstood. I also still can't solve your problem, sorry... |
Hello, @SomovMike! What is the status of this issue? Shall we go for round 3 and see if we can figure out what's going on? |
So the requirement to fix this issue is probably: Add a Python function that wraps SCIPcreateOrigSol(), and add that to the exported SCIP functions. |
@Opt-Mucca yeah, that seems like it would work, thanks! But I think it would also be useful to have the possibility to transform an expression/solution/whatever from the original space into the transformed space and the other way around. What do you think? |
Hello! I try to add my own heuristic, which called while branching and give primal solutions to SCIP. This heuristic works only with original problem, but after presolving SCIP add new different variables and constraints. I've tried to create solution with CreateSol() method, and then put solution to SCIP with trySol() or addSol(), but as I said my heuristic get only values of original variables, and CreateSol() creates solution with transformed variables. I guess trySol() and addSol() also require transformed variables. Is it possible to put original solution while solving? Only way I see to off presolving, but it is not the best option for me.
Thank you in advance!
The text was updated successfully, but these errors were encountered: