Search…
Build and run your app
Build and run your custom app

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:
Bash
1
go get ./...
Copied!
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.
Bash
1
cd cmd/<model-name>
Copied!
Then run the following command to compile all of the packages named in the import path of ./cmd/<model-name>:
Bash
1
go build
Copied!
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:
Bash
1
./<model-name> -h
Copied!
This is an example of how to run the binary using some of the flags provided:
Bash
1
./<model-name> \
2
-hop.runner.input.path data/input.json \
3
-hop.solver.limits.duration 10s \
4
-hop.runner.output.path data/output.json
Copied!
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:
Bash
1
sh cmd.sh
Copied!
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.
txt
1
root
2
/ \
3
node node
4
/ \
5
node node
6
|
7
node
Copied!
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.
Go
1
states := expand.States(solution, root)
2
solver := solve.Satisfier(states, opt)
Copied!
For optimization problems, we expand valuers. These are states that implement Value methods.
Go
1
states := expand.Valuers(solution, root)
2
solver := solve.Minimizer(states, opt)
Copied!
Both functions accept variadic arguments. These result in a search tree similar to the following.
txt
1
dummy
2
/ \
3
solution root
4
/ \
5
node node
6
|
7
node
Copied!
This lets Hop benefit from information about a known solution early in its search.
Export as PDF
Copy link