You are viewing Nextmv legacy docs. ⚡️ Go to latest docs ⚡️

Get Started

Build Run 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:

go get ./...
Copy

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.

cd cmd/<model-name>
Copy

Then run the following command to compile all of the packages named in the import path of ./cmd/<model-name>:

go build
Copy

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:

./<model-name> -h
Copy

This is an example of how to run the binary using some of the flags provided:

./<model-name> \
         -hop.runner.input.path data/input.json \
         -hop.solver.limits.duration 10s \
         -hop.runner.output.path data/output.json
Copy

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:

sh cmd.sh
Copy

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.

      root
      /  \
   node  node
   /  \
node  node
  |
node
Copy

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.

states := expand.States(solution, root)
solver := solve.Satisfier(states, opt)
Copy

For optimization problems, we expand valuers. These are states that implement Value methods.

states := expand.Valuers(solution, root)
solver := solve.Minimizer(states, opt)
Copy

Both functions accept variadic arguments. These result in a search tree similar to the following.

       dummy
       /   \
solution   root
           /  \
        node  node
          |
        node
Copy

This lets Hop benefit from information about a known solution early in its search.

Page last updated

Go to on-page nav menu