Skip to content

BUG: _VarArray can't handle MatrixVar #1043

@Zeroto521

Description

@Zeroto521

Describe the bug

_VarArray will raise an error when vars is a MatrixVar.

To Reproduce

from pyscipopt import Model

model = Model()
x = model.addVar()
binvar = model.addMatrixVar(1, vtype="B")
model.addConsIndicator(x >= 1, binvar)
# ---------------------------------------------------------------------------
# TypeError                                 Traceback (most recent call last)
# Cell In[3], line 1
# ----> 1 model.addConsIndicator(x >= 1, binvar)
# 
# File src/pyscipopt/scip.pxi:6834, in pyscipopt.scip.Model.addConsIndicator()
# 
# File src/pyscipopt/scip.pxi:2457, in pyscipopt.scip._VarArray.__cinit__()
# 
# TypeError: Expected Variable or list of Variable, got <class 'pyscipopt.scip.MatrixVariable'>.

cdef class _VarArray:
cdef SCIP_VAR** ptr
cdef int size
def __cinit__(self, object vars):
if isinstance(vars, Variable):
self.size = 1
self.ptr = <SCIP_VAR**> malloc(sizeof(SCIP_VAR*))
self.ptr[0] = (<Variable>vars).scip_var
else:
if not isinstance(vars, (list, tuple)):
raise TypeError("Expected Variable or list of Variable, got %s." % type(vars))

Expected behavior

The result of MatrixVar should be like list and tuple.

Screenshots

Image

System

  • OS: Windows 11
  • Version: 24H2 (26100.4061)
  • SCIP version: 9.2.3
  • How did you install pyscipopt?: build from b4a70f5, base on 5.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions