Calling Custom Solver

Currently the only way to call the custom solver is using C. Remember that the qoco_custom can only solve problems within the problem family that was specified when the solver was generated. Here we will assume that the solver was generated using the code that we generated in section generate.

Below is sample code to call qoco_custom in a file called run.c.

#include "qoco_custom.h"
#include <stdio.h>

int main()
{
  Workspace work;

  // Set default settings.
  set_default_settings(&work);
  work.settings.verbose = 1;

  // Load the data P, c, A, b, G, h, nsoc, q that was specified when generating code.
  load_data(&work);

  // Solve with custom solver.
  qoco_custom_solve(&work);

  // Print optimal objective.
  printf("\nobj: %f", work.sol.obj);

  // Update A to [2 2 0 0;0 2 2 0].
  work.A[0] = 2;
  work.A[1] = 2;
  work.A[2] = 2;
  work.A[3] = 2;

  // Solve the updated problem.
  qoco_custom_solve(&work);

  // Print optimal objective.
  printf("\nobj: %f", work.sol.obj);
}

To compile and run.c, first follow the instruction in building to build the custom solver, the execute the following in terminal assuming that run.c is one directory up from qoco_custom

export LD_LIBRARY_PATH=./qoco_custom/build:$LD_LIBRARY_PATH
gcc run.c -o run -Iqoco_custom -Lqoco_custom/build -lqoco_custom
./run