Watch out for step 3 you will need to change clang++ for g++
Step 3: Write a Model in C++
We'll start by creating a model in C++. To do this, open a text editor IDE session. Copy and paste the snippet to create a model. Once you have the program in your session, save the model as my_example in C++.
#include "octeract.h" //Add Octeract's header file
using namespace octeract;
auto m = Model(); //Define an empty model
//Declare variables and variable bounds
m.add_variable("x1", 0, 1);
m.add_variable("x2", 0, 1);
m.add_variable("x3", 0, 1);
m.add_variable("x4", 0, 1);
m.add_variable("x5", 0, 1);
//Set an objective function
m.set_objective("42*x1 - 0.5*(100*x1*x1 + 100*x2*x2 + 100*x3*x3 + 100*x4*x4 + 100*x5*x5) + 44*x2 + 45*x3 + 47*x4 + 47.5*x5");
//Add a constraint
m.add_constraint("20*x1 + 12*x2 + 11*x3 + 7*x4 + 4*x5 <= 40");
//Solve model to global optimality using 4 cores
} //End program
Step 4: Compile the Program
To compile your freshly written program please execute the following command:
In your Shell Session, you can run this file. To do this, use the name of the file in the command. There is an example in the snippet. From there, the solution will be displayed on the screen. An example of what your final screen should look like can be seen below.
And that's it - you're done!
You've just solved an optimisation problem using C++.