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
Hi Kibrom,
yes, I was referring to that one, but if you managed to reformulate the problem in a way that gets rid of any nonlinearities completely, then that is even better of course.
- FICOCommunity Manager
Hi Tristan,
I managed to do so yesterday with this line instead
forall(i in Potential_kf) sum(j in Copackers) kf_copacker(i,j) = getsize(Copackers)*kf(i)Is it true that removing the nonlinearities reduces the runtime?
Also, is there a whitepaper on how to reduce runtime? I am nearly done with my model and have started to read in larger datasets and the response time is becoming unreasonably long.
Thanks again Tristan for your input. It is greatly appreciated.
- FICOCommunity Manager
Hi Kibrom,
the tuning guide in our documentation should give you some ideas of what to try: https://www.fico.com/fico-xpress-optimization/docs/dms2021-01/opttuning/GUID-A812CF0D-3316-34F0-85D9-ACADCB4497AB.html
If you get stuck with it, we also offer to help with this.
- FICOCommunity Manager
Hi Tristan,
Sounds good. Thanks again.
Two questions:
1) I am not sure why I am getting an error when populating an array within an array with one element. Some ingredients only have one supplier.
! Declaration of sets. This is will eventually be a list declarations Supplier_sites = 1..16 !Defines the supplier sites Potential_kf = 1..2 !Defines the potential kitting facilities Copackers = 1..6 ! Defines the copackers Ingredients = 1..8 ! Defines the number of ingredients test_Supplier_sites: array(Ingredients) of list of integer !... end-declarations !Declaration of parameters declarations DISTANCES_M1: array (Supplier_sites,Potential_kf ) of integer ! Distances from sp sites to potential kfs DISTANCES_M2: array(Potential_kf, Copackers) of integer ! Distances from sp sites to potential kfs INGREDIENT_DEMAND: array(Ingredients) of real end-declarations !read data from file initializations from "mmsheet.excel:"+ dataSource DISTANCES_M1 as 'Supplier_PotentialKf' DISTANCES_M2 as 'Possiblekf_Copacker' end-initializations declarations supplier_kf: array(Supplier_sites,Potential_kf) of mpvar kf_copacker: array(Potential_kf, Copackers) of mpvar kf: array(Potential_kf) of mpvar !sp: array(Supplier_sites) of mpvar end-declarations ! Objective: Minimize the overall cost of the new supply chain MinCost := sum(i in Supplier_sites, j in Potential_kf )supplier_kf(i,j)*DISTANCES_M1(i,j) + sum(i in Potential_kf, j in Copackers) kf_copacker(i,j)*DISTANCES_M2(i,j) test_Supplier_sites :: [[1],[2,3],[4],[5],[6],[7,8],[9,10],[11..16]] n := 1 m := 12) I am on PST and wondering if you and Susanne are operating from a different timezone. I am only asking so I can plan my work more strategically.
At any rate, this forum is a helpful resource.
- FICOCommunity Manager
This is the error: Mosel: E-101 at (52,68) of `Model_v7.mos': Incompatible types in initialiser list (`list of integer' expected).
- FICOCommunity Manager
Hi Kibrom,
0) I think I didn't answer this before, but yes, nonlinearities (just as additional non-implied integrality constraints) will make the problem harder to solve and increase run-times. In particular equality constraints with quadratics (unless transformable when all variables are binary or with some other tricks) will make the problem or more specifically the continuous relaxation non-convex, meaning that the solver can no longer guarantee global optimality and will only return locally optimal solutions.
1) I believe you ommitted the first lines of the file, unfortunately this means that the line numbers won't match the error message, could you point out which line in the file you posted here the errors message refers to?
2) Indeed we are both located in Europe.
- FICOCommunity Manager
Tristan,
Thank you for the information. The error is now resolved so that is taken care of.
- FICOCommunity Manager
Good evening,
Can you point me to a resource or explain to me how I can set the ranges for suppliers, possible kitting facilities and copackers based on the data read in from the Excel file?
Currently, it is hard-coded and thus not very flexible. I will eventually also encode each of the suppliers with key to correspond to an ingredient but that is the next step.
I have copied part of the code below. Note that I have left out the Excel file because it is calling an API through a macro.
model Model_v7 !options noimplicit !Changes from v1: Data points read rather than entered !Ingredients added to the model uses "mmxprs" uses "mmsheet" ! uses "mminsight" ! uncomment this line for an Xpress Insight model parameters dataSource = "dataCapstone.xlsm" ! Use Excel spreadsheet `dataCapstone.xlsx' end-parameters ! Declaration of sets. This is will eventually be a list declarations Supplier_sites = 1..16 !Defines the supplier sites Potential_kf = 1..11 !Defines the potential kitting facilities Copackers = 1..6 ! Defines the copackers Ingredients = 1..8 ! Defines the number of ingredients test_Supplier_sites: array(Ingredients) of list of integer !... end-declarations !Declaration of parameters declarations 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 ! Distances from sp sites to potential kfs ! INGREDIENT_DEMAND: array(Ingredients) of real end-declarations !read data from file initializations from "mmsheet.excel:"+dataSource DISTANCES_M1 as 'Supplier_PotentialKf' DISTANCES_M2 as 'Possiblekf_Copacker' end-initializations declarations supplier_kf: array(Supplier_sites,Potential_kf) of mpvar kf_copacker: array(Potential_kf, Copackers) of mpvar kf: array(Potential_kf) of mpvar !sp: array(Supplier_sites) of mpvar end-declarations ! Objective: Minimize the overall cost of the new supply chain MinCost := sum(i in Supplier_sites, j in Potential_kf )supplier_kf(i,j)*DISTANCES_M1(i,j) + sum(i in Potential_kf, j in Copackers) kf_copacker(i,j)*DISTANCES_M2(i,j) test_Supplier_sites :: [[1],[2,3],[4],[5],[6],[7,8],[9,10],[11,12,13,14,15,16]]Lines 17,18 and 19 restricts the input to the specific range which makes it rigid.
Thanks again @Tristan Gally and @Susanne Heipcke for all the input.
- FICOCommunity Manager
If the ranges you have specified within your spreadsheet include the index values then there is no need to provide any fixed values for index sets within your model (it is indeed generally recommended good practice for optimization model implementations to make your model code independent of specific data instances by removing any fixed data from the model itself). For your case you should be able to use declarations along these lines:
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 test_Supplier_sites: array(Ingredients) of list of integer end-declarations ! Read data from file (range definitions are expected to contain index values) initializations from "mmsheet.excel:"+dataSource DISTANCES_M1 as 'Supplier_PotentialKf' DISTANCES_M2 as 'Possiblekf_Copacker' end-initializations !... ! Specify index range if not known previously: test_Supplier_sites :: [1..8][[1],[2,3],[4],[5],[6],[7,8],[9,10],[11,12,13,14,15,16]] - FICOCommunity Manager
@Susanne Heipcke
Hi!
I attempted to implement your suggestion and realized my Excel sheet is not set up to read in the index values. As far as your explanation, that makes sense since my named ranges consist of pairs.
To address this issue, I decided to instead go ahead and create named/dynamic ranges simply for the index and then read it in. Sort of like this:
model Model_v9 !options noimplicit !Changes from v1: Data points read rather than entered !Ingredients added to the model uses "mmxprs" uses "mmsheet" ! uses "mminsight" ! uncomment this line for an Xpress Insight model parameters dataSource = "dataCapstone.xlsm" ! Use Excel spreadsheet `dataCapstone.xlsx' end-parameters ! Declaration of sets. This is will eventually be a list declarations Supplier_sites = array(Supplier_list) of integer !Defines the supplier sites Potential_kf = array(Potentialkf_list) of integer !Defines the potential kitting facilities Copackers = array(Copackers_list) of integer ! Defines the copackers Ingredients = array(Ingredients_list) of integer ! Defines the number of ingredients test_Supplier_sites: array(Ingredients) of list of integer end-declarations !Declaration of parameters declarations 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 ! Distances from sp sites to potential kfs end-declarations !read data from file initializations from "mmsheet.excel:"+dataSource DISTANCES_M1 as 'Supplier_PotentialKf' DISTANCES_M2 as 'Possiblekf_Copacker' Supplier_list as !Named range for index Potentialkf_list !Named range for index Copackers_list !Named range for index Ingredients_list !Named range for index end-initializations !DISTANCES_M2(4,1) := 1000000 Uncomment this line to obtain the second optimal city to locate the possible facility location - Big M method !DISTANCES_M2(8,1) := 1000000 Uncomment this line to obtain the third optimal city to locate the possible facility location - Big M method declarations supplier_kf: array(Supplier_sites,Potential_kf) of mpvar kf_copacker: array(Potential_kf, Copackers) of mpvar kf: array(Potential_kf) of mpvar end-declarations forall(i in Supplier_sites,j in Potential_kf) do writeln(DISTANCES_M1(i,j)) writeln("Index: "+i+" "+j) end-doI have not been able to prove that this works yet. I intended to do so tomorrow morning.
I hope you can provide some input on whether I am on the right track.
Sincerely,
Kibrom

