writeproblem

Save optimization problem description

Syntax

writeproblem(prob)
writeproblem(prob,filename)

Description

writeproblem(prob) saves a description of the optimization problem prob in a file named prob.txt. Here, prob is the workspace variable name of the problem. If writeproblem cannot construct the file name from the problem name, it writes to WriteProblemOutput.txt. The writeproblem function overwrites any existing file.

example

writeproblem(prob,filename) saves a description of the optimization problem prob in a file named filename.

Examples

collapse all

Create an optimization problem.

x = optimvar('x');
y = optimvar('y');
prob = optimproblem;
prob.Objective = -x - y/3;
prob.Constraints.cons1 = x + y <= 2;
prob.Constraints.cons2 = x + y/4 <= 1;
prob.Constraints.cons3 = x - y <= 2;
prob.Constraints.cons4 = x/4 + y >= -1;
prob.Constraints.cons5 = x + y >= 1;
prob.Constraints.cons6 = -x + y <= 2;

Save the problem description in a file in the current directory.

writeproblem(prob,'ProblemDescription.txt')

The contents of ProblemDescription.txt:

	minimize :
       -x - 0.33333*y

	subject to cons1:
       x + y <= 2

	subject to cons2:
       x + 0.25*y <= 1

	subject to cons3:
       x - y <= 2

	subject to cons4:
       0.25*x + y >= -1

	subject to cons5:
       x + y >= 1

	subject to cons6:
       -x + y <= 2

Input Arguments

collapse all

Optimization problem, specified as an OptimizationProblem object. Create a problem by using optimproblem.

Example: prob = optimproblem; prob.Objective = obj; prob.Constraints.cons1 = cons1;

Path to the file, specified as a string or character vector. The path is relative to the current folder. The resulting file is a text file, so the file name typically has the extension .txt.

Example: "../Notes/steel_stuff.txt"

Data Types: char | string

Tips

  • writeproblem is equivalent to calling all of the following:

  • To obtain the writeproblem information at the Command Window, use showproblem.

Introduced in R2017b