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 line 57-64 and line 69 achieve my goal of the two constraints above?
When I output the result, I can get zeros for all kfs which conflict with line 69.
Output:
Supplier to Kitting Facility Solutions:
Supplier 1 to Kitting Facility 1 = 0
Supplier 1 to Kitting Facility 2 = 0
Supplier 2 to Kitting Facility 1 = 0
Supplier 2 to Kitting Facility 2 = 0
Supplier 3 to Kitting Facility 1 = 0
Supplier 3 to Kitting Facility 2 = 0
Supplier 4 to Kitting Facility 1 = 0
Supplier 4 to Kitting Facility 2 = 0
Supplier 5 to Kitting Facility 1 = 0
Supplier 5 to Kitting Facility 2 = 0
Supplier 6 to Kitting Facility 1 = 0
Supplier 6 to Kitting Facility 2 = 0
Supplier 7 to Kitting Facility 1 = 0
Supplier 7 to Kitting Facility 2 = 0
Supplier 8 to Kitting Facility 1 = 0
Supplier 8 to Kitting Facility 2 = 0
Supplier 9 to Kitting Facility 1 = 0
Supplier 9 to Kitting Facility 2 = 0
Supplier 10 to Kitting Facility 1 = 0
Supplier 10 to Kitting Facility 2 = 0
Note that the dat file with the code is attached. It contains no proprietary information.
Please let me know if anything needs any further clarification.
Thank you in advance,
Kibrom
27 Replies
- FICOCommunity 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) - FICOCommunity Manager
Hi @Susanne Heipcke
Thank you for your answer. I am down to wire now before the Capstone is due.
Is there a way to direct message you with the Excel Workbook for you to the see the structure of the data?
There is nothing highly confidential in the data.
Sincerely,
Kibrom
- FICOCommunity Manager
It is late here in the United States and I will have to get some rest.
Please access the Mosel and Excel file: https://send.tresorit.com/a#8LPU4yWx1DXeRJeCSkw1Sw
The password is Xpress2021
Note that there is a limit on the number of times it can be opened.
Thanks again for all your help.
Learning how to use Xpress has been far better than AMPL, which is what my program initially used.
- FICOCommunity Manager
One point that you may still want to address are the fixed sizes for the range sets. There are several possibilities here:
1- use runtime parameters, like what you are already doing for the filename:
parameters dataSource = "Optimization_TransportationData.xlsm" ! Use Excel spreadsheet `dataCapstone.xlsx' NUMS = 19 NUMP = 10 NUMC = 6 NUMI = 9 end-parameters ! Declaration of sets. declarations Supplier_sites = 1..NUMS !Defines the supplier sites Potential_kf = 1..NUMP !Defines the potential kitting facilities Copackers = 1..NUMC ! Defines the copackers Ingredients = 1..NUMI ! Defines the number of ingredients end-declarations2- use scalar values that are populated from the spreadsheet - note that in order to avoid opening the spreadsheet twice, I have surrounded the two 'initializations from' blocks with fopen/fclose:
declarations NUMS,NUMP,NUMC,NUMI: integer end-declarations fopen("mmsheet.xlsx:"+dataSource, F_INPUT) initializations from "mmsheet.xlsx:"+dataSource ! ...example using a fictitious sheet entry, similarly for other scalars: NUMS as "[Sheet1$A1:A1]" end-initializations declarations Supplier_sites = 1..NUMS !Defines the supplier sites Potential_kf = 1..NUMP !Defines the potential kitting facilities Copackers = 1..NUMC ! Defines the copackers Ingredients = 1..NUMI ! Defines the number of ingredients DISTANCES_M1: dynamic array (Supplier_sites,Potential_kf ) of real ! Distances from sp sites to potential kfs DISTANCES_M2: dynamic array(Potential_kf, Copackers) of real end-declarations initializations from "mmsheet.xlsx:"+dataSource DISTANCES_M1 as 'skiph;[Xpress $A:C]' DISTANCES_M2 as 'skiph;[Xpress $E:G]' end-initializations fclose(F_INPUT)3- Given that your spreadsheet also contains names that get associated with the indices you can also proceed as follows:
declarations NUMS,NUMP,NUMC,NUMI: integer end-declarations fopen("mmsheet.xlsx:"+dataSource, F_INPUT) initializations from "mmsheet.xlsx:"+dataSource ! ...example using a fictitious sheet entry, similarly for other scalars: NUMS as "[Sheet1$A1:A1]" end-initializations declarations Supplier_sites: range !Defines the supplier sites Potential_kf : range !Defines the potential kitting facilities Copackers : range ! Defines the copackers Ingredients: range ! Defines the number of ingredients Supplier_names: array(Supplier_sites) of string Potential_kf_names: array(Potential_kf) of string Copackers_names: array(Copackers) of string Ingredients_names: array(Ingredients) of string DISTANCES_M1: dynamic array (Supplier_sites,Potential_kf ) of real DISTANCES_M2: dynamic array(Potential_kf, Copackers) of real end-declarations initializations from "mmsheet.xlsx:"+dataSource Supplier_names as '[Xpress $I2:J'+(NUMS+1)+']' Potential_kf_names as '[Xpress $K2:L+(NUMP+1)+']' !... DISTANCES_M1 as 'skiph;[Xpress $A:C]' DISTANCES_M2 as 'skiph;[Xpress $E:G]' end-initializations fclose(F_INPUT)Another point regarding the 'DISTANCES' arrays: you seem to be populating all entries, so these are dense arrays, meaning that you should remove the 'dynamic' marker from the definition.
Furthermore, given that the index sets are known upfront, you could read the data from the sheet that has the data in rectangular format, eg:
DISTANCES_M1 as 'skiph;noindex;[Distances_supplier_possiblekf$B:K]'
or
DISTANCES_M1 as 'noindex;[Distances_supplier_possiblekf$R2C2:R'+(NUMS+1)+'C'+(NUMP+1)+']'
- FICOCommunity Manager
What is the error message that you are seeing?
You seem to be missing some quotes (sorry, I just noticed one was missing in my example too):
Supplier_names as '[Xpress $I2:J'+(NUMS+1)+']' Potential_kf_names as '[Xpress $K2:L'+(NUMP+1)+']' Copacker_names as '[Xpress $M2:N'+(NUMC+1)+']'The sheet name 'Xpress ' in the spreadsheet that I have downloaded has a trailing blank, hence the space. Given that this is the second worksheet in the file this form should also be usable (alternatively to this explicit form you can of course always define named ranges within the spreadsheet and simply work with these names as labels within Mosel):
Supplier_names as '[2$I2:J'+(NUMS+1)+']' - FICOCommunity Manager
@Susanne Heipcke
Thanks again.
I figured it out after looking at it some more.
- FICOCommunity Manager
Also, thank you very much for your help.
You made using Xpress much more doable!

