Forum Discussion
FICO
5 years agoCommunity Manager
Hi, I am in the process of developing a simple optimization model for a supply chain. Two of the constraints relate to suppliers and the kitting facility.
The two constraints are: 1) Only one kitting facility can be chosen 2) Only one (or a variable number) of suppliers of one ingredient needs to be chosen. Why don't the constraints expressed on lin...
FICO
5 years agoCommunity Manager
Without knowing the structure of how data are organized in the spreadsheet it is somewhat difficult to answer which structures provide the best match on Mosel side. However, there are a few points that need to be modified from a syntax point of view in your code extract:
1- Declarations usually use a ':' (unless you wish to define a new type or a constant in which case one indeed needs to use a '=' sign), furthermore, if you name the index set of an array it also needs to be declared. The most common form of array declaration probably is:
declarations
Supplier_list: range ! or: 'set of integer', 'set of string' ...
Supplier_sites: array(Supplier_list) of integer !Defines the supplier sites
end-declarationsEquivalently you can use:
declarations
Supplier_sites: array(Supplier_list: range) of integer !Defines the supplier sites
end-declarationsOr if you are not interested in the index set (unlikely if you wish to enumerate array elements) you could even write:
declarations
Supplier_sites: array(range) of integer !Defines the supplier sites
end-declarations2- Arrays take sets as their indices in the declarations (but you can use list structures in the specification of loops enumerating array entries):
declarations
DISTANCES_M1: dynamic array(Supplier_list, Potential_kf_list) of real
end-declarations3- For the enumeration of sparse (eg dynamic) arrays it is usually more efficient to employ the keyword 'exists' to enumerate only those entries that have been populated:
forall(i in Supplier_list, j in Potential_kf_list | exists(DISTANCES_M1(i,j)) )
writeln(i, " ", j, ":", DISTANCES_M1(i,j))
! or simply:
writeln(DISTANCES_M1)
