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

getSols returns empty array #838

Open
cjrodriguez98 opened this issue Apr 4, 2024 · 14 comments
Open

getSols returns empty array #838

cjrodriguez98 opened this issue Apr 4, 2024 · 14 comments

Comments

@cjrodriguez98
Copy link

Describe the bug
I am trying to use the count feature. I correctly get the number of solutions but when I try to get the solutions an empty array is returned. I know this has previously been addressed in #248 and #549, I can see the merged changes in my sources thats why I am opening this issue.

To Reproduce
The parameters I am ussing.
model.setHeuristics(3)
model.setBoolParam("constraints/countsols/collect", True)
model.hideOutput()

Expected behavior
Retrive an array of solutions.

System

  • OS: Windows
  • Version 10
  • SCIP version 9
  • How did you install pyscipopt? Conda install
@Joao-Dionisio
Copy link
Collaborator

Hello, @cjrodriguez98! Can you please share a minimal reproducible example, something small-ish that yields this error, so that we can try to fix it?

@cjrodriguez98

This comment was marked as outdated.

@cjrodriguez98
Copy link
Author

cjrodriguez98 commented Apr 5, 2024

I could not append the model.cip file, put I paste its content in here. Let me know if you can reproduce it with that.

To provide more context I am then performing count on this problem and while I obtain a solCount of 7 the solutions array is empty.

@Opt-Mucca
Copy link
Collaborator

Opt-Mucca commented Apr 5, 2024

For counting solutions: Have you simply tried getNSolsFound()? That is preferable to setting the parameter countsols and relying on the constraint handler.

Edit: After talking to a colleague: If you enable the countsols then SCIP is essentially hiding the solutions from itself. So it stores the solutions internally, and gives you a valid count of solutions found, but SCIP itself does not have access them (to do things like prune the search tree etc or terminate the search early). This will massively impact performance however, and provide a different solution path to default SCIP. So if you just want the umber of solutions found during the solve process, then use getNSolsFound().

@Joao-Dionisio
Copy link
Collaborator

Hey @cjrodriguez98! What's normally done to share cip files on github is to change its file extension to txt. Can you do that, please? I'm getting an unexpected end of file error....

I see that you have many indicator constraints. After looking at the getSols method, if I don't find anything I'll probably look into them, as Issue #717 shares some problems with them.

@cjrodriguez98
Copy link
Author

model.txt

Okay, many thanks @Joao-Dionisio

@Joao-Dionisio
Copy link
Collaborator

Joao-Dionisio commented Apr 9, 2024

Hey @cjrodriguez98! Sorry for taking a while to answer. I cannot reproduce your problem, I'm able to get the solution:

image

Can you tell me which version of pyscipopt you are using? (There is the model.printVersion() function)

@cjrodriguez98
Copy link
Author

cjrodriguez98 commented Apr 10, 2024

Hello @Joao-Dionisio! Thank you!

Yes, I can optimize() and get the solution. But I cannot get the solution array when using count().

I am using pyscipopt 5.0.0

from pyscipopt import Model

m = Model()
m.readProblem('model.cip')
m.setHeuristics(3)
m.setBoolParam("constraints/countsols/collect", True)
m.hideOutput()

m.count()
print(m.printVersion())
print(m.getNCountedSols())
print(m.getSols())

Thanks in advance!

@Joao-Dionisio
Copy link
Collaborator

Ohh sorry, I didn't read your problem properly :) Yeah, I agree that something is strange. But can you elaborate on what you want to do? I'd never seen the count method, it might be quite old. Can you not achieve what you want with the getSols and getNSolsFound methods like Mark mentioned?

Looking at the documentation, I'm not even sure why we have the count method in the first place, it seems to be something for SCIP, not PySCIPOpt.

@cjrodriguez98
Copy link
Author

No worries!

From my understanding the count method it is the equivalent of populate in other commercial solvers. My problem requires that when a solution is found a restriction is added to remove that solution from the solution space so it cannot be part of a larger solution. To explain it breifly we try to find a set of solutions that must be minimal, so we are not interested in bigger sets if they contain the minimal solution therefore the added constraint. But as we add more constraints the problem becomes harder and harder. So with the count method we could encounter all the solutions of certain length at once, instead of finding them one by one. (I do not know if I explained myself)

In my expirience scip is doing a fenomenal job finding the correct number of solutions (7) but I cannot get the solutions.

Let me know if I could help you in any way or provide more context.

Thanks!

@Joao-Dionisio
Copy link
Collaborator

Ah okay, I think I understand what you're trying to do @cjrodriguez98. There would be alternatives if finding solutions 1 by 1 were a possibility (using event handlers, or setting the solution limit to 1 and then looping), but if you want access to all the vertices, then it seems like you do need the count method.

I don't think I'll be able to help out much, maybe @Opt-Mucca has some more insights, given your context.

@Joao-Dionisio
Copy link
Collaborator

Hello, @cjrodriguez98!

Did you take a look at this page? It says what one needs to do to get the solutions. It also says it only looks at the active variables. However, when disabling presolve with your problem, I get these errors:

image

I don't know what might be causing them. I know this doesn't fix anything, just trying to give you more information :)

@cjrodriguez98
Copy link
Author

Hey @Joao-Dionisio,

Yes, we have risen thin issue, (ELEAVE56) in another page of scip.

But yeah, I see that scip is calculating the number of solutions correctly but not returning the solution array.

Thanks anyway :)

@Joao-Dionisio
Copy link
Collaborator

Hey @cjrodriguez98! Did you end up getting an answer from that other page of SCIP?

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

3 participants