#
Modelling with Xpress

`Chip.mos` explained

The following well-written model of the Chippendale problem illustrates the basics
of modelling with Xpress Mosel. Comments are used to explain what
each line does and there are links to further information about
certain statements

`
!`

!Define the name of the model

!

`
model chip`

`
!`

!Tell Xpress_MP to load the mmxprs library of routines

!

`
uses` `"mmxprs"`

`
!`

!Define the data identifiers within a declaration block

!

`
declarations`

`
!`

!Products and Operations are sets of strings. These sets are currently empty.

!

` Products:`
`set of string`

` Operations:`
`set of string`

`
!`

!Profit, LabourTime and LabourLimit are arrays of real numbers, indexed by

!the strings in Products and Operations. Since these sets are empty, the

!arrays Profit, LabourTime and LabourLimit contain no entries.

!

`
Profit:` `array(``Products``) of real`

` LabourTime:` `array(``Operations, Products``) of real`

` LabourLimit:` `array(``Operations``) of real`

`
!`

!Define the array of decision variables.

!

`
Make:` `array(``Products``) of mpvar`

`
end-declarations`

`
!`

!Initialize the sets Products and Operationsthen read values into Profit,

!LabourLimit and LabourTime.

!See Chip.dat

!

`
initializations from` `"Chip.dat"`

`
Products Operations Profit LabourLimit LabourTime`

`
end-initializations`

`
!`

!Define the objective.

!Note the natural way that sets of strings can be used to index array

!entries in the summation, indicating clearly what is being modelled.

!

`TotalProfit`
`:=`
`sum(``p`
`in`
`Products``)`
`Profit``(``p``)``*``Make``(``p``)`

`
!`

!Define the constraints

!Note the natural way that sets of strings can be used to define one

!constraint for each of the operations.

!Note also that each constraint is given a name.

!This is done for two reasons.

! 1. It allows data about the constraint to be extracted.

! 2. It allows the constraint to be modified if solving a

! sequence of optimization problems.

!The names form an array, LabourConstraint (of type linctr) but need not

!be declared since their type and the dimension are defined by the

!context in which LabourConstraint is used.

!

`forall(``o`
`in`
`Operations``)`
`LabourConstraint``(``o``)`
`:=`

`sum(``p`
`in`
`Products``)`
`LabourTime``(``o, p``)``*``Make``(``p``)`
`<=`
`LabourLimit``(``o``)`

`
!`

!Maximize the objective

!

`maximize``(``TotalProfit``)`

`
!`

!Write out the solution

!

`forall(``p`
`in`
`Products``)`

`writeln(`
`"Make "``,`
`getsol(``Make``(``p``)),`
`" "``,`
`p``)`

`
!`

!Write out the objective value

!

`writeln`

`writeln(``"Daily profit is £"``, ``getobjval)`

`
!`

!Indicate that the model has ended

!

`
end-model`

`
!`

!Initialise the sets of strings Products and Operations.

!

`Products: `
`[``"Tables" "Sets of chairs"``] `

`Operations: `
`[``"Assembling" "Finishing"``] `

`
!`

!Initialise the values of the Profit and LabourLimit arrays.

!

`Profit:`
`[``10`
`25``]`

`LabourLimit:`
`[``80`
`120``]`

`
!`

!Initialise the values of the LabourTime array.

!Since the sets of strings Products and Operations are now defined,

!all that is required is the list of values, row-by-row.

!

`LabourTime:`
`[``1 2 1 4``]`

Back to Modelling with Xpress home page