<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Dear Nicolas (or Julian?),<br>
<br>
I am happy to hear that you like the python interface. We like it,
too.<br>
<br>
Regarding the callbacks: There are four fundamental callbacks of a
constraint handler, namely consCheck, consEnfoLP, consEnfoPS, and
consLocks. These are described in the section "Fundamental
callbacks" of the constraint handler implementation documentation
that you mentioned. <br>
<br>
The consCheck method is called by SCIP for every solution that
must be checked, which is usually the solution of the LP
relaxation (if all binary variables have integer values) or
solutions that are found by the primal heuristics of SCIP.<br>
<br>
The source of a performance bottleneck in your case may be the
presence of too many calls of the check routine, or an expensive
algorithm used within your check routine, or a combination of
both.<br>
I took the time and scanned through your code, but I couldn't see
an obvious performance flaw in the way you check your solution.<br>
<br>
You can only partially get around the number of calls to the check
method; The callback will be called every time SCIP needs to know
if a solution is feasible regarding the constraints. However, if
you assign your constraint handler a very low negative
checkpriority, it will only be called if the feasibility of the
remaining constraints has been checked already.<br>
This means SCIP will skip (hehe) the expensive check of your
constraint, if a solution already violates one of the linear or
integrality constraints.<br>
<br>
I suggest you use a performance profiler (in your case, profiling
the python code part should be sufficient) to spot algorithmic
parts of your check that can be improved.<br>
By using the Python interface, some computational overhead
compared to plain C/C++ is unavoidable. Especially, an extensive
use of dictionary lookups (instead of arrays) is very pythonic,
but may result in a computational disaster, IMHO. The same holds
for return types, I would definitely use tuples instead
dictionaries, wherever I have the freedom. <br>
<br>
I hope this gives you some hints how to further optimize your
application.<br>
<br>
Happy profiling,<br>
Gregor<br>
<br>
<br>
<br>
Am 30.03.2017 um 21:28 schrieb Julain Stebler:<br>
</div>
<blockquote
cite="mid:CAM4HdxQqvAA7KA0+qHWVhWdmZ7goGrv3AAEv2u6RXOEn0Eo4=w@mail.gmail.com"
type="cite">
<div dir="ltr">
<div dir="ltr" class="gmail_msg">
<div dir="ltr" class="gmail_msg">Hello Everybody
<div class="gmail_msg"><br class="gmail_msg">
</div>
<div class="gmail_msg">I like your Python interface for the
SCIP Optimization Suite. And I would like to learn more
about the plugins. For that I try to solve following
Election Problem:</div>
<div class="gmail_msg"><br class="gmail_msg">
</div>
<div class="gmail_msg">I have a grid with the size of 10x10
(100 pieces/states). Every piece represents a state and
every state has votes.</div>
<div class="gmail_msg">Votes for democrats and votes for
republicans. The votes for the republicans are two times
higher.</div>
<div class="gmail_msg">The sum of ten states defines which
party wins the vote for the constituency. So there are 10
constituency.<br class="gmail_msg">
The goal is that the party with the lower number of votes
wins the most constituency more precisely wins the
election.</div>
<div class="gmail_msg">Now to make the whole part more
trickier, I want that the constituency are all aside.
Which means the constituency grid should look something
like this:</div>
<div class="gmail_msg">[1, 1, 1, 1, 2, 2, 2, 5, 5, 6</div>
<div class="gmail_msg"> 1, 1, 1, 1, 1, 2, 2, 2, 5, 6</div>
<div class="gmail_msg"> 1, 4, 4, 4, 4, 2, 2, 2, 5, 6</div>
<div class="gmail_msg"> 3, 3, 4, 4, 4, 2, 5, 5, 5,6</div>
<div class="gmail_msg"> ....</div>
<div class="gmail_msg"> ....]</div>
<div class="gmail_msg">
<div class="gmail_msg">The number represents the number of
the constituency which won the election.</div>
<div class="gmail_msg"><br class="gmail_msg">
</div>
<div class="gmail_msg">To check if the winning
constituency are aside I would like to use my own
constraint handler. But I do not know which method (<a
moz-do-not-send="true"
href="http://scip.zib.de/doc/html/CONS.php">http://scip.zib.de/doc/html/CONS.php</a>)
I should use. </div>
<div class="gmail_msg">At the moment I
implemented 'conscheck' and 'consenfolp'. But the time
to check the correctness is way to long.</div>
<div class="gmail_msg">I am not sure if this is possible,
but I would like to call my handler for every solution
the solver sets the constituency of a state.</div>
<div class="gmail_msg"><br>
</div>
<div class="gmail_msg">
<div class="gmail_msg">The code for my election problem
with the handler can be found here:</div>
<div class="gmail_msg"><a moz-do-not-send="true"
href="https://gist.github.com/bhzunami/54cbc4f5ce37ba88e8c91d4ece0a4b56">https://gist.github.com/bhzunami/54cbc4f5ce37ba88e8c91d4ece0a4b56</a></div>
<div class="gmail_msg"><br>
</div>
</div>
<div class="gmail_msg">If there is a better idea I am
happy to hear it.</div>
<div class="gmail_msg">If something is not clear please
ask back or make some comments in the gist.</div>
<div class="gmail_msg"><br>
</div>
<div class="gmail_msg">Thank you for your help and time.<br>
</div>
<div class="gmail_msg"><br>
</div>
<div class="gmail_msg">Kind regards</div>
<div class="gmail_msg">Nicolas</div>
<div class="gmail_msg"><br>
</div>
<br
class="m_-9016179870582273115inbox-inbox-Apple-interchange-newline
gmail_msg">
</div>
<div class="gmail_msg"><br class="gmail_msg">
</div>
<div class="gmail_msg"><br>
</div>
<div class="gmail_msg"><br class="gmail_msg">
</div>
<div class="gmail_msg"><br class="gmail_msg">
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Scip mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Scip@zib.de">Scip@zib.de</a>
<a class="moz-txt-link-freetext" href="https://listserv.zib.de/mailman/listinfo/scip">https://listserv.zib.de/mailman/listinfo/scip</a>
</pre>
</blockquote>
<br>
</body>
</html>