メインコンテンツへスキップ

A bug of setting warm-start basis using gurobipy

回答済み

コメント

2件のコメント

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Cheng,

    Numpy uses its own types, eg

    >>> type(np.array([1])[0])
    numpy.int64

    Numpy is not a dependency of gurobipy (unless matrix API is used) and so we cannot check for this type.  You can however convert individual numpy ints to standard ints using .item()

    >>> type(np.array([1])[0].item())
    int

    but the best course of action in your example is to convert the numpy arrays to lists and set all vbasis and cbasis information in one step, rather than using the enumeration approach which is slow

    model.setAttr("VBasis", model.getVars(), basis.vbasis.tolist())
    model.setAttr("CBasis", model.getConstrs(), basis.cbasis.tolist())

    Depending on your application, it may make sense to convert to lists within your dataclass.

    - Riley

    1
  • Chengwenjian Wang
    Gurobi-versary
    First Question
    First Comment

    Hi Riley,

    Thank you very much for your detailed explanation. It works now!

    Best regards,

    Cheng

    0

サインインしてコメントを残してください。