# Example based on https://metab0t.github.io/PyOptInterface/
# and equipped with demonstration of some MOSEK-specific elements.
import pyoptinterface as poi
from pyoptinterface import mosek as pyoptmosek
import mosek

model = pyoptmosek.Model()

x = model.add_variable(lb = 0, ub = 1, domain = poi.VariableDomain.Continuous, name = "x")
y = model.add_variable(lb = 0, ub = 1, domain = poi.VariableDomain.Integer, name = "y")
con = model.add_linear_constraint(x + y >= 1.2, name = "con")
model.set_objective(2 * x, poi.ObjectiveSense.Minimize)

model.set_model_attribute(poi.ModelAttribute.Silent, False)

# Set some MOSEK parameters
model.set_raw_parameter("MSK_DPAR_OPTIMIZER_MAX_TIME", 10.0)
model.set_raw_parameter("MSK_IPAR_INTPNT_SOLVE_FORM",  int(mosek.solveform.dual))   # Must explicitly convert to int or know the value
model.set_raw_parameter("MSK_IPAR_NUM_THREADS",  "2")

# How to write a task file
model.write("dump.task.gz")   # Binary
model.write("dump.ptf")       # Human-readable

model.optimize()

print(model.get_model_attribute(poi.ModelAttribute.TerminationStatus))
x_val = model.get_value(x)
y_val = model.get_value(y)
