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
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)+']'

