Skip to content

Instantly share code, notes, and snippets.

@Kovak
Created September 18, 2013 09:34
Show Gist options
  • Save Kovak/6606793 to your computer and use it in GitHub Desktop.
Save Kovak/6606793 to your computer and use it in GitHub Desktop.
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