Created
September 18, 2013 09:34
-
-
Save Kovak/6606793 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constraint_handlers = {} | |
from cpython.ref cimport PyObject | |
cdef void _call_constraint_presolve_func(cpConstraint *constraint, cpSpace *space): | |
global constraint_handlers | |
global current_spaces | |
py_space = current_spaces[0] | |
python_constraint = constraint.data | |
constraint_dict = constraint_handlers[python_constraint] | |
constraint_dict['pre_solve'](constraint_dict['constraint'], py_space) | |
cdef class Constraint: | |
def __init__(self, args): | |
self._constraint = cpConstraint() | |
cdef PyObject* ptr = <PyObject*>self | |
self._constraint.data = <cpDataPointer>ptr | |
global constraint_handlers | |
constraint_handlers[self._constraint.data] = {'constraint': self} | |
property pre_solve: | |
def __set__(self, func): | |
self._set_py_presolve_handler(func) | |
self._constraint.preSolve = _call_constraint_presolve_func | |
def _set_py_presolve_handler(self, presolve_func): | |
global constraint_handlers | |
constraint_handlers[self._constraint.data]['pre_solve'] = presolve_func |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment