I want an interesting synonym To describe this thing That you say we're all grandfathered in I'll use the search engine (we've got much to discuss) Too much to discuss Over a bucket of balls I can recall the glow of your low beams It's the big night in Tinsel City Life became a spectator sport I launch my fragrance called "Integrity" I sell the fact that I can't be bought Have I told you all about the time That I got sucked into a hole through a hand held device? I will flashback now and again but I'm usually alright Thankfully the process has been simplified Since the last time you tried -- Alex Turner
Nextmv offers a comprehensive set of tools for solving Mixed Integer Programs (MIP). To get started with MIP use Platform for a fully customizable solution.
Platform
Please make sure you already completed the steps described in the 5-minute getting started experience.
To test that the Nextmv CLI is correctly configured, please 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.
To get started with MIP, consider the knapsack problem, which is a classical example of a MIP:
Given a set of items, each with a weight and a value, determine which items to include in the collection so that the total weight is less than or equal to a given limit and the total value is as large as possible.
This problem can be formulated as follows:
These are the supported solvers and solver interfaces for MIP:
Provider | Description | Use with |
---|---|---|
FICO Xpress | Commercial solver. | Go (Nextmv SDK), Python |
HiGHS | Open-source solver. | Go (Nextmv SDK) |
OR-Tools | Open-source solver interface for various solvers. Included open-source solvers: CLP , GLOP , PDLP , SCIP . | Java, Python |
Pyomo | Open-source interface for various solvers. Included open-source solvers in Cloud: CBC , GLPK . | Python |
Depending on the solver of your choice, Get started by initializing one of the available community apps:
Change directories into the templateβs folder. For Java, build the main.jar
.
You should see an input.json
file with a sample knapsack problem.
Depending on the template's language, you can find the main code to solve the problem in one of the following files/directories:
- Go:
main.go
file. - Java:
src/main/java/com/nextmv/example
directory,Main.java
file. - Python:
main.py
file.
Run the code, specifying the file to be used as input, and the file to be used as output, along with other options.
After running, an output.json
file should have been created with the solution.
π π π π π π π π π π π π
You are all set to keep exploring! Here are the next steps to continue your journey:
- Deploy your app to Nextmv Cloud.
- Run remotely on Nextmv Cloud.
- Test and experiment with your app.
- Take a deeper look at the supported solvers.
- Explore more examples of solving MIP problems using the Nextmv Go SDK.
- Meal allocation: allocate meals to bunnies to maximize binkies.
- Incentive allocation: allocate discounts to users while not exceeding a budget.
If you are working with Go (Nextmv SDK) please continue reading.
Go (Nextmv SDK) considerations
In general, the steps to solve a MIP are:
- Create a
Model
. - Add
Variables
to the model, by calling methods on theModel
. - Set the
Objective
of the model, and the sense (max or min), by calling methods on theModel
. - Add
Constraints
to the model, by calling methods on theModel
. For eachConstraint
, you define the sense, the right hand side and add terms to it. - Solve the MIP defined in the
Model
by using aSolver
.
Please note that HiGHS is used as the default solver provider. To use a different one, please visit the supported solvers page to learn more about working with different providers.
Options
All MIP applications are configurable through options.
- Runner options change how the runner outputs solutions and reads/writes data.
- Solve options change the behavior of the solver.
Options can be configured when running locally with the Nextmv platform or when running remotely on Nextmv Cloud. Running remotely is possible when a custom app built has been deployed.
Visit the options reference for detailed information on all the available options.
Options - running locally
- CLI flags. They are added after the double-dash character (
--
). Consider the same example that was shown in the platform section for running the code from the template:
- Environment variables. To set an environment variable, convert its corresponding CLI flag to uppercase, replacing each period (.) with an underscore (_) and removing the leading dash (-). For example:
-solve.duration
is equivalent toSOLVE_DURATION
. Here you can find the same example that was shown above. This time, however, we show how to use environment variables instead of CLI flags. Notice that there is no need for the double-dash character (--
) anymore.
If both an environment variable and its corresponding CLI flag are defined, the CLI flag will overwrite the environment variable.
Options - running remotely
Use the "options"
key in the JSON
payload when executing a run on Nextmv cloud. The leading dash (-
) is removed from the option name, when compared to running locally. For example, -solve.duration
on a local run is equivalent to solve.duration
run remotely.
Note that all values should be set as a string
, regardless of the type.
Here is an example of how to use options when running remotely:
Options - output
Most options are parsed to the output, under the options
key:
When working with platform, you may also modify the options in code, which would override the ones passed from the runner.
Options - solver control parameters
Visit the options reference for more detail on using solver control parameters.
Please find relevant links and examples for each provider in the supported solvers page.
Each provider has its own set of parameters for controlling their solver. Depending on the option's data type, you can use one of the following flags to set these parameters. The list showcases CLI-style flags.
-solve.control.bool
: parameters withbool
values.-solve.control.float
: parameters withfloat
values.-solve.control.int
: parameters withint
values.-solve.control.string
parameters withstring
values.
Each of these options receives a name=value
pair. To set multiple options of the same type, use a comma-separated list: name1=value1,name2=value2
. Note that not all providers support all data types.
For example: -solve.control.float "mip_heuristic_effort=0.7"