public static void Main (String[] args) { mosek.Env env = null; mosek.Task task = null; mosek.Task[] task_list = new mosek.Task[] { null }; try { // Create mosek environment. env = new mosek.Env (); // Create a task object linked with the environment env. task = new mosek.Task (env, 0,0); // Directs the log task stream to the user specified // method task_msg_obj.streamCB task.set_Stream (mosek.streamtype.log, new msgclass ("simplex: ")); task_list[0] = new mosek.Task (env, 0,0); task_list[0].set_Stream (mosek.streamtype.log, new msgclass ("intrpnt: ")); task.readdata(args[0]); // Assign different parameter values to each task. // In this case different optimizers. task.putintparam(mosek.iparam.optimizer, mosek.optimizertype.primal_simplex); task_list[0].putintparam(mosek.iparam.optimizer, mosek.optimizertype.intpnt); // Optimize task and task_list[0] in parallel. // The problem data i.e. C, A, etc. // is copied from task to task_list[0]. task.optimizeconcurrent(task_list); task.solutionsummary(mosek.streamtype.log); } catch (mosek.Exception e) { Console.WriteLine (e.Code); Console.WriteLine (e); } if (task != null) task.Dispose (); if (env != null) env.Dispose (); }
public static void Main () { const int numcon = 3; const int numvar = 4; // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; double[] c = {3.0, 1.0, 5.0, 1.0}; int[][] asub = { new int[] {0,1,2}, new int[] {0,1,2,3}, new int[] {1,3} }; double[][] aval = { new double[] {3.0,1.0,2.0}, new double[] {2.0,1.0,3.0,1.0}, new double[] {2.0,3.0} }; mosek.boundkey[] bkc = {mosek.boundkey.fx, mosek.boundkey.lo, mosek.boundkey.up}; double[] blc = {30.0, 15.0, -infinity}; double[] buc = {30.0, +infinity, 25.0}; mosek.boundkey[] bkx = {mosek.boundkey.lo, mosek.boundkey.ra, mosek.boundkey.lo, mosek.boundkey.lo}; double[] blx = {0.0, 0.0, 0.0, 0.0}; double[] bux = {+infinity, 10.0, +infinity, +infinity}; mosek.Task task = null; mosek.Env env = null; double[] xx = new double[numvar]; try { // Make mosek environment. env = new mosek.Env (); // Create a task object linked with the environment env. task = new mosek.Task (env, 0,0); // Directs the log task stream to the user specified // method task_msg_obj.streamCB task.set_Stream (mosek.streamtype.log, new msgclass ("")); /* Give MOSEK an estimate of the size of the input data. This is done to increase the speed of inputting data. However, it is optional. */ /* Append 'numcon' empty constraints. The constraints will initially have no bounds. */ task.appendcons(numcon); /* Append 'numvar' variables. The variables will initially be fixed at zero (x=0). */ task.appendvars(numvar); /* Optionally add a constant term to the objective. */ task.putcfix(0.0); for(int j=0; j<numvar; ++j) { /* Set the linear term c_j in the objective.*/ task.putcj(j,c[j]); /* Set the bounds on variable j. blx[j] <= x_j <= bux[j] */ task.putvarbound(j,bkx[j],blx[j],bux[j]); } /* Set the bounds on constraints. for i=1, ...,numcon : blc[i] <= constraint i <= buc[i] */ for(int i=0; i<numcon; ++i) { task.putconbound(i,bkc[i],blc[i],buc[i]); /* Input row i of A */ task.putarow(i, /* Row index.*/ asub[i], /* Column indexes of non-zeros in row i.*/ aval[i]); /* Non-zero Values of row i. */ } task.putobjsense(mosek.objsense.maximize); task.optimize(); // Print a summary containing information // about the solution for debugging purposes task.solutionsummary(mosek.streamtype.msg); mosek.solsta solsta; /* Get status information about the solution */ task.getsolsta(mosek.soltype.bas, out solsta); task.getxx(mosek.soltype.bas, // Basic solution. xx); switch(solsta) { case mosek.solsta.optimal: case mosek.solsta.near_optimal: Console.WriteLine ("Optimal primal solution\n"); for(int j = 0; j < numvar; ++j) Console.WriteLine ("x[{0}]:",xx[j]); break; case mosek.solsta.dual_infeas_cer: case mosek.solsta.prim_infeas_cer: case mosek.solsta.near_dual_infeas_cer: case mosek.solsta.near_prim_infeas_cer: Console.WriteLine("Primal or dual infeasibility.\n"); break; case mosek.solsta.unknown: Console.WriteLine("Unknown solution status.\n"); break; default: Console.WriteLine("Other solution status"); break; } } catch (mosek.Exception e) { Console.WriteLine (e.Code); Console.WriteLine (e); throw; } finally { if (task != null) task.Dispose (); if (env != null) env.Dispose (); } }
public static void Main () { mosek.Env env = null; mosek.Task task = null; // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; int numvar = 4; int numcon = 1; int NUMINTVAR = 3; double[] c = { 7.0, 10.0, 1.0, 5.0 }; mosek.boundkey[] bkc = {mosek.boundkey.up}; double[] blc = {-infinity}; double[] buc = {2.5}; mosek.boundkey[] bkx = {mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo}; double[] blx = {0.0, 0.0, 0.0, 0.0}; double[] bux = {infinity, infinity, infinity, infinity}; int[] ptrb = {0, 1, 2, 3}; int[] ptre = {1, 2, 3, 4}; double[] aval = {1.0, 1.0, 1.0, 1.0}; int[] asub = {0, 0, 0, 0 }; int[] intsub = {0, 1, 2}; double[] xx = new double[numvar]; try { // Make mosek environment. env = new mosek.Env (); // Create a task object linked with the environment env. task = new mosek.Task (env, numcon,numvar); // Directs the log task stream to the user specified // method task_msg_obj.streamCB task.set_Stream (mosek.streamtype.log, new msgclass ("[task]")); task.inputdata(numcon,numvar, c, 0.0, ptrb, ptre, asub, aval, bkc, blc, buc, bkx, blx, bux); for(int j=0 ; j<NUMINTVAR ; ++j) task.putvartype(intsub[j],mosek.variabletype.type_int); task.putobjsense(mosek.objsense.maximize); // Construct an initial feasible solution from the // values of the integer valuse specified task.putintparam(mosek.iparam.mio_construct_sol, mosek.onoffkey.on); // Set status of all variables to unknown //task.makesolutionstatusunknown(mosek.soltype.itg); // Assign values 0,2,0 to integer variables. Important to // assign a value to all integer constrained variables. double[] values={0.0, 2.0, 0.0}; task.putxxslice(mosek.soltype.itg, 0, 3, values); try { task.optimize(); } catch (mosek.Warning w) { Console.WriteLine("Mosek warning:"); Console.WriteLine (w.Code); Console.WriteLine (w); } task.getsolutionslice(mosek.soltype.itg, /* Basic solution. */ mosek.solitem.xx, /* Which part of solution. */ 0, /* Index of first variable. */ numvar, /* Index of last variable+1 */ xx); for(int j = 0; j < numvar; ++j) Console.WriteLine ("x[{0}]:{1}", j,xx[j]); } catch (mosek.Exception e) { Console.WriteLine (e.Code); Console.WriteLine (e); throw; } if (task != null) task.Dispose (); if (env != null) env.Dispose (); }
public static void Main () { // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; const int numcon = 3; const int numvar = 3; double[] c = {1.5, 2.5, 3.0}; mosek.boundkey[] bkc = {mosek.boundkey.up, mosek.boundkey.up, mosek.boundkey.up}; double[] blc = {-infinity, -infinity, -infinity}; double[] buc = {100000, 50000, 60000}; mosek.boundkey[] bkx = {mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo}; double[] blx = {0.0, 0.0, 0.0}; double[] bux = {+infinity, +infinity, +infinity}; int[][] asub = new int[numvar][]; asub[0] = new int[] {0, 1, 2}; asub[1] = new int[] {0, 1, 2}; asub[2] = new int[] {0, 1, 2}; double[][] aval = new double[numvar][]; aval[0] = new double[] { 2.0, 3.0, 2.0 }; aval[1] = new double[] { 4.0, 2.0, 3.0 }; aval[2] = new double[] { 3.0, 3.0, 2.0 }; double[] xx = new double[numvar]; mosek.Task task = null; mosek.Env env = null; try { // Create mosek environment. env = new mosek.Env (); // Create a task object linked with the environment env. task = new mosek.Task (env, numcon,numvar); /* Append the constraints. */ task.appendcons(numcon); /* Append the variables. */ task.appendvars(numvar); /* Put C. */ task.putcfix(0.0); for(int j=0; j<numvar; ++j) task.putcj(j,c[j]); /* Put constraint bounds. */ for(int i=0; i<numcon; ++i) task.putbound(mosek.accmode.con,i,bkc[i],blc[i],buc[i]); /* Put variable bounds. */ for(int j=0; j<numvar; ++j) task.putbound(mosek.accmode.var,j,bkx[j],blx[j],bux[j]); /* Put A. */ if ( numcon>0 ) { for(int j=0; j<numvar; ++j) task.putacol(j, asub[j], aval[j]); } task.putobjsense(mosek.objsense.maximize); try { task.optimize(); } catch (mosek.Warning w) { Console.WriteLine("Mosek warning:"); Console.WriteLine (w.Code); Console.WriteLine (w); } task.getxx(mosek.soltype.bas, // Request the basic solution. xx); for(int j = 0; j < numvar; ++j) Console.WriteLine ("x[{0}]:{1}", j,xx[j]); /* Make a change to the A matrix */ task.putaij(0, 0, 3.0); task.optimize(); /* Get index of new variable. */ int varidx; task.getnumvar(out varidx); /* Append a new varaible x_3 to the problem */ task.appendvars(1); /* Set bounds on new varaible */ task.putbound(mosek.accmode.var, varidx, mosek.boundkey.lo, 0, +infinity); /* Change objective */ task.putcj(varidx,1.0); /* Put new values in the A matrix */ int[] acolsub = new int[] {0, 2}; double[] acolval = new double[] {4.0, 1.0}; task.putacol(varidx, /* column index */ acolsub, acolval); /* Change optimizer to simplex free and reoptimize */ task.putintparam(mosek.iparam.optimizer,mosek.optimizertype.free_simplex); task.optimize(); /* Get index of new constraint */ int conidx; task.getnumcon(out conidx); /* Append a new constraint */ task.appendcons(1); /* Set bounds on new constraint */ task.putbound( mosek.accmode.con, conidx, mosek.boundkey.up, -infinity, 30000); /* Put new values in the A matrix */ int[] arowsub = new int[] {0, 1, 2, 3 }; double[] arowval = new double[] {1.0, 2.0, 1.0, 1.0}; task.putarow(conidx, /* row index */ arowsub, arowval); task.optimize(); } catch (mosek.Exception e) { Console.WriteLine (e.Code); Console.WriteLine (e); } if (task != null) task.Dispose (); if (env != null) env.Dispose (); }
public static void Main () { const int numcon = 2; const int numvar = 2; // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; mosek.boundkey[] bkc = { mosek.boundkey.up, mosek.boundkey.lo }; double[] blc = { -infinity, -4.0 }; double[] buc = { 250.0, infinity }; mosek.boundkey[] bkx = { mosek.boundkey.lo, mosek.boundkey.lo }; double[] blx = { 0.0, 0.0 }; double[] bux = { infinity, infinity }; double[] c = {1.0, 0.64 }; int[][] asub = { new int[] {0, 1}, new int[] {0, 1} }; double[][] aval = { new double[] {50.0, 3.0},new double[] {31.0, -2.0} }; double[] xx = new double[numvar]; mosek.Env env = null; mosek.Task task = null; try { // Make mosek environment. env = new mosek.Env (); // Create a task object linked with the environment env. task = new mosek.Task (env, numcon,numvar); // Directs the log task stream to the user specified // method task_msg_obj.streamCB MsgClass task_msg_obj = new MsgClass (); task.set_Stream (mosek.streamtype.log,task_msg_obj); /* Give MOSEK an estimate of the size of the input data. This is done to increase the speed of inputting data. However, it is optional. */ /* Append 'numcon' empty constraints. The constraints will initially have no bounds. */ task.appendcons(numcon); /* Append 'numvar' variables. The variables will initially be fixed at zero (x=0). */ task.appendvars(numvar); /* Optionally add a constant term to the objective. */ task.putcfix(0.0); for(int j=0; j<numvar; ++j) { /* Set the linear term c_j in the objective.*/ task.putcj(j,c[j]); /* Set the bounds on variable j. blx[j] <= x_j <= bux[j] */ task.putvarbound(j,bkx[j],blx[j],bux[j]); /* Input column j of A */ task.putacol(j, /* Variable (column) index.*/ asub[j], /* Row index of non-zeros in column j.*/ aval[j]); /* Non-zero Values of column j. */ } /* Set the bounds on constraints. for i=1, ...,numcon : blc[i] <= constraint i <= buc[i] */ for(int i=0; i<numcon; ++i) task.putconbound(i,bkc[i],blc[i],buc[i]); /* Specify integer variables. */ for(int j=0; j<numvar; ++j) task.putvartype(j,mosek.variabletype.type_int); task.putobjsense(mosek.objsense.maximize); task.optimize(); // Print a summary containing information // about the solution for debugging purposes task.solutionsummary(mosek.streamtype.msg); mosek.solsta solsta; /* Get status information about the solution */ task.getsolsta(mosek.soltype.itg, out solsta); task.getxx(mosek.soltype.itg, // Integer solution. xx); switch(solsta) { case mosek.solsta.optimal: case mosek.solsta.near_optimal: Console.WriteLine ("Optimal primal solution\n"); for(int j = 0; j < numvar; ++j) Console.WriteLine ("x[{0}]:",xx[j]); break; case mosek.solsta.dual_infeas_cer: case mosek.solsta.prim_infeas_cer: case mosek.solsta.near_dual_infeas_cer: case mosek.solsta.near_prim_infeas_cer: Console.WriteLine("Primal or dual infeasibility.\n"); break; case mosek.solsta.unknown: mosek.prosta prosta; task.getprosta(mosek.soltype.itg,out prosta); switch(prosta) { case mosek.prosta.prim_infeas_or_unbounded: Console.WriteLine("Problem status Infeasible or unbounded"); break; case mosek.prosta.prim_infeas: Console.WriteLine("Problem status Infeasible."); break; case mosek.prosta.unknown: Console.WriteLine("Problem status unknown."); break; default: Console.WriteLine("Other problem status."); break; } break; default: Console.WriteLine("Other solution status"); break; } } catch (mosek.Exception e) { Console.WriteLine (e.Code); Console.WriteLine (e); throw; } finally { if (task != null) task.Dispose (); if (env != null) env.Dispose (); } }
public static void Main() { // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; const int NUMCON = 3; const int NUMVAR = 3; const int NUMANZ = 9; double[] c = { 1.5, 2.5, 3.0 }; mosek.boundkey[] bkc = { mosek.boundkey.up, mosek.boundkey.up, mosek.boundkey.up }; double[] blc = { -infinity, -infinity, -infinity }; double[] buc = { 100000, 50000, 60000 }; mosek.boundkey[] bkx = { mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo }; double[] blx = { 0.0, 0.0, 0.0 }; double[] bux = { +infinity, +infinity, +infinity }; int[][] asub = new int[NUMVAR][]; asub[0] = new int[] { 0, 1, 2 }; asub[1] = new int[] { 0, 1, 2 }; asub[2] = new int[] { 0, 1, 2 }; double[][] aval = new double[NUMVAR][]; aval[0] = new double[] { 2.0, 3.0, 2.0 }; aval[1] = new double[] { 4.0, 2.0, 3.0 }; aval[2] = new double[] { 3.0, 3.0, 2.0 }; double[] xx = new double[NUMVAR]; mosek.Task task = null; mosek.Env env = null; try { // Create mosek environment. env = new mosek.Env(); // Initialize the environment. env.init(); // Create a task object linked with the environment env. task = new mosek.Task(env, NUMCON, NUMVAR); /* Give MOSEK an estimate on the size of * the data to input. This is done to increase * the speed of inputting data and is optional.*/ task.putmaxnumvar(NUMVAR); task.putmaxnumcon(NUMCON); task.putmaxnumanz(NUMANZ); /* Append the constraints. */ task.append(mosek.accmode.con, NUMCON); /* Append the variables. */ task.append(mosek.accmode.var, NUMVAR); /* Put C. */ task.putcfix(0.0); for (int j = 0; j < NUMVAR; ++j) { task.putcj(j, c[j]); } /* Put constraint bounds. */ for (int i = 0; i < NUMCON; ++i) { task.putbound(mosek.accmode.con, i, bkc[i], blc[i], buc[i]); } /* Put variable bounds. */ for (int j = 0; j < NUMVAR; ++j) { task.putbound(mosek.accmode.var, j, bkx[j], blx[j], bux[j]); } /* Put A. */ if (NUMCON > 0) { for (int j = 0; j < NUMVAR; ++j) { task.putavec(mosek.accmode.var, j, asub[j], aval[j]); } } task.putobjsense(mosek.objsense.maximize); try { task.optimize(); } catch (mosek.Warning w) { Console.WriteLine("Mosek warning:"); Console.WriteLine(w.Code); Console.WriteLine(w); } task.getsolutionslice(mosek.soltype.bas, /* Basic solution. */ mosek.solitem.xx, /* Which part of solution. */ 0, /* Index of first variable. */ NUMVAR, /* Index of last variable+1 */ xx); for (int j = 0; j < NUMVAR; ++j) { Console.WriteLine("x[{0}]:{1}", j, xx[j]); } /* Make a change to the A matrix */ task.putaij(0, 0, 3.0); task.optimize(); /* Append a new varaible x_3 to the problem */ task.append(mosek.accmode.var, 1); /* Get index of new variable, this should be 3 */ int numvar; task.getnumvar(out numvar); /* Set bounds on new varaible */ task.putbound(mosek.accmode.var, numvar - 1, mosek.boundkey.lo, 0, +infinity); /* Change objective */ task.putcj(numvar - 1, 1.0); /* Put new values in the A matrix */ int[] acolsub = new int[] { 0, 2 }; double[] acolval = new double[] { 4.0, 1.0 }; task.putavec(mosek.accmode.var, numvar - 1, /* column index */ acolsub, acolval); /* Change optimizer to simplex free and reoptimize */ task.putintparam(mosek.iparam.optimizer, mosek.optimizertype.free_simplex); task.optimize(); /* Append a new constraint */ task.append(mosek.accmode.con, 1); /* Get index of new constraint, this should be 4 */ int numcon; task.getnumcon(out numcon); /* Set bounds on new constraint */ task.putbound( mosek.accmode.con, numcon - 1, mosek.boundkey.up, -infinity, 30000); /* Put new values in the A matrix */ int[] arowsub = new int[] { 0, 1, 2, 3 }; double[] arowval = new double[] { 1.0, 2.0, 1.0, 1.0 }; task.putavec(mosek.accmode.con, numcon - 1, /* row index */ arowsub, arowval); task.optimize(); } catch (mosek.Exception e) { Console.WriteLine(e.Code); Console.WriteLine(e); } if (task != null) { task.Dispose(); } if (env != null) { env.Dispose(); } }
public static void Main() { const int numcon = 2; const int numvar = 2; // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; mosek.boundkey[] bkc = { mosek.boundkey.up, mosek.boundkey.lo }; double[] blc = { -infinity, -4.0 }; double[] buc = { 250.0, infinity }; mosek.boundkey[] bkx = { mosek.boundkey.lo, mosek.boundkey.lo }; double[] blx = { 0.0, 0.0 }; double[] bux = { infinity, infinity }; double[] c = { 1.0, 0.64 }; int[][] asub = { new int[] { 0, 1 }, new int[] { 0, 1 } }; double[][] aval = { new double[] { 50.0, 3.0 }, new double[] { 31.0, -2.0 } }; double[] xx = new double[numvar]; mosek.Env env = null; mosek.Task task = null; try { // Make mosek environment. env = new mosek.Env(); // Create a task object linked with the environment env. task = new mosek.Task(env, numcon, numvar); // Directs the log task stream to the user specified // method task_msg_obj.streamCB MsgClass task_msg_obj = new MsgClass(); task.set_Stream(mosek.streamtype.log, task_msg_obj); /* Give MOSEK an estimate of the size of the input data. * This is done to increase the speed of inputting data. * However, it is optional. */ /* Append 'numcon' empty constraints. * The constraints will initially have no bounds. */ task.appendcons(numcon); /* Append 'numvar' variables. * The variables will initially be fixed at zero (x=0). */ task.appendvars(numvar); /* Optionally add a constant term to the objective. */ task.putcfix(0.0); for (int j = 0; j < numvar; ++j) { /* Set the linear term c_j in the objective.*/ task.putcj(j, c[j]); /* Set the bounds on variable j. * blx[j] <= x_j <= bux[j] */ task.putvarbound(j, bkx[j], blx[j], bux[j]); /* Input column j of A */ task.putacol(j, /* Variable (column) index.*/ asub[j], /* Row index of non-zeros in column j.*/ aval[j]); /* Non-zero Values of column j. */ } /* Set the bounds on constraints. * for i=1, ...,numcon : blc[i] <= constraint i <= buc[i] */ for (int i = 0; i < numcon; ++i) { task.putconbound(i, bkc[i], blc[i], buc[i]); } /* Specify integer variables. */ for (int j = 0; j < numvar; ++j) { task.putvartype(j, mosek.variabletype.type_int); } task.putobjsense(mosek.objsense.maximize); task.optimize(); // Print a summary containing information // about the solution for debugging purposes task.solutionsummary(mosek.streamtype.msg); mosek.solsta solsta; /* Get status information about the solution */ task.getsolsta(mosek.soltype.itg, out solsta); task.getxx(mosek.soltype.itg, // Integer solution. xx); switch (solsta) { case mosek.solsta.optimal: case mosek.solsta.near_optimal: Console.WriteLine("Optimal primal solution\n"); for (int j = 0; j < numvar; ++j) { Console.WriteLine("x[{0}]:", xx[j]); } break; case mosek.solsta.dual_infeas_cer: case mosek.solsta.prim_infeas_cer: case mosek.solsta.near_dual_infeas_cer: case mosek.solsta.near_prim_infeas_cer: Console.WriteLine("Primal or dual infeasibility.\n"); break; case mosek.solsta.unknown: mosek.prosta prosta; task.getprosta(mosek.soltype.itg, out prosta); switch (prosta) { case mosek.prosta.prim_infeas_or_unbounded: Console.WriteLine("Problem status Infeasible or unbounded"); break; case mosek.prosta.prim_infeas: Console.WriteLine("Problem status Infeasible."); break; case mosek.prosta.unknown: Console.WriteLine("Problem status unknown."); break; default: Console.WriteLine("Other problem status."); break; } break; default: Console.WriteLine("Other solution status"); break; } } catch (mosek.Exception e) { Console.WriteLine(e.Code); Console.WriteLine(e); throw; } finally { if (task != null) { task.Dispose(); } if (env != null) { env.Dispose(); } } }
public static void Main() { const double inf = 0.0; /* We don't actually need any value for infinity */ const int NUMCON = 1; /* Number of constraints. */ const int NUMVAR = 3; /* Number of variables. */ const int NUMANZ = 3; /* Number of numzeros in A. */ const int NUMQNZ = 4; /* Number of nonzeros in Q. */ mosek.boundkey[] bkc = { mosek.boundkey.lo }, bkx = { mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo }; int[][] asub = { new int[] { 0 }, new int[] { 0 }, new int[] { 0 } }; double[][] aval = { new double[] { 1.0 }, new double[] { 1.0 }, new double[] { 1.0 } }; double[] blc = { 1.0 }, buc = { inf }, c = { 0.0, -1.0, 0.0 }, blx = { 0.0, 0.0, 0.0 }, bux = { inf, inf, inf }, xx = new double[NUMVAR]; mosek.Task task = null; mosek.Env env = null; try { // Make mosek environment. env = new mosek.Env(); // Direct the env log stream to the user specified // method env_msg_obj.streamCB env.set_Stream(mosek.streamtype.log, new msgclass("")); // Initialize the environment. env.init(); // Create a task object linked with the environment env. task = new mosek.Task(env, 0, 0); // Directs the log task stream to the user specified // method task_msg_obj.streamCB task.set_Stream(mosek.streamtype.log, new msgclass("")); /* Give MOSEK an estimate of the size of the input data. * This is done to increase the speed of inputting data. * However, it is optional. */ task.putmaxnumvar(NUMVAR); task.putmaxnumcon(NUMCON); task.putmaxnumanz(NUMANZ); /* Append 'NUMCON' empty constraints. * The constraints will initially have no bounds. */ task.append(mosek.accmode.con, NUMCON); /* Append 'NUMVAR' variables. * The variables will initially be fixed at zero (x=0). */ task.append(mosek.accmode.var, NUMVAR); /* Optionally add a constant term to the objective. */ task.putcfix(0.0); for (int j = 0; j < NUMVAR; ++j) { /* Set the linear term c_j in the objective.*/ task.putcj(j, c[j]); /* Set the bounds on variable j. * blx[j] <= x_j <= bux[j] */ task.putbound(mosek.accmode.var, j, bkx[j], blx[j], bux[j]); /* Input column j of A */ task.putavec(mosek.accmode.var, /* Input columns of A.*/ j, /* Variable (column) index.*/ asub[j], /* Row index of non-zeros in column j.*/ aval[j]); /* Non-zero Values of column j. */ } /* Set the bounds on constraints. * for i=1, ...,NUMCON : blc[i] <= constraint i <= buc[i] */ for (int i = 0; i < NUMCON; ++i) { task.putbound(mosek.accmode.con, i, bkc[i], blc[i], buc[i]); } /* * The lower triangular part of the Q * matrix in the objective is specified. */ { int[] qsubi = { 0, 1, 2, 2 }, qsubj = { 0, 1, 0, 2 }; double[] qval = { 2.0, 0.2, -1.0, 2.0 }; /* Input the Q for the objective. */ task.putqobj(qsubi, qsubj, qval); } /* * The lower triangular part of the Q^0 * matrix in the first constraint is specified. * This corresponds to adding the term * - x0^2 - x1^2 - 0.1 x2^2 + 0.2 x0 x2 */ { int[] qsubi = { 0, 1, 2, 2 }, qsubj = { 0, 1, 2, 0 }; double[] qval = { -2.0, -2.0, -0.2, 0.2 }; /* put Q^0 in constraint with index 0. */ task.putqconk(0, qsubi, qsubj, qval); } task.putobjsense(mosek.objsense.minimize); task.optimize(); // Print a summary containing information // about the solution for debugging purposes task.solutionsummary(mosek.streamtype.msg); mosek.solsta solsta; mosek.prosta prosta; /* Get status information about the solution */ task.getsolutionstatus(mosek.soltype.itr, out prosta, out solsta); task.getsolutionslice(mosek.soltype.itr, // Basic solution. mosek.solitem.xx, // Which part of solution. 0, // Index of first variable. NUMVAR, // Index of last variable+1 xx); switch (solsta) { case mosek.solsta.optimal: case mosek.solsta.near_optimal: Console.WriteLine("Optimal primal solution\n"); for (int j = 0; j < NUMVAR; ++j) { Console.WriteLine("x[{0}]:", xx[j]); } break; case mosek.solsta.dual_infeas_cer: case mosek.solsta.prim_infeas_cer: case mosek.solsta.near_dual_infeas_cer: case mosek.solsta.near_prim_infeas_cer: Console.WriteLine("Primal or dual infeasibility.\n"); break; case mosek.solsta.unknown: Console.WriteLine("Unknown solution status.\n"); break; default: Console.WriteLine("Other solution status"); break; } } catch (mosek.Exception e) { Console.WriteLine(e); } finally { if (task != null) { task.Dispose(); } if (env != null) { env.Dispose(); } } } /* Main */
public static void Main() { const int numcon = 3; const int numvar = 4; // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; double[] c = { 3.0, 1.0, 5.0, 1.0 }; int[][] asub = { new int[] { 0, 1, 2 }, new int[] { 0, 1,2, 3 }, new int[] { 1, 3 } }; double[][] aval = { new double[] { 3.0, 1.0, 2.0 }, new double[] { 2.0, 1.0,3.0, 1.0 }, new double[] { 2.0, 3.0 } }; mosek.boundkey[] bkc = { mosek.boundkey.fx, mosek.boundkey.lo, mosek.boundkey.up }; double[] blc = { 30.0, 15.0, -infinity }; double[] buc = { 30.0, +infinity, 25.0 }; mosek.boundkey[] bkx = { mosek.boundkey.lo, mosek.boundkey.ra, mosek.boundkey.lo, mosek.boundkey.lo }; double[] blx = { 0.0, 0.0, 0.0, 0.0 }; double[] bux = { +infinity, 10.0, +infinity, +infinity }; mosek.Task task = null; mosek.Env env = null; double[] xx = new double[numvar]; try { // Make mosek environment. env = new mosek.Env(); // Create a task object linked with the environment env. task = new mosek.Task(env, 0, 0); // Directs the log task stream to the user specified // method task_msg_obj.streamCB task.set_Stream(mosek.streamtype.log, new msgclass("")); /* Give MOSEK an estimate of the size of the input data. * This is done to increase the speed of inputting data. * However, it is optional. */ /* Append 'numcon' empty constraints. * The constraints will initially have no bounds. */ task.appendcons(numcon); /* Append 'numvar' variables. * The variables will initially be fixed at zero (x=0). */ task.appendvars(numvar); /* Optionally add a constant term to the objective. */ task.putcfix(0.0); for (int j = 0; j < numvar; ++j) { /* Set the linear term c_j in the objective.*/ task.putcj(j, c[j]); /* Set the bounds on variable j. * blx[j] <= x_j <= bux[j] */ task.putvarbound(j, bkx[j], blx[j], bux[j]); } /* Set the bounds on constraints. * for i=1, ...,numcon : blc[i] <= constraint i <= buc[i] */ for (int i = 0; i < numcon; ++i) { task.putconbound(i, bkc[i], blc[i], buc[i]); /* Input row i of A */ task.putarow(i, /* Row index.*/ asub[i], /* Column indexes of non-zeros in row i.*/ aval[i]); /* Non-zero Values of row i. */ } task.putobjsense(mosek.objsense.maximize); task.optimize(); // Print a summary containing information // about the solution for debugging purposes task.solutionsummary(mosek.streamtype.msg); mosek.solsta solsta; /* Get status information about the solution */ task.getsolsta(mosek.soltype.bas, out solsta); task.getxx(mosek.soltype.bas, // Basic solution. xx); switch (solsta) { case mosek.solsta.optimal: case mosek.solsta.near_optimal: Console.WriteLine("Optimal primal solution\n"); for (int j = 0; j < numvar; ++j) { Console.WriteLine("x[{0}]: {1}", j, xx[j]); } break; case mosek.solsta.dual_infeas_cer: case mosek.solsta.prim_infeas_cer: case mosek.solsta.near_dual_infeas_cer: case mosek.solsta.near_prim_infeas_cer: Console.WriteLine("Primal or dual infeasibility.\n"); break; case mosek.solsta.unknown: Console.WriteLine("Unknown solution status.\n"); break; default: Console.WriteLine("Other solution status"); break; } } catch (mosek.Exception e) { Console.WriteLine(e.Code); Console.WriteLine(e); throw; } finally { if (task != null) { task.Dispose(); } if (env != null) { env.Dispose(); } } }
public static void Main(string[] args) { mosek.Task task = null; mosek.Env env = null; if (args.Length == 0) { Console.WriteLine("Missing argument. The syntax is:"); Console.WriteLine(" simple inputfile [ solutionfile ]"); } else { try { // Make mosek environment. env = new mosek.Env(); // Initialize the environment. env.init(); // Create a task object linked with the environment env. // We create it initially with 0 variables and 0 columns, // since we don't know the size of the problem. task = new mosek.Task(env, 0, 0); // We assume that a problem file was given as the first command // line argument (received in `args') task.readdata(args[0]); // Solve the problem task.optimize(); // Print a summary of the solution task.solutionsummary(mosek.streamtype.log); // If an output file was specified, write a solution if (args.Length > 1) { // We define the output format to be OPF, and tell MOSEK to // leave out parameters and problem data from the output file. task.putintparam(mosek.iparam.write_data_format, mosek.dataformat.op); task.putintparam(mosek.iparam.opf_write_solutions, mosek.onoffkey.on); task.putintparam(mosek.iparam.opf_write_hints, mosek.onoffkey.off); task.putintparam(mosek.iparam.opf_write_parameters, mosek.onoffkey.off); task.putintparam(mosek.iparam.opf_write_problem, mosek.onoffkey.off); task.writedata(args[1]); } } finally { // Dispose of task end environment if (task != null) { task.Dispose(); } if (env != null) { env.Dispose(); } } } }
public static void Main() { mosek.Env env = null; mosek.Task task = null; const double infinity = 0; mosek.boundkey[] bkc = new mosek.boundkey[] { mosek.boundkey.up, mosek.boundkey.up, mosek.boundkey.up, mosek.boundkey.fx, mosek.boundkey.fx, mosek.boundkey.fx, mosek.boundkey.fx }; mosek.boundkey[] bkx = new mosek.boundkey[] { mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo }; int[] ptrb = new int[] { 0, 2, 4, 6, 8, 10, 12 }; int[] ptre = new int[] { 2, 4, 6, 8, 10, 12, 14 }; int[] sub = new int[] { 0, 3, 0, 4, 1, 5, 1, 6, 2, 3, 2, 5, 2, 6 }; double[] blc = new double[] { -infinity, -infinity, -infinity, 800, 100, 500, 500 }; double[] buc = new double[] { 400, 1200, 1000, 800, 100, 500, 500 }; double[] c = new double[] { 1.0, 2.0, 5.0, 2.0, 1.0, 2.0, 1.0 }; double[] blx = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; double[] bux = new double[] { infinity, infinity, infinity, infinity, infinity, infinity, infinity }; double[] val = new double[] { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; int NUMCON = 7; /* Number of constraints. */ int NUMVAR = 7; /* Number of variables. */ int NUMANZ = 14; /* Number of non-zeros in A. */ try { // Create mosek environment. env = new mosek.Env(); // Direct the env log stream to the user specified // method env_msg_obj.streamCB env.set_Stream(mosek.streamtype.log, new msgclass("[env]")); // Initialize the environment. env.init(); // Create a task object linked with the environment env. task = new mosek.Task(env, NUMCON, NUMVAR); // Directs the log task stream to the user specified // method task_msg_obj.streamCB task.set_Stream(mosek.streamtype.log, new msgclass("[task]")); task.inputdata(NUMCON, NUMVAR, c, 0.0, ptrb, ptre, sub, val, bkc, blc, buc, bkx, blx, bux); /* A maximization problem */ task.putobjsense(mosek.objsense.minimize); try { task.optimize(); } catch (mosek.Warning w) { Console.WriteLine("Mosek warning:"); Console.WriteLine(w.Code); Console.WriteLine(w); } /* Analyze upper bound on c1 and the equality constraint on c4 */ int[] subi = new int [] { 0, 3 }; mosek.mark[] marki = new mosek.mark[] { mosek.mark.up, mosek.mark.up }; /* Analyze lower bound on the variables x12 and x31 */ int[] subj = new int [] { 1, 4 }; mosek.mark[] markj = new mosek.mark[] { mosek.mark.lo, mosek.mark.lo }; double[] leftpricei = new double[2]; double[] rightpricei = new double[2]; double[] leftrangei = new double[2]; double[] rightrangei = new double[2]; double[] leftpricej = new double[2]; double[] rightpricej = new double[2]; double[] leftrangej = new double[2]; double[] rightrangej = new double[2]; task.primalsensitivity(subi, marki, subj, markj, leftpricei, rightpricei, leftrangei, rightrangei, leftpricej, rightpricej, leftrangej, rightrangej); Console.Write("Results from sensitivity analysis on bounds:\n"); Console.Write("For constraints:\n"); for (int i = 0; i < 2; ++i) { Console.Write( "leftprice = {0}, rightprice = {1},leftrange = {2}, rightrange ={3}\n", leftpricei[i], rightpricei[i], leftrangei[i], rightrangei[i]); } Console.Write("For variables:\n"); for (int i = 0; i < 2; ++i) { Console.Write( "leftprice = {0}, rightprice = {1},leftrange = {2}, rightrange ={3}\n", leftpricej[i], rightpricej[i], leftrangej[i], rightrangej[i]); } double[] leftprice = new double[2]; double[] rightprice = new double[2]; double[] leftrange = new double[2]; double[] rightrange = new double[2]; int[] subc = new int[] { 2, 5 }; task.dualsensitivity(subc, leftprice, rightprice, leftrange, rightrange ); Console.Write("Results from sensitivity analysis on objective coefficients:"); for (int i = 0; i < 2; ++i) { Console.Write( "leftprice = {0}, rightprice = {1},leftrange = {2}, rightrange = {3}\n", leftprice[i], rightprice[i], leftrange[i], rightrange[i]); } } catch (mosek.Exception e) { Console.WriteLine(e.Code); Console.WriteLine(e); } if (task != null) { task.Dispose(); } if (env != null) { env.Dispose(); } }
public static void Main() { // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; const int numcon = 3; const int numvar = 3; double[] c = { 1.5, 2.5, 3.0 }; mosek.boundkey[] bkc = { mosek.boundkey.up, mosek.boundkey.up, mosek.boundkey.up }; double[] blc = { -infinity, -infinity, -infinity }; double[] buc = { 100000, 50000, 60000 }; mosek.boundkey[] bkx = { mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo }; double[] blx = { 0.0, 0.0, 0.0 }; double[] bux = { +infinity, +infinity, +infinity }; int[][] asub = new int[numvar][]; asub[0] = new int[] { 0, 1, 2 }; asub[1] = new int[] { 0, 1, 2 }; asub[2] = new int[] { 0, 1, 2 }; double[][] aval = new double[numvar][]; aval[0] = new double[] { 2.0, 3.0, 2.0 }; aval[1] = new double[] { 4.0, 2.0, 3.0 }; aval[2] = new double[] { 3.0, 3.0, 2.0 }; double[] xx = new double[numvar]; mosek.Task task = null; mosek.Env env = null; try { // Create mosek environment. env = new mosek.Env(); // Create a task object linked with the environment env. task = new mosek.Task(env, numcon, numvar); /* Append the constraints. */ task.appendcons(numcon); /* Append the variables. */ task.appendvars(numvar); /* Put C. */ task.putcfix(0.0); for (int j = 0; j < numvar; ++j) { task.putcj(j, c[j]); } /* Put constraint bounds. */ for (int i = 0; i < numcon; ++i) { task.putbound(mosek.accmode.con, i, bkc[i], blc[i], buc[i]); } /* Put variable bounds. */ for (int j = 0; j < numvar; ++j) { task.putbound(mosek.accmode.var, j, bkx[j], blx[j], bux[j]); } /* Put A. */ if (numcon > 0) { for (int j = 0; j < numvar; ++j) { task.putacol(j, asub[j], aval[j]); } } task.putobjsense(mosek.objsense.maximize); try { task.optimize(); } catch (mosek.Warning w) { Console.WriteLine("Mosek warning:"); Console.WriteLine(w.Code); Console.WriteLine(w); } task.getxx(mosek.soltype.bas, // Request the basic solution. xx); for (int j = 0; j < numvar; ++j) { Console.WriteLine("x[{0}]:{1}", j, xx[j]); } /* Make a change to the A matrix */ task.putaij(0, 0, 3.0); task.optimize(); /* Get index of new variable. */ int varidx; task.getnumvar(out varidx); /* Append a new varaible x_3 to the problem */ task.appendvars(1); /* Set bounds on new varaible */ task.putbound(mosek.accmode.var, varidx, mosek.boundkey.lo, 0, +infinity); /* Change objective */ task.putcj(varidx, 1.0); /* Put new values in the A matrix */ int[] acolsub = new int[] { 0, 2 }; double[] acolval = new double[] { 4.0, 1.0 }; task.putacol(varidx, /* column index */ acolsub, acolval); /* Change optimizer to simplex free and reoptimize */ task.putintparam(mosek.iparam.optimizer, mosek.optimizertype.free_simplex); task.optimize(); /* Get index of new constraint */ int conidx; task.getnumcon(out conidx); /* Append a new constraint */ task.appendcons(1); /* Set bounds on new constraint */ task.putbound( mosek.accmode.con, conidx, mosek.boundkey.up, -infinity, 30000); /* Put new values in the A matrix */ int[] arowsub = new int[] { 0, 1, 2, 3 }; double[] arowval = new double[] { 1.0, 2.0, 1.0, 1.0 }; task.putarow(conidx, /* row index */ arowsub, arowval); task.optimize(); } catch (mosek.Exception e) { Console.WriteLine(e.Code); Console.WriteLine(e); } if (task != null) { task.Dispose(); } if (env != null) { env.Dispose(); } }
public static void Main () { // Since the value infinity is never used, we define // 'infinity' symbolic purposes only const double infinity = 0; const int numcon = 1; /* Number of constraints. */ const int numvar = 3; /* Number of variables. */ double[] c = {0.0,-1.0,0.0}; mosek.boundkey[] bkc = {mosek.boundkey.lo}; double[] blc = {1.0}; double[] buc = {infinity}; mosek.boundkey[] bkx = {mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo}; double[] blx = {0.0, 0.0, 0.0}; double[] bux = {+infinity, +infinity, +infinity}; int[][] asub = { new int[] {0}, new int[] {0}, new int[] {0}}; double[][] aval = { new double[] {1.0}, new double[] {1.0}, new double[] {1.0}}; mosek.Task task = null; mosek.Env env = null; double[] xx = new double[numvar]; try { // Make mosek environment. env = new mosek.Env (); // Create a task object linked with the environment env. task = new mosek.Task (env, 0,0); // Directs the log task stream to the user specified // method task_msg_obj.streamCB task.set_Stream (mosek.streamtype.log, new msgclass ("")); /* Give MOSEK an estimate of the size of the input data. This is done to increase the speed of inputting data. However, it is optional. */ /* Append 'numcon' empty constraints. The constraints will initially have no bounds. */ task.appendcons(numcon); /* Append 'numvar' variables. The variables will initially be fixed at zero (x=0). */ task.appendvars(numvar); for(int j=0; j<numvar; ++j) { /* Set the linear term c_j in the objective.*/ task.putcj(j,c[j]); /* Set the bounds on variable j. blx[j] <= x_j <= bux[j] */ task.putvarbound(j,bkx[j],blx[j],bux[j]); /* Input column j of A */ task.putacol(j, /* Variable (column) index.*/ asub[j], /* Row index of non-zeros in column j.*/ aval[j]); /* Non-zero Values of column j. */ } /* Set the bounds on constraints. for i=1, ...,numcon : blc[i] <= constraint i <= buc[i] */ for(int i=0; i<numcon; ++i) task.putconbound(i,bkc[i],blc[i],buc[i]); /* * The lower triangular part of the Q * matrix in the objective is specified. */ int[] qsubi = {0, 1, 2, 2 }; int[] qsubj = {0, 1, 0, 2 }; double[] qval = {2.0, 0.2, -1.0, 2.0}; /* Input the Q for the objective. */ task.putobjsense(mosek.objsense.minimize); task.putqobj(qsubi,qsubj,qval); task.optimize(); // Print a summary containing information // about the solution for debugging purposes task.solutionsummary(mosek.streamtype.msg); mosek.solsta solsta; /* Get status information about the solution */ task.getsolsta(mosek.soltype.itr, out solsta); switch(solsta) { case mosek.solsta.optimal: case mosek.solsta.near_optimal: task.getxx(mosek.soltype.itr, // Interior point solution. xx); Console.WriteLine ("Optimal primal solution\n"); for(int j = 0; j < numvar; ++j) Console.WriteLine ("x[{0}]:",xx[j]); break; case mosek.solsta.dual_infeas_cer: case mosek.solsta.prim_infeas_cer: case mosek.solsta.near_dual_infeas_cer: case mosek.solsta.near_prim_infeas_cer: Console.WriteLine("Primal or dual infeasibility.\n"); break; case mosek.solsta.unknown: Console.WriteLine("Unknown solution status.\n"); break; default: Console.WriteLine("Other solution status"); break; } } catch (mosek.Exception e) { Console.WriteLine (e); throw; } finally { if (task != null) task.Dispose (); if (env != null) env.Dispose (); } } /* Main */
public static void Main() { const int NUMCON = 1; const int NUMVAR = 6; const int NUMANZ = 4; // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; mosek.boundkey[] bkc = { mosek.boundkey.fx }; double[] blc = { 1.0 }; double[] buc = { 1.0 }; mosek.boundkey[] bkx = { mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.lo, mosek.boundkey.fr, mosek.boundkey.fr }; double[] blx = { 0.0, 0.0, 0.0, 0.0, -infinity, -infinity }; double[] bux = { +infinity, +infinity, +infinity, +infinity, +infinity, +infinity }; double[] c = { 0.0, 0.0, 0.0, 0.0, 1.0, 1.0 }; double[][] aval = { new double[] { 1.0 }, new double[] { 1.0 }, new double[] { 1.0 }, new double[] { 1.0 } }; int[][] asub = { new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, new int[] { 0 } }; int[] csub = new int[3]; double[] xx = new double[NUMVAR]; mosek.Env env = null; mosek.Task task = null; try { // Make mosek environment. env = new mosek.Env(); // Direct the env log stream to the user specified // method env_msg_obj.streamCB env.set_Stream(mosek.streamtype.log, new msgclass("")); // Initialize the environment. env.init(); // Create a task object linked with the environment env. task = new mosek.Task(env, 0, 0); // Directs the log task stream to the user specified // method task_msg_obj.streamCB task.set_Stream(mosek.streamtype.log, new msgclass("")); /* Give MOSEK an estimate of the size of the input data. * This is done to increase the speed of inputting data. * However, it is optional. */ task.putmaxnumvar(NUMVAR); task.putmaxnumcon(NUMCON); task.putmaxnumanz(NUMANZ); /* Append 'NUMCON' empty constraints. * The constraints will initially have no bounds. */ task.append(mosek.accmode.con, NUMCON); /* Append 'NUMVAR' variables. * The variables will initially be fixed at zero (x=0). */ task.append(mosek.accmode.var, NUMVAR); /* Optionally add a constant term to the objective. */ task.putcfix(0.0); for (int j = 0; j < NUMVAR; ++j) { /* Set the linear term c_j in the objective.*/ task.putcj(j, c[j]); /* Set the bounds on variable j. * blx[j] <= x_j <= bux[j] */ task.putbound(mosek.accmode.var, j, bkx[j], blx[j], bux[j]); } for (int j = 0; j < aval.Length; ++j) { /* Input column j of A */ task.putavec(mosek.accmode.var, /* Input columns of A.*/ j, /* Variable (column) index.*/ asub[j], /* Row index of non-zeros in column j.*/ aval[j]); /* Non-zero Values of column j. */ } /* Set the bounds on constraints. * for i=1, ...,NUMCON : blc[i] <= constraint i <= buc[i] */ for (int i = 0; i < NUMCON; ++i) { task.putbound(mosek.accmode.con, i, bkc[i], blc[i], buc[i]); } csub[0] = 4; csub[1] = 0; csub[2] = 2; task.appendcone(mosek.conetype.quad, 0.0, /* For future use only, can be set to 0.0 */ csub); csub[0] = 5; csub[1] = 1; csub[2] = 3; task.appendcone(mosek.conetype.quad, 0.0, csub); task.putobjsense(mosek.objsense.minimize); task.optimize(); // Print a summary containing information // about the solution for debugging purposes task.solutionsummary(mosek.streamtype.msg); mosek.solsta solsta; mosek.prosta prosta; /* Get status information about the solution */ task.getsolutionstatus(mosek.soltype.itr, out prosta, out solsta); task.getsolutionslice(mosek.soltype.itr, // Basic solution. mosek.solitem.xx, // Which part of solution. 0, // Index of first variable. NUMVAR, // Index of last variable+1 xx); switch (solsta) { case mosek.solsta.optimal: case mosek.solsta.near_optimal: Console.WriteLine("Optimal primal solution\n"); for (int j = 0; j < NUMVAR; ++j) { Console.WriteLine("x[{0}]:", xx[j]); } break; case mosek.solsta.dual_infeas_cer: case mosek.solsta.prim_infeas_cer: case mosek.solsta.near_dual_infeas_cer: case mosek.solsta.near_prim_infeas_cer: Console.WriteLine("Primal or dual infeasibility.\n"); break; case mosek.solsta.unknown: Console.WriteLine("Unknown solution status.\n"); break; default: Console.WriteLine("Other solution status"); break; } } catch (mosek.Exception e) { Console.WriteLine(e); throw(e); } finally { if (task != null) { task.Dispose(); } if (env != null) { env.Dispose(); } } }