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

Score plugin #12

Merged
merged 5 commits into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more score functions
  • Loading branch information
jurgen-lentz committed Jun 3, 2022
commit cf5f4cd7ced12d89608f9ddf434aade51ed56c11
2 changes: 1 addition & 1 deletion src/pygcgopt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
from pyscipopt import SCIP_ROWORIGINTYPE

# export user-relevant objects
from pygcgopt.gcg import Model, Detector, PricingSolver
from pygcgopt.gcg import Model, Detector, PricingSolver, Score
from pygcgopt.gcg import PY_GCG_PRICINGSTATUS as GCG_PRICINGSTATUS
3 changes: 3 additions & 0 deletions src/pygcgopt/decomposition.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,9 @@ cdef class PartialDecomposition:
cdef bool cpp_fromorig = fromorig
self.thisptr.setStemsFromOrig(cpp_fromorig)

def getScore(PartialDecomposition self, Score score):
return self.thisptr.getScore(GCGfindScore(self.thisptr.getDetprobdata().getScip(), str_conversion(score.scorename)))

# def setUsergiven(PartialDecomposition self, cpp.USERGIVEN usergiven):
# """sets whether this partialdec is user given

Expand Down
5 changes: 5 additions & 0 deletions src/pygcgopt/gcg.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ cdef extern from "gcg/gcg.h":

SCIP_RETCODE GCGincludeScore(SCIP* scip, const char* name, const char* shortname,const char* description, DEC_SCOREDATA* scoredata, SCIP_RETCODE (*scorefree) (SCIP* scip, DEC_SCORE* score), SCIP_RETCODE (*scorecalc) (SCIP* scip, DEC_SCORE* score, int partialdecid, SCIP_Real* scorevalue))
DEC_SCOREDATA* GCGscoreGetData(DEC_SCORE* score)
int GCGgetNScores(SCIP* scip)
DEC_SCORE** GCGgetScores(SCIP* scip)
const char* GCGscoreGetName(DEC_SCORE* score)
DEC_SCORE* GCGfindScore(SCIP* scip, const char* name)


cdef extern from "gcg/pub_gcgsepa.h":
Expand Down Expand Up @@ -311,6 +315,7 @@ cdef extern from "gcg/class_partialdecomp.h" namespace "gcg":
void buildDecChainString(char * buffer) except +
bool fixConsToBlock(SCIP_CONS* cons, int block)
bool fixConsToMaster(SCIP_CONS* cons)
SCIP_Real getScore(DEC_SCORE* score) except +


cdef extern from "gcg/class_detprobdata.h" namespace "gcg":
Expand Down
10 changes: 10 additions & 0 deletions src/pygcgopt/gcg.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ cdef class Model(SCIPModel):

return [DECdetectorGetName(detectors[i]).decode('utf-8') for i in range(n_detectors)]

def listScores(self):
"""Lists all scores that are currently included

:return: A list of strings of the score names
"""
cdef int n_scores = GCGgetNScores(self._scip)
cdef DEC_SCORE** scores = GCGgetScores(self._scip)

return [GCGscoreGetName(scores[i]).decode('utf-8') for i in range(n_scores)]

def setDetectorEnabled(self, detector_name, is_enabled=True):
"""Enables or disables a detector for detecting partial decompositions.

Expand Down
10 changes: 8 additions & 2 deletions tests/tesr_score.py → tests/test_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ def test_pyscore():
m.includeScore(proxyScore, "pyscore", "python", "Python score test")

m.readProblem("/Users/lentz/Desktop/BR7_56.lp.gz")
m.detect()

m.optimize()
partdecs = m.listDecompositions()

for i in partdecs:
print(str(i.getScore(proxyScore)))

return m.listScores()

if __name__ == "__main__":
test_pyscore()
print(test_pyscore())