/* Copyright: MOSEK ApS File: rmt.c Purpose : Template for use with solve.mosek.com */ #include "mosek.h" static void MSKAPI printstr(void *handle, const char str[]) { printf("%s", str); } int main(int argc, const char * argv[]) { MSKenv_t env = NULL; MSKtask_t task = NULL; MSKrescodee res = MSK_RES_OK; MSKrescodee trm = MSK_RES_OK; char symname[MSK_MAX_STR_LEN]; char desc[MSK_MAX_STR_LEN]; // Create the mosek environment. res = MSK_makeenv(&env, NULL); // Create a task object linked with the environment env. if (res == MSK_RES_OK) res = MSK_maketask(env, 0, 0, &task); // Direct the task log stream to a user specified function if (res == MSK_RES_OK) res = MSK_linkfunctotaskstream(task, MSK_STREAM_LOG, NULL, printstr); // Set the URL of the OptServer if (res == MSK_RES_OK) res = MSK_putoptserverhost(task, "http://solve.mosek.com:30080"); /* SET UP THE OPTIMIZATION PROBLEM HERE */ if (res == MSK_RES_OK) { // Trivial sample problem MSK_appendvars(task, 1); // 1 variable x MSK_putcj(task, 0, 1.0); // c_0 = 1.0 MSK_putvarbound(task, 0, MSK_BK_RA, 2.0, 3.0); // 2.0 <= x <= 3.0 MSK_putobjsense(task, MSK_OBJECTIVE_SENSE_MINIMIZE); // Minimize } /* END OF PROBLEM SETUP */ // Solve the problem if (res == MSK_RES_OK) res = MSK_optimizetrm(task, &trm); // Perform some error diagnostic specific to the OptServer if (res != MSK_RES_OK) { MSK_getcodedesc(res, symname, desc); printf("Error during optimization: %s %s\n", symname, desc); if (res == MSK_RES_ERR_SERVER_PROBLEM_SIZE) printf("Error: the problem was too big for the demo server.\n"); } else { if (trm == MSK_RES_TRM_USER_CALLBACK) printf("Note: demo server time limit was reached.\n"); // Print a summary of the solution. if (res == MSK_RES_OK) res = MSK_solutionsummary(task, MSK_STREAM_LOG); // Now fetch the problem status and solution as always // ... } // Delete task and environment MSK_deletetask(&task); MSK_deleteenv(&env); return res; }