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

get counted solutions #248

Closed
ramabile opened this issue Feb 24, 2019 · 13 comments · Fixed by #729
Closed

get counted solutions #248

ramabile opened this issue Feb 24, 2019 · 13 comments · Fixed by #729

Comments

@ramabile
Copy link
Collaborator

ramabile commented Feb 24, 2019

Dear SCIPers,
this question has the purpose to check whether the function is already implemented somewhere. Otherwise I think I will implement it at some point.

I want to collect the counted solutions. I use this script:

from pyscipopt import Model
m = Model()
x = m.addVar("x", "B")
y = m.addVar("y", "B")
z = m.addVar("z", "B")

m.setBoolParam("constraints/countsols/collect", True)
m.hideOutput()

m.count()

nsols = m.getNCountedSols()
sols = m.getSols()
print(nsols)
print(sols)

nsols is 8 (right), but sols is empty (it should be an 8-long list).
This is expected since counted solutions are not obtained with getSols.
So: how to get them? I did not find anything appropriate and already implemented.

1)Looking at this: https://scip.zib.de/doc/html/COUNTER.php
it seems there are several missing interfaces. Do you confirm?
One step further is to implement SCIPgetCountedSparseSolutions which may not be enough.

2)Documentation suggests: https://scip.zib.de/doc/html/group__CONSHDLRS.php#ga1c3b0e8f05febeac36ad6f77ce45bf66
which writes the counted solutions. Arguably, a more Pythonic way is to store the counted solutions in a list instead of writing them (and then reading them again). Is there anything similar?

3)[SCIP side from a Python user] What is the design choice behind a dialog for a writing interface without a writing interface? If there were a writing interface, is there any design choice to avoid something like SCIPgetCountedOriginalSolutions which would be so much appreciated?

Thanks!

@mattmilten
Copy link
Collaborator

Counting solutions has been implemented in SCIP as an afterthought and is more proof-of-concept than API functionality. We should change that...

@ramabile
Copy link
Collaborator Author

Thanks @mattmilten for the clarification!
As a humble newcomer, I would have expected that SCIPdialogExecWriteAllsolutions calls SCIPwriteAllsolutions which on turn calls SCIPgetAllsolutions.

Please help me to understand your ellipsis. Do you suggest to change SCIP before someone changes PySCIPOpt? Is any effort to mimic the current behaviour worthy?

Thanks!

@mattmilten
Copy link
Collaborator

Currently, there are no concrete plans to implement proper access to the counted solutions. So (re)implementing this in PySCIPOpt would be the way to go if you need this rather sooner than later.

@soumyamittal
Copy link

@ramabile Did you end up implementing this at your end?

@mattmilten
Copy link
Collaborator

closed due to inactivity

@EtashGuha
Copy link

Has there been any update on how to get the solutions? I am able to get the sparse solutions, but converting them into the new space is difficult... It seems like access to the hashmap is difficult.

@mattmilten
Copy link
Collaborator

I am not aware of any progress in this regard. If you want to share your prototype code via a pull request, we might be able to complete this.

I am reopening this issue again.

@mattmilten mattmilten reopened this Jan 2, 2021
@EtashGuha
Copy link

Great thanks. I created a pull request under name Multiple sol #470:
https://github.com/scipopt/PySCIPOpt/pull/470/files
I created a new function called getSparseSols(). This is based off of https://www.scipopt.org/doc/html/cons__countsols_8c_source.php#l02693

I'm very new to this so I apologize if I havent done a whole lot.

@CGraczyk
Copy link
Collaborator

CGraczyk commented Jan 8, 2021

After some clean-up, the commits will be merged into a feature branch and we can work together on finalizing the functionality.

@kligler
Copy link

kligler commented May 30, 2021

Is there any news with this PR?
Interested in this functionaliy (even before its merged), I tried installing it, though got a few errors regarding the extended functionality:
>pip install git+https://github.com/scipopt/PySCIPOpt.git@multipleSol Collecting git+https://github.com/scipopt/PySCIPOpt.git@multipleSol Cloning https://github.com/scipopt/PySCIPOpt.git (to revision multipleSol) to ... Running command git clone -q https://github.com/scipopt/PySCIPOpt.git 'C:\Users\user\AppData\...' Running command git checkout -b multipleSol --track origin/multipleSol Branch 'multipleSol' set up to track remote branch 'multipleSol' from 'origin'. Switched to a new branch 'multipleSol' ERROR: Command errored out with exit status 1: command: '...\assignMultiSol\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = .... Complete output (55 lines): Using include path <C:\Program Files\SCIPOptSuite 7.0.2\include>. Using SCIP library <libscip> at <C:\Program Files\SCIPOptSuite 7.0.2\lib>. Compiling src\pyscipopt\scip.pyx because it changed. [1/1] Cythonizing src\pyscipopt\scip.pyx Error compiling Cython file: ------------------------------------------------------------ ... SCIP_Real SCIPfeastol(SCIP* scip) SCIP_RETCODE SCIPsetObjIntegral(SCIP* scip) SCIP_Real SCIPgetLocalOrigEstimate(SCIP* scip) SCIP_Real SCIPgetLocalTransEstimate(SCIP* scip) SCIP_RETCODE SCIPgetProbvarLinearSum(SCIP* scip, SCIP_VAR** vars, SCIP_Real* scalars, int* nvars, int varssize, SCIP_Real* constant, int* requiredsize, SCIP_Bool mergemultiples) SCIP_Bool SCIPsparseSolGetNextSol(SCIP_SPARSESOL* sparsesol, SCIP_Longint* sol, int nvars) ^ ------------------------------------------------------------ src\pyscipopt\scip.pxd:631:38: 'SCIP_SPARSESOL' is not a type identifier Error compiling Cython file: ------------------------------------------------------------ ... cdef extern from "scip/cons_countsols.h": SCIP_RETCODE SCIPcount(SCIP* scip) SCIP_RETCODE SCIPsetParamsCountsols(SCIP* scip) SCIP_Longint SCIPgetNCountedSols(SCIP* scip, SCIP_Bool* valid) void SCIPgetCountedSparseSols(SCIP* scip, SCIP_VAR*** vars, int* nvars, SCIP_SPARSESOL*** sols, int* nsols); ^ ------------------------------------------------------------ src\pyscipopt\scip.pxd:1613:76: 'SCIP_SPARSESOL' is not a type identifier Error compiling Cython file: ------------------------------------------------------------ ... PY_SCIP_CALL( SCIPgetProbvarLinearSum(self._scip, vars, scalars, &nvars, sparsenvars, &constant, &requiredsize, True) ) realvalue = constant; for i in range(_nallvars): # I have no idea how to get the hashmap? # https://www.scipopt.org/doc-5.0.0/html/group__SparseSol.php#gaed7a10e2bd49c6b18a16e98d37174498 if not SCIPsparseSolGetNextSol(sparsesol, sol, sparsenvars): ^ ------------------------------------------------------------ src\pyscipopt\scip.pyx:4159:0: Expected an increase in indentation level Traceback (most recent call last): File "<string>", line 1, in <module> File "...\pip-req-build-onaxqani\setup.py", line 74, extensions = cythonize(extensions, compiler_directives = {'language_level': 3}) File "...\Cython\Build\Dependencies.py", line 1102, in cythonize cythonize_one(*args) File "...\Cython\Build\Dependencies.py", line 1225, in cythonize_one raise CompileError(None, pyx_file): src\pyscipopt\scip.pyx WARNING: Discarding git+https://github.com/scipopt/PySCIPOpt.git@multipleSol. Command errored out with exit status 1

Am I doing something wrong or are there still compilation issues?

@CGraczyk
Copy link
Collaborator

CGraczyk commented Jun 4, 2021

Hi, that branch is still a WIP and you shouldn't install from there, feel free to checkout that branch though

@IgnaceBleukx
Copy link

Hi all,
Any news on this issue? I am a developer of the CPMpy modeling library and we would really like to add SCIP as a solver.
Ideally, we can also add the solveAll method for SCIP through the appropriate Python interface.

@Joao-Dionisio
Copy link
Collaborator

Hello, @ramabile! I think the issue is that the function getSols prints the solution of the transformed problem. SCIP enters a presolving stage, where it looks for ways to make the problem simpler. In very simple instances, this means that all the variables might actually get deleted, which is happening in your case.

I've now changed the getSols function so that it prints the solution with respect to the original variables. Please let me know if you find that this actually didn't fix your problem!

@IgnaceBleukx, I think the problems related to this issue are now fixed.

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

Successfully merging a pull request may close this issue.

8 participants