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

Duals for MIQCP #79

Open
Anjula-Antonis opened this issue Oct 13, 2022 · 8 comments
Open

Duals for MIQCP #79

Anjula-Antonis opened this issue Oct 13, 2022 · 8 comments

Comments

@Anjula-Antonis
Copy link

Hi,
I have a mixed-integer QCP code. I need to extract the dual solutions for this. I didn't find an option for fixed start in docplex. Can someone please help

@vberaudi
Copy link
Member

if I don't mistake, you only have to do:

    model.solve()

    c = model.get_cplex()
    values = c.solution.get_dual_values([c1.index, c2.index, ...])
    print(values)

where c1, c2,... will be your constraints.
which will internally call the getpi function based on your input. Seehttps://www.ibm.com/docs/en/icos/22.1.0?topic=SSSA5P_22.1.0/ilog.odms.cplex.help/refpythoncplex/html/cplex._internal._subinterfaces.SolutionInterface-class.html

When docplex does not provide built-in functionalities, you can always get to the under lying cplex object and get the "low level" api which handles indexes.

@Anjula-Antonis
Copy link
Author

Hi,
Thank you for the suggestion. But this doesnt work in my case since it is a mixed-integer problem. Also the option of fixed-MILP in cplex doesn't work for me since my problem in MIQCP

cplex.exceptions.errors.CplexSolverError: CPLEX Error 1017: Not available for mixed-integer problems.

@AndrasKiss
Copy link

Hi,
I'm facing the exact same problem and couldn't find a method to solve fixed MIQCPs anywhere (to get the dual values for some of the linear constraints, in my case). I suppose reformulating the model by hand with the optimal integer solutions as constants would work. Is that the only option though? Help would be very much appreciated.

@PhilippeCouronne
Copy link

Hello,

I have committed a small sample to show how to fix values for a MIQP, solve it as a QP and access dual values.
The idea is to change the CPLEX problem type to "fixed_MIQP" once it has been solved successfully.
As this modification can lead to tricky errors, I encapsulated it in a context manager to ensure I get back the original model
unchanged at the end.

The sample:

https://github.com/PhilippeCouronne/docplex_contribs/blob/master/docplex_contribs/src/miqp_duals1.py

Hope this helps

@AndrasKiss
Copy link

Hi Philippe,

Thanks for your work! I've already come across a similar code segment of yours from June 2021 on an IBM Community site. That one was for MILP -> fixed MILP.

The reason neither of these segments solve my problem (or the OP's problem) is that we are looking for MIQCP -> fixed MIQCP. And the reference manual says that there is no ProblemType value for fixed_MIQCP.

As for me, I've already figured out how to work around this limitation by defining a second QCP model based on the solution values of the first MIQCP. But it would still be nice to know if there is an officially supported way of running a fixed version of an MIQCP model and calculating the duals from it. Please let us know if you have other ideas, or if something is incorrect in my diagnosis above.

@PhilippeCouronne
Copy link

PhilippeCouronne commented Nov 21, 2022

Hi,
My bad, I missed you had a MIQCP. You are right, there is no fixed MIQCP so my code won't work for MIQCP. I'll come back to you if I find some way to work this around,
In addition, I'm curious about how you managed to define your fixed QCP. I guess you changed variables to continuous and constrained variables in intervals with some precision values?

@AndrasKiss
Copy link

Hi Philippe,
I somehow missed your question in the second line at first reading, sorry about that! I only had binary non-continuous variables, and I simply substituted their optimal values as constants at the second QCP run.

For example:
Suppose x may be either 0 ("inactive") or between 0.5 and 1.0 ("active"). In the MIQCP, I define x as continuous between 0 and 1, and a second, binary variable z, which is either 0 or 1. Then I add the following constraints:
0.5 * z <= x
x <= z
Essentially, z records whether x is active or inactive.

Once I solve the MIQCP, the optimal value of z tells me whether x will be active (z = 1) or inactive (z = 0) at the optimal solution. So I redefine a QCP with x only, and substitute either z = 1 or z = 0 into the two constraints above. Either way, optimizing the QCP will give me the same optimal x as the MIQCP did, but now I can query the duals on (some other) constraints that I'm interested in.

This may be too specific to my application to be useful to others, though. I haven't thought much about generalizations.

@PhilippeCouronne
Copy link

Thanks Andras, this is fairly natural. I was thinking about a generalized way of doing this. Advanced features such as piecewise funtional constraints, SOS sets , indicators, equivalences should also be translated into the fixed problem. I guess you had none of them in your model. I have ideas about how to handle them; I may post a fix_model() transformation when I have time.
Thanks again for your response.

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