Getting started¶
This page takes you from an empty folder to your first CBF file in about five minutes.
Install¶
You need Python 3.12 or newer and git (pip uses it to download
misdp). misdp depends only on numpy and scipy; pip installs them for you.
Create a virtual environment and install misdp from GitHub:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install "misdp @ git+https://github.com/tpse-tuda/MISDP.git@v0.1.0"
On Windows, create the environment with py -3.12 -m venv .venv (or -3.13) and
activate it with .venv\Scripts\activate instead. Plain py takes the newest installed
Python, which may be newer than the versions misdp is tested with; py -0p lists the
installed ones. If PowerShell says that running scripts is disabled, run
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once, or use the Command Prompt.
Inside the activated environment, python is the environment's Python on every system.
If Windows blocks the pip launcher in .venv\Scripts (Smart App Control can),
python -m pip does the same.
The @v0.1.0 at the end installs this release. Without it, pip installs the current
state of the main branch.
Check that it worked:
python -c "import misdp; print(misdp.__version__)"
Your first model¶
Here is a small problem with two integer variables and one linear matrix inequality (LMI):
min y1 + y2
s.t. [ y1 1.5 ]
[ 1.5 y2 ] is positive semidefinite
y1, y2 integer
The matrix is positive semidefinite exactly when y1 >= 0, y2 >= 0 and
y1 * y2 >= 2.25. Without integrality the optimum is 3 at y1 = y2 = 1.5; with
integrality it is 4, for example at y1 = 1, y2 = 3.
Save this as first_model.py and run it with python first_model.py:
import misdp as ms
m = ms.Model("beispiel_a")
y1 = m.add_var("y1", vtype="integer")
y2 = m.add_var("y2", vtype="integer")
m.add_constraint(ms.matrix([[y1, 1.5], [1.5, y2]]) >> 0, name="lmi")
m.optimize(y1 + y2)
print(m.summary())
m.write("beispiel_a.cbf")
Line by line:
ms.Model(...)creates an empty model with a name.add_varcreates a scalar variable.vtypeis"continuous"(the default),"integer"or"binary";lbandubset bounds.ms.matrix(...)builds a symmetric matrix from variables and numbers, and>> 0says "is positive semidefinite".m.add_constraintadds the constraint to the model;name="lmi"names it in the summary and in the file.m.optimize(...)sets the objective. It minimizes by default;sense="max"maximizes.m.summary()returns an overview of the model as text;m.write(...)writes the CBF file.
The CBF file¶
beispiel_a.cbf is a plain text file in the
Conic Benchmark Format, version 2. It starts with a
few comment lines (# misdp-...) that store the names you chose; solvers ignore them. Here
is the rest, the problem itself:
VER
2
OBJSENSE
MIN
VAR
2 1
F 2
INT
2
0
1
PSDCON
1
2
OBJACOORD
2
0 1.0
1 1.0
HCOORD
2
0 0 0 0 1.0
0 1 1 1 1.0
DCOORD
1
0 1 0 1.5
VAR declares two free variables, INT marks both as integer, PSDCON declares one
2×2 matrix constraint, OBJACOORD holds the objective, and HCOORD and DCOORD hold the
matrix entries. A HCOORD line 0 1 1 1 1.0 reads: PSD constraint 0, variable 1 (y2),
matrix entry (1, 1), coefficient 1.0. Only the lower triangle (row ≥ column) is stored.
The Concepts page explains the dual form behind this layout.
Solve it¶
misdp does not solve problems; SCIP-SDP does,
and it is installed separately (see the build instructions in its repository). With
SCIP-SDP installed, run:
scipsdp -c "read beispiel_a.cbf optimize display solution quit"
SCIP-SDP reports optimal solution found and objective value: 4 (checked with SCIP-SDP 4.4.0).
Next steps¶
- The Tutorial builds three classic models step by step.
- Concepts explains what happens between your code and the file.
- The API reference lists every class and function on the built site; in
Python,
help(ms.Model)shows the same text.