Skip to content

Commit

Permalink
add fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgen-lentz committed Oct 4, 2024
1 parent a3891de commit c8ed13a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 82 deletions.
70 changes: 35 additions & 35 deletions amplpy/ampl.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,43 @@ cdef extern from "ampl/ampl_c.h":
AMPL_STRING

ctypedef enum AMPL_STRINGSUFFIX:
astatus
sstatus
status
message
result
sense
AMPL_ASTATUS
AMPL_SSTATUS
AMPL_STATUS
AMPL_MESSAGE
AMPL_RESULT
AMPL_SENSE

ctypedef enum AMPL_NUMERICSUFFIX:
VALUE
DEFEQN
DUAL
INIT
INIT0
LB
UB
LB0
UB0
LB1
UB1
LB2
UB2
LRC
URC
LSLACK
USLACK
RC
SLACK
BODY
DEFVAR
DINIT
DINIT0
LBS
UBS
LDUAL
UDUAL
VAL
EXITCODE
AMPL_VALUE
AMPL_DEFEQN
AMPL_DUAL
AMPL_INIT
AMPL_INIT0
AMPL_LB
AMPL_UB
AMPL_LB0
AMPL_UB0
AMPL_LB1
AMPL_UB1
AMPL_LB2
AMPL_UB2
AMPL_LRC
AMPL_URC
AMPL_LSLACK
AMPL_USLACK
AMPL_RC
AMPL_SLACK
AMPL_BODY
AMPL_DEFVAR
AMPL_DINIT
AMPL_DINIT0
AMPL_LBS
AMPL_UBS
AMPL_LDUAL
AMPL_UDUAL
AMPL_VAL
AMPL_EXITCODE

const char* NUMERICSUFFIXES[29]

Expand Down
36 changes: 18 additions & 18 deletions amplpy/constraint.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ cdef class Constraint(Entity):
Get the current value of the constraint's body.
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.BODY, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_BODY, &value)
return value

def astatus(self):
"""
Get the current AMPL status (dropped, presolved, or substituted out).
"""
cdef char* value_c
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_STRINGSUFFIX.astatus, &value_c)
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_STRINGSUFFIX.AMPL_ASTATUS, &value_c)
value = str(value_c.decode('utf-8'))
campl.AMPL_StringFree(&value_c)
return value
Expand All @@ -95,23 +95,23 @@ cdef class Constraint(Entity):
constraint.
"""
cdef int value
campl.AMPL_InstanceGetIntSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.DEFVAR, &value)
campl.AMPL_InstanceGetIntSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_DEFVAR, &value)
return value

def dinit(self):
"""
Get the current initial guess for the constraint's dual variable.
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.DINIT, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_DINIT, &value)
return value

def dinit0(self):
"""
Get the original initial guess for the constraint's dual variable.
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.DINIT0, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_DINIT0, &value)
return value

def dual(self):
Expand All @@ -124,23 +124,23 @@ cdef class Constraint(Entity):
(see :func:`~amplpy.AMPL.setOption`).
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.DUAL, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_DUAL, &value)
return value

def lb(self):
"""
Get the current value of the constraint's lower bound.
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.LB, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_LB, &value)
return value

def ub(self):
"""
Get the current value of the constraint's upper bound.
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.UB, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_UB, &value)
return value

def lbs(self):
Expand All @@ -149,7 +149,7 @@ cdef class Constraint(Entity):
adjustment for fixed variables).
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.LBS, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_LBS, &value)
return value

def ubs(self):
Expand All @@ -158,47 +158,47 @@ cdef class Constraint(Entity):
adjustment for fixed variables).
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.UBS, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_UBS, &value)
return value

def ldual(self):
"""
Get the current dual value associated with the lower bound.
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.LDUAL, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_LDUAL, &value)
return value

def udual(self):
"""
Get the current dual value associated with the upper bounds.
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.UDUAL, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_UDUAL, &value)
return value

def lslack(self):
"""
Get the slack at lower bound `body - lb`.
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.LSLACK, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_LSLACK, &value)
return value

def uslack(self):
"""
Get the slack at upper bound `ub - body`.
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.USLACK, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_USLACK, &value)
return value

def slack(self):
"""
Constraint slack (the lesser of lslack and uslack).
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.SLACK, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_SLACK, &value)
return value

def sstatus(self):
Expand All @@ -207,7 +207,7 @@ cdef class Constraint(Entity):
variable).
"""
cdef char* value_c
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_STRINGSUFFIX.sstatus, &value_c)
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_STRINGSUFFIX.AMPL_SSTATUS, &value_c)
value = str(value_c.decode('utf-8'))
campl.AMPL_StringFree(&value_c)
return value
Expand All @@ -217,7 +217,7 @@ cdef class Constraint(Entity):
Get the AMPL status if not `in`, otherwise solver status.
"""
cdef char* value_c
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_STRINGSUFFIX.status, &value_c)
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_STRINGSUFFIX.AMPL_STATUS, &value_c)
value = str(value_c.decode('utf-8'))
campl.AMPL_StringFree(&value_c)
return value
Expand Down Expand Up @@ -245,7 +245,7 @@ cdef class Constraint(Entity):
"""
cdef double value
if self.is_logical():
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.VAL, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), self._index, campl.AMPL_NUMERICSUFFIX.AMPL_VAL, &value)
return value
else:
return None
Expand Down
14 changes: 7 additions & 7 deletions amplpy/objective.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ cdef class Objective(Entity):
Get the value of the objective.
"""
cdef double value
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_NUMERICSUFFIX.VALUE, &value)
campl.AMPL_InstanceGetDoubleSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_NUMERICSUFFIX.AMPL_VALUE, &value)
return value

def astatus(self):
"""
Return the AMPL status.
"""
cdef char* value_c
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_STRINGSUFFIX.astatus, &value_c)
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_STRINGSUFFIX.AMPL_ASTATUS, &value_c)
value = str(value_c.decode('utf-8'))
campl.AMPL_StringFree(&value_c)
return value
Expand All @@ -53,7 +53,7 @@ cdef class Objective(Entity):
Return the solver status.
"""
cdef char* value_c
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_STRINGSUFFIX.sstatus, &value_c)
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_STRINGSUFFIX.AMPL_SSTATUS, &value_c)
value = str(value_c.decode('utf-8'))
campl.AMPL_StringFree(&value_c)
return value
Expand All @@ -64,7 +64,7 @@ cdef class Objective(Entity):
objective.
"""
cdef int value
campl.AMPL_InstanceGetIntSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_NUMERICSUFFIX.EXITCODE, &value)
campl.AMPL_InstanceGetIntSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_NUMERICSUFFIX.AMPL_EXITCODE, &value)
return value

def message(self):
Expand All @@ -73,7 +73,7 @@ cdef class Objective(Entity):
objective.
"""
cdef char* value_c
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_STRINGSUFFIX.message, &value_c)
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_STRINGSUFFIX.AMPL_MESSAGE, &value_c)
value = str(value_c.decode('utf-8'))
campl.AMPL_StringFree(&value_c)
return value
Expand All @@ -84,7 +84,7 @@ cdef class Objective(Entity):
objective.
"""
cdef char* value_c
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_STRINGSUFFIX.result, &value_c)
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_STRINGSUFFIX.AMPL_RESULT, &value_c)
value = str(value_c.decode('utf-8'))
campl.AMPL_StringFree(&value_c)
return value
Expand All @@ -107,7 +107,7 @@ cdef class Objective(Entity):
False if maximize.
"""
cdef char* value_c
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_STRINGSUFFIX.sense, &value_c)
campl.AMPL_InstanceGetStringSuffix(self._c_ampl, self._name.encode('utf-8'), NULL, campl.AMPL_STRINGSUFFIX.AMPL_SENSE, &value_c)
value = str(value_c.decode('utf-8'))
campl.AMPL_StringFree(&value_c)
if value == 'minimize':
Expand Down
Loading

0 comments on commit c8ed13a

Please sign in to comment.