Linear Programming
The basic procedure of running XProg to solve deterministic optimization problems is demonstrated by the simple linear program below.
\begin{align}
\max~&3x+4y \\
\text{s.t.}~&2.5x+y\leq 20 \\
&3x+3y\leq 30 \\
& x+2y\leq 16 \\\
&x,y\geq 0
\end{align} This problem is represented by the fllowing code, which gives the optimal solution \(x=4\) and \(y=6\). The optimal objective value is 36.
The basic procedure of running XProg to solve deterministic optimization problems is demonstrated by the simple linear program below.
\begin{align}
\max~&3x+4y \\
\text{s.t.}~&2.5x+y\leq 20 \\
&3x+3y\leq 30 \\
& x+2y\leq 16 \\\
&x,y\geq 0
\end{align} This problem is represented by the fllowing code, which gives the optimal solution \(x=4\) and \(y=6\). The optimal objective value is 36.
model=xprog('Simple LP'); % create a model, named "Simple LP" x=model.decision; % create a decision variable x for the model y=model.decision; % create a decision variable y for the model model.max(3*x+4*y); % define objective function model.add(2.5*x+y<=20); % add the 1st constraint to the model model.add(3*x+3*y<=30); % add the 2nd constraint to the model model.add(x+2*y<=16); % add the 3rd constraint to the model model.add(x>=0); % bound of x model.add(y>=0); % bound of y model.solve; % solve the problem Obj=model.get; % get the objective value X =x.get; % get solution x Y =y.get; % get solution y
This example shows that the first step of modeling by XProg is to create a XProg object. For this model object, users may define the decision variables, the objective function, as well as constraints. This optimization model can be solved by calling the function “solve”, then the user can access the optimal objective and solutions through function “get”.