7.5. JuMP

JuMP is an open-source modeling tool based on the Julia programming language, specifically designed for mathematical optimization. It offers an efficient and scalable platform for defining and solving various optimization problems, including linear programming, mixed-integer programming, quadratic programming, and nonlinear programming.

Currently, MindOpt can solve linear programming models created with JuMP on Windows, Linux, and macOS platforms. For more detailed information about JuMP, please refer to the JuMP official documentation.

In this section, we will introduce how to use JuMP to establish the optimization problem in :ref:Example LO and call MindOpt to solve it.

7.5.1. Install JuMP

Users must first install MindOpt. For installation and configuration of MindOpt, please refer to :ref:Local Installation. After MindOpt is installed, users need to download and set up the JuMP environment on their own, following the steps below:

Step 1: Install Julia
  1. Visit the official Julia website: https://julialang.org/downloads/.

  2. Download the version of Julia that is compatible with your operating system. Choose the version you want (it is recommended to use the latest stable version).

  3. Launch the downloaded installer and follow the instructions to complete the installation.

  4. Once installed, execute Julia from the command line. It will open a Julia command-line interface.

Step 2: Install the JuMP Package In the Julia command line, you can install the JuMP package through the built-in package manager. Please follow the steps below:

using Pkg
Pkg.add("JuMP")

This will automatically download and install the JuMP package and its dependencies. After the installation is complete, you can import it into your Julia project by using the command using JuMP.

Step 3: Install the AmplNLWriter Package

Similarly, you can install the AmplNLWriter package through Julia’s package manager. In the Julia command line, execute the following command:

Pkg.add("AmplNLWriter")

After the installation is complete, you can use it by running the command using AmplNLWriter.

For detailed installation instructions for JuMP, please refer to JuMP Installation.

7.5.2. JuMP Interface

Now that you have installed JuMP and AmplNLWriter, you can start creating and solving optimization models in Julia. First, you need to import the JuMP and AmplNLWriter modules into Julia.

1using AmplNLWriter, JuMP

Next, we need to call the JuMP API to create a model object, specifying mindoptampl as the solver. Note that the path here should be replaced with the actual path of the user.

9model = Model(() -> AmplNLWriter.Optimizer(mindoptampl))

Subsequently, we call the JuMP API to establish the optimization problem in Example of Linear Programming. For detailed information about the JuMP API, please refer to JuMP Official Documentation API.

10@variable(model, 0 <= x0 <= 10)
11@variable(model, x1 >= 0)
12@variable(model, x2 >= 0)
13@variable(model, x3 >= 0)
14@objective(model, Min, x0 + 2x1 + x2 + x3)
15@constraint(model, c1, x0 + x1 + 2x2 + 3x3 >= 1)
16@constraint(model, c2, x0 - x2 + 6x3 == 1)

Finally, solve the problem by calling JuMP’s optimize!() function and obtain the relevant results:

17optimize!(model)
18println("Optimal objective value is: ", objective_value(model))
19println("x0 = ", value(x0))
20println("x1 = ", value(x1))
21println("x2 = ", value(x2))
22println("x3 = ", value(x3))

7.5.2.1. Execution on Windows Platform

We provide example files under the installation path <MDOHOME>\<VERSION>\examples\jump. Execute the following instructions to run the sample code to complete the optimization solution:

cd <MDOHOME>\<VERSION>\examples\jump
julia jump_lp_ex1.jl

7.5.2.2. Execution on Linux and macOS

We provide example files under the installation path <MDOHOME>/<VERSION>/examples/jump. Execute the following instructions to run the sample code to complete the optimization solution:

cd <MDOHOME>/<VERSION>/jump
julia jump_lp_ex1.jl

7.5.3. Modeling Example: jump_lp_ex1

The complete code is provided in the file link jump_lp_ex1.jl:

 1using AmplNLWriter, JuMP
 2
 3mindopt_home = ENV["MINDOPT_HOME"]
 4mindoptampl = joinpath(mindopt_home, "osx64-x86", "bin", "mindoptampl")
 5if Sys.iswindows()
 6    mindoptampl *= ".exe"
 7end
 8
 9model = Model(() -> AmplNLWriter.Optimizer(mindoptampl))
10@variable(model, 0 <= x0 <= 10)
11@variable(model, x1 >= 0)
12@variable(model, x2 >= 0)
13@variable(model, x3 >= 0)
14@objective(model, Min, x0 + 2x1 + x2 + x3)
15@constraint(model, c1, x0 + x1 + 2x2 + 3x3 >= 1)
16@constraint(model, c2, x0 - x2 + 6x3 == 1)
17optimize!(model)
18println("Optimal objective value is: ", objective_value(model))
19println("x0 = ", value(x0))
20println("x1 = ", value(x1))
21println("x2 = ", value(x2))
22println("x3 = ", value(x3))