Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Speed up `ProdExpr.__neg__` and `Constant.__neg__` via C-level API (#1250)
- Extended `structured_optimization_trace` recipe to support context-managed JSONL tracing with final `run_end` records, alongside the existing attach-style in-memory tracing.
### Removed
- `SumExpr`.coefs has been removed; its values were always 1.0 (#1258)

## 6.2.1 - 2026.05.16
### Fixed
Expand Down
14 changes: 2 additions & 12 deletions src/pyscipopt/expr.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -582,24 +582,20 @@ cdef class GenExpr(ExprLike):

# add left term
if left.getOp() == Operator.add:
ans.coefs.extend(left.coefs)
ans.children.extend(left.children)
ans.constant += left.constant
elif left.getOp() == Operator.const:
ans.constant += left.number
else:
ans.coefs.append(1.0)
ans.children.append(left)

# add right term
if right.getOp() == Operator.add:
ans.coefs.extend(right.coefs)
ans.children.extend(right.children)
ans.constant += right.constant
elif right.getOp() == Operator.const:
ans.constant += right.number
else:
ans.coefs.append(1.0)
ans.children.append(right)

return ans
Expand All @@ -615,18 +611,15 @@ cdef class GenExpr(ExprLike):
# if self.getOp() == Operator.const:
# newsum.constant += self.number
# else:
# newsum.coefs.append(1.0)
# newsum.children.append(self.copy()) # TODO: what is copy?
# self = newsum
# # add right term
# if right.getOp() == Operator.add:
# self.coefs.extend(right.coefs)
# self.children.extend(right.children)
# self.constant += right.constant
# elif right.getOp() == Operator.const:
# self.constant += right.number
# else:
# self.coefs.append(1.0)
# self.children.append(right)
# return self

Expand Down Expand Up @@ -740,31 +733,28 @@ cdef class GenExpr(ExprLike):
cdef class SumExpr(GenExpr):

cdef public constant
cdef public coefs

def __init__(self):
self.constant = 0.0
self.coefs = []
self.children = []
self._op = Operator.add

def __repr__(self):
return self._op + "(" + str(self.constant) + "," + ",".join(map(lambda child : child.__repr__(), self.children)) + ")"

cpdef double _evaluate(self, Solution sol) except *:
cdef double res = self.constant
cdef int i = 0, n = len(self.children)
cdef list children = self.children
cdef list coefs = self.coefs
for i in range(n):
res += <double>coefs[i] * (<GenExpr>children[i])._evaluate(sol)
res += (<GenExpr>children[i])._evaluate(sol)
return res

cdef SumExpr copy(self, bint copy=True):
cdef SumExpr res = SumExpr.__new__(SumExpr)
res._op = self._op
res.children = self.children.copy() if copy else self.children
res.constant = self.constant
res.coefs = self.coefs.copy() if copy else self.coefs
return res


Expand Down
1 change: 0 additions & 1 deletion src/pyscipopt/scip.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2354,7 +2354,6 @@ class Statistics:

@disjoint_base
class SumExpr(GenExpr):
coefs: Incomplete
constant: Incomplete
def __init__(self, *args: Incomplete, **kwargs: Incomplete) -> None: ...
def __neg__(self, /) -> ProdExpr: ...
Expand Down
Loading