/* Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. File : midual1.cs Purpose: Demonstrates how to compute dual values with respect to a fixed integer solution for a MIO problem. minimize 500 s1 + 300 s2 + 10 x1 + 14 x2 subject to x1 + x2 >= 100 0 <= x1 <= 70 s1 0 <= x2 <= 80 s2 s1, s2 - binary */ using System; namespace mosek.example { public class MsgClass : mosek.Stream { public MsgClass () {} public override void streamCB (string msg) { Console.Write ("{0}", msg); } } public class midual1 { public static string midual1_ptf = String.Join("\n", new string[] { "Task midual1", "Objective", " Minimize + 10 x1 + 14 x2 + 500 s1 + 300 s2", "Constraints", " 'demand' [100] + x1 + x2", " 'production1' [-inf;0] + x1 - 70 s1", " 'production2' [-inf;0] + x2 - 80 s2", "Variables", " x1 [0;+inf]", " x2 [0;+inf]", " s1 [0;1]", " s2 [0;1]", "Integers", " s1 s2"}); public static void Main () { using (Task task = new Task()) { MsgClass task_msg_obj = new MsgClass (); task.set_Stream(mosek.streamtype.log, task_msg_obj); task.putintparam(mosek.iparam.log_include_summary, 1); /* Task is the original mixed-integer problem */ task.readptfstring(midual1_ptf); task.optimize(); if (task.getprosta(mosek.soltype.itg) != mosek.prosta.prim_feas) throw new System.Exception("Unsuitable problem status, exiting"); double[] xx = task.getxxslice(mosek.soltype.itg, 0, 2); Console.WriteLine ("x = {0}, {1}", xx[0], xx[1]); /* Construct the continuous problem with fixed variables */ using (Task fixTask = task.getfixedproblem()) { fixTask.set_Stream(mosek.streamtype.log, task_msg_obj); fixTask.optimize(); if (fixTask.getprosta(mosek.soltype.bas) != mosek.prosta.prim_and_dual_feas) throw new System.Exception("Unsuitable problem status, exiting"); double[] xfix = fixTask.getxxslice(mosek.soltype.bas, 0, 2); double[] y = fixTask.getyslice(mosek.soltype.bas, 0, 3); Console.WriteLine ("xfix = {0}, {1}", xfix[0], xfix[1]); Console.WriteLine ("demand dual = {0}", y[0]); Console.WriteLine ("production dual = {0}, {1}", y[1], y[2]); } } } } }