public static void Main(string[] argv) { if (argv.Length < 1) { Console.WriteLine("No input file specified"); } else { using (Env env = new Env()) { using (Task task = new Task(env, 0, 0)) { // Directs the log task stream to the user specified // method task_msg_obj.stream task.set_Stream(streamtype.log, new msgclass()); task.readdata(argv[0]); rescode trm = task.optimize(); solsta solsta; task.getsolsta(soltype.itr, out solsta); switch (solsta) { case solsta.optimal: case solsta.near_optimal: Console.WriteLine("An optimal basic solution is located."); task.solutionsummary(streamtype.msg); break; case solsta.dual_infeas_cer: case solsta.near_dual_infeas_cer: Console.WriteLine("Dual infeasibility certificate found."); break; case solsta.prim_infeas_cer: case solsta.near_prim_infeas_cer: Console.WriteLine("Primal infeasibility certificate found."); break; case solsta.unknown: { StringBuilder symname = new StringBuilder(); StringBuilder desc = new StringBuilder(); /* The solutions status is unknown. The termination code * indicating why the optimizer terminated prematurely. */ Console.WriteLine("The solution status is unknown."); /* No system failure e.g. an iteration limit is reached. */ Env.getcodedesc(trm, symname, desc); Console.WriteLine(" Termination code: %{0}", symname); break; } default: Console.WriteLine("An unexpected solution status is obtained."); break; } } } } }
public static void Main(string[] argv) { StringBuilder symname = new StringBuilder(); StringBuilder desc = new StringBuilder(); string filename; if (argv.Length >= 1) { filename = argv[0]; } else { filename = "../data/cqo1.mps"; } // Define environment and task using (Env env = new Env()) { using (Task task = new Task(env, 0, 0)) { try { // (Optionally) set a log handler // task.set_Stream (streamtype.log, new msgclass ()); // (Optionally) uncomment this to get solution status unknown // task.putintparam(iparam.intpnt_max_iterations, 1); // In this example we read data from a file task.readdata(filename); // Perform optimization rescode trm = task.optimize(); // Handle solution status. We expect Optimal solsta solsta = task.getsolsta(soltype.itr); switch (solsta) { case solsta.optimal: case solsta.near_optimal: // Optimal solution. Print variable values Console.WriteLine("An optimal interior-point solution is located."); int numvar = task.getnumvar(); double[] xx = new double[numvar]; task.getxx(soltype.itr, xx); for (int i = 0; i < numvar; i++) { Console.WriteLine("x[" + i + "] = " + xx[i]); } break; case solsta.dual_infeas_cer: case solsta.near_dual_infeas_cer: Console.WriteLine("Dual infeasibility certificate found."); break; case solsta.prim_infeas_cer: case solsta.near_prim_infeas_cer: Console.WriteLine("Primal infeasibility certificate found."); break; case solsta.unknown: /* The solutions status is unknown. The termination code * indicates why the optimizer terminated prematurely. */ Console.WriteLine("The solution status is unknown."); Env.getcodedesc(trm, symname, desc); Console.WriteLine(" Termination code: {0} {1}", symname, desc); break; default: Console.WriteLine("An unexpected solution status " + solsta); break; } } catch (mosek.Error e) { Console.WriteLine("Unexpected optimization error ({0}) {1}", e.Code, e.Message); } } } }