This reference guide assumes you already completed the steps described in the 5-minute getting started experience. To test that the Nextmv CLI is correctly configured, you can optionally run the following command on your terminal. It will get some files that are necessary to work with the Nextmv Platform. You can see the expected output as well.
The Nextmv Software Development Kit (SDK) lets you automate any operational decision in a way that looks and feels like writing other code. It provides the guardrails to turn your data into automated decisions and test and deploy them into production environments.
Introduction
The mip
package, part of the Nextmv SDK, is an interface for solving various types of Mixed-Integer Problems (MIP). This example aims to solve a basic problem to demonstrate the steps required to solve a MIP.
Consider the following MIP:
This guide will teach you how to solve this MIP.
Let's see how.
Set up the environment
Somewhere in your computer, create a Go module called mip
. You should obtain an output similar to the one depicted.
Now add the Nextmv SDK to your dependencies. You should observe the latest version being pulled as part of the output.
You should now have a go.mod
file that looks like this:
To proceed with running the example, create an empty main.go
file in the mip
directory, like the code snippet below.
Your application should roughly contain this structure:
The following steps showcase how to complete the main
function of your program to solve the basic MIP described above.
Create the model
A Model
is the main interface to model a Mixed-Integer Problem. You define a problem by adding variables, an objective and constraints to a model.
First, you add the variables to a model. In this case you add two int
variables, x
and y
, with initial bounds that seem reasonable for the problem you are solving.
Next you define the objective, 6x + 5y
, and define it is a maximization problem.
Lastly, you define the constraints. For each constraint you define the sense, the right hand side and you add the terms on the constraint.
Solve the model
You can solve your MIP defined in the model by using a Solver
. In this guide we suggest you use the HiGHS solver. After creating the solver you can solve the problem by invoking solver.Solve
with the options for the invocation.
You can find the solution of a Solver
invocation in the Solution
returned.
The complete main.go
file should now look like the code snippet below.
Run the program using the Nextmv CLI. You can check the output to see the actual solution to the problem.
The precision of the values printed can be different depending on your machine.
Click here for more information on the mip package