Build your app
To build your app with Nextmv, start by by running the following command from the root of the directory to download and install the external packages listed in the go.mod
file:
The go get
command will create a go.sum
file (if not already present) that contains hashes of each module to ensure the same files are being retrieved upon each build. At this point, you should have all of the necessary packages needed to build our executable binary.
Change directory into the ./cmd/<model-name>
package (replace <model-name>
with your model package name). This is the directory that holds a main.go
file.
Then run the following command to compile all of the packages named in the import path of ./cmd/<model-name>
:
Notice that a ./<model-name>
binary should have been created.
Run your app
You have several options for running a model with Nextmv. The easiest one is the Command Line Interface (CLI) runner. You can use flags to tell the solver where to read the data and where to write it, among other options.
Before running the binary using the CLI runner, first view available flags using:
This is an example of how to run the binary using some of the flags provided:
This command will tell the runner to read data from a ./data/input.json
file, set the solver duration to 10 seconds, and write it to a ./data/output.json
file. The CLI runner will print JSON to standard out. We recommend saving this code snippet in cmd.sh
file. It can then be run via:
Alternatively, you can run your app with the go run main.go
command, but we recommend building the binary and working with it. Binaries make the deployment process easier. You can read more about binaries in this short blog.
Use warm starts
You can also pass in a feasible solution to the solver prior to starting your search. This is known as a warm start. Warm starts can reduce cognitive overhead, help you to build on the design of the Nextmv solver (Hop), and get to the best solution more quickly.
The simplest way to warm start a solver is to use a "static expander." Static expanders make it easy to put more than one state at the root of Hop's search tree.
A typical Hop search tree has a single root node and many child nodes.
A static expander functions as a dummy node with a known list of child nodes. Hop expands them in the order they are given. For example, say we have a root node and a known feasible solution. We can use a static expander to expose that solution to the solver at the second layer of the root diagram.
For satisfaction problems, we expand states. These implement Feasible
and Next
methods.
For optimization problems, we expand valuers. These are states that implement Value
methods.
Both functions accept variadic arguments. These result in a search tree similar to the following.
This lets Hop benefit from information about a known solution early in its search.