A simple exercise in AIMMS

I want to model the following Linear program (in the spreadsheet, using solver).

First of all, you’ll need to create a new Project, and one Set for each dimension.

Two dimensions = two sets. Each of this varying from 1 to 2.

We can write the data directly using {1,2} in definition area.

Now, you’ll have to create the arrays of data.

MatrizDados(i,j)

Rhs(i)  !Right hand side

c(j) !Coefficients in the FO

Next, create the variable. In this case, the name given was “var” and the dimension is j.

(You can name the dimensions as you wish, but do not make confusion with these).

Now, the constraint equations.

Note that the index domain is i. There is one equation like this for each line.

Another variable is the objective function:  sum(j,c(j)*var(j));

The mathematical programming is where we indicate the direction, the objective function and the type of problem (LP, MIP).

Last step. In the Main Execution, write down “solve mp;” – it is the command to solve the mathematical program we’ve called mp.

Click F6 to run.

The variable var(j) will contain the results: {12.5, 0} – the same as in the excel solver.

In this link, the aimms model. Perhaps it will not run in an older version of the software.

Regards.

Model Main_Teste01 {

    Set Set1 {

        SubsetOf: Integers;

        Index: i;

        Definition: {

            {1,2}

        }

    }

    Set Set2 {

        SubsetOf: Integers;

        Index: j;

        Definition: {

            {1,2}

        }

    }

   Parameter MatrizDados {

        IndexDomain: (i,j);

        Definition: data { ( 1, 1 ) : 10,  ( 1, 2 ) : 30,  ( 2, 1 ) : 20,  ( 2, 2 ) : 40 };

    }

    Parameter c {

        IndexDomain: j;

        Definition: data { 1 : 12,  2 : 23 };

    }

    Parameter rhs {

        IndexDomain: i;

        Definition: data { 1 : 150,  2 : 250 };

    }

    Variable var {

        IndexDomain: j;

        Range: nonnegative;

    }

    Constraint restr {

        IndexDomain: i;

        Definition: sum(j, var(j)*MatrizDados(i,j))<= rhs(i);

    }

    Variable fo {

        Range: free;

        Definition: sum(j,c(j)*var(j));

    }

    MathematicalProgram mp {

        Objective: fo;

        Direction: minimize;

        Constraints: AllConstraints;

        Variables: AllVariables;

        Type: LP;

    }

    Procedure MainInitialization;

    Procedure MainExecution {

        Body: {

            solve mp;

        }

    }

    Procedure MainTermination {

        Body: {

            return DataManagementExit();

        }

    }

}