Here’s follow the solution (aimms) to the challenge Port in a Storm (puzzleor).

We need to create the sets docks and groups.

The distances, given in the spreadsheet:

Tip: in the definition, we can fill the matrix with the values.

Another tip: it is easy to exchange indexes. Make sure it does not happen.
The variable has range integer in dimensions (g,d)

Contraints: max docks and the minimum we have to distribute from the groups

Next, the mathematical programming.

We’re minimizing.

FO is the sum of variables times distances.

In the main execution, we write solve port (name of the mathematical programming);
Type F6 to run:

Result is FO = 31, the same as in the excel.

Note that the assignment is different from excel – in this case there’s more than one solution.

The zip file here contains the formulation. And here, the Excel solver version.
Below transcribed the full formulation.
MAIN MODEL Main_Port_in_a_storm
DECLARATION SECTION
SET:
identifier : Docks
subset of : Integers
index : d
definition : {1..3} ;
SET:
identifier : Groups
subset of : Integers
index : g
definition : {1..3} ;
PARAMETER:
identifier : distances
index domain : (g,d)
definition : data { ( 1, 1 ) : 1, ( 1, 2 ) : 3, ( 1, 3 ) : 2, ( 2, 1 ) : 2, ( 2, 2 ) : 2, ( 2, 3 ) : 1, ( 3, 1 ) : 3, ( 3, 2 ) : 2, ( 3, 3 ) : 1 } ;
PARAMETER:
identifier : max_docks
index domain : d
definition : data { 1 : 4, 2 : 7, 3 : 9 } ;
PARAMETER:
identifier : min_groups
index domain : (g)
definition : data { 1 : 8, 2 : 5, 3 : 7 } ;
VARIABLE:
identifier : aloc
index domain : (g,d)
range : integer ;
VARIABLE:
identifier : fo
range : free
definition : sum((g,d),aloc(g, d)*distances(g, d)) ;
CONSTRAINT:
identifier : c_docks
index domain : d
definition : sum(g, aloc(g,d))<=max_docks(d) ;
CONSTRAINT:
identifier : c_groups
index domain : (g)
definition : sum(d, aloc(g,d))>=min_groups(g) ;
MATHEMATICAL PROGRAM:
identifier : Port
objective : fo
direction : minimize
constraints : AllConstraints
variables : AllVariables
type : Automatic ;
ENDSECTION ;
PROCEDURE
identifier : MainInitialization
ENDPROCEDURE ;
PROCEDURE
identifier : MainExecution
body :
solve port;
ENDPROCEDURE ;
PROCEDURE
identifier : MainTermination
body :
return DataManagementExit();
ENDPROCEDURE ;
ENDMODEL Main_Port_in_a_storm ;
Ideias técnicas com uma pitada de filosofia:
Você precisa fazer login para comentar.