int Dev = 40;// Deviation
extern const int CNN = 5;// Case Index
extern const int P = 3;// Number of phases
extern const int PT = 6;// Number of periods in a phase
extern const int T = 18;// Number of periods
extern const int I1 =1;// Number of suppliers
extern const int I2 = 8;// Number of customers
extern const int I = 9;// Number of sites
extern const int BN = 72;//Number of bids
extern const int LBN = 9;//Number of bids on each arc
extern const int SPN = 351;//Number of shipments
extern const int SN = 10;//Number of scenarios at each stage
extern const int MBSN = 9;//Number of shipments in a bid
// tree parameters:
double PRO[P][SN]={{0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1},{0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1},{0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1}}; // the probability of each scenario at each phase 
// timing parameters: 
int PTN[P]={6,6,6}; // number of periods in each phase 
int PTset[P][PT]={{0,1,2,3,4,5},{6,7,8,9,10,11},{12,13,14,15,16,17}}; // set of periods in each phase 
// distribution parameters: 
int sup[I][P][SN][PT]={{{{11698,0,0,0,0,0},{12638,0,0,0,0,0},{12294,0,0,0,0,0},{12270,0,0,0,0,0},{13090,0,0,0,0,0},{12419,0,0,0,0,0},{12099,0,0,0,0,0},{12195,0,0,0,0,0},{13228,0,0,0,0,0},{12518,0,0,0,0,0}},{{11892,0,0,0,0,0},{12519,0,0,0,0,0},{12268,0,0,0,0,0},{12429,0,0,0,0,0},{12611,0,0,0,0,0},{12100,0,0,0,0,0},{12292,0,0,0,0,0},{12544,0,0,0,0,0},{13521,0,0,0,0,0},{12614,0,0,0,0,0}},{{11301,0,0,0,0,0},{11309,0,0,0,0,0},{11380,0,0,0,0,0},{11559,0,0,0,0,0},{11174,0,0,0,0,0},{11397,0,0,0,0,0},{12194,0,0,0,0,0},{11262,0,0,0,0,0},{11564,0,0,0,0,0},{10915,0,0,0,0,0}}},{{{-179,-247,-238,-309,-329,-391},{-294,-256,-344,-412,-412,-259},{-373,-182,-197,-297,-259,-379},{-344,-341,-300,-206,-403,-312},{-388,-403,-268,-206,-397,-409},{-218,-212,-373,-353,-282,-332},{-320,-253,-247,-276,-412,-185},{-191,-291,-279,-320,-268,-291},{-400,-300,-223,-256,-318,-312},{-247,-350,-235,-194,-265,-218}},{{-296,-360,-339,-227,-160,-360},{-264,-263,-235,-203,-302,-155},{-351,-183,-241,-334,-166,-246},{-264,-317,-333,-307,-363,-241},{-345,-326,-353,-279,-176,-168},{-293,-343,-336,-175,-336,-215},{-270,-269,-260,-233,-336,-176},{-206,-237,-263,-307,-304,-311},{-310,-372,-274,-323,-240,-192},{-290,-223,-274,-326,-328,-205}},{{-292,-237,-158,-217,-195,-235},{-345,-220,-161,-155,-229,-280},{-302,-182,-172,-215,-128,-286},{-330,-237,-256,-159,-175,-278},{-242,-172,-273,-255,-163,-194},{-348,-273,-282,-137,-257,-253},{-322,-266,-296,-258,-261,-233},{-158,-329,-317,-228,-229,-124},{-320,-213,-310,-190,-128,-235},{-158,-240,-231,-195,-143,-229}}},{{{-161,-132,-208,-236,-193,-124},{-235,-206,-196,-209,-123,-162},{-108,-101,-136,-125,-167,-178},{-228,-123,-203,-227,-120,-141},{-197,-181,-170,-247,-219,-264},{-202,-203,-133,-240,-245,-174},{-160,-115,-212,-209,-247,-168},{-212,-201,-226,-115,-184,-250},{-185,-139,-121,-231,-202,-267},{-150,-164,-147,-140,-110,-181}},{{-228,-275,-168,-181,-153,-269},{-121,-139,-234,-214,-318,-236},{-131,-152,-230,-292,-321,-317},{-249,-135,-143,-135,-179,-157},{-156,-244,-230,-281,-268,-257},{-234,-168,-275,-203,-192,-226},{-234,-193,-160,-230,-270,-274},{-178,-180,-145,-144,-206,-255},{-164,-180,-143,-287,-268,-314},{-190,-207,-166,-228,-277,-143}},{{-338,-252,-288,-308,-208,-195},{-158,-293,-196,-200,-233,-311},{-183,-237,-241,-181,-199,-266},{-230,-332,-217,-294,-241,-170},{-210,-186,-170,-200,-233,-342},{-158,-245,-299,-246,-222,-351},{-306,-230,-176,-211,-363,-331},{-165,-158,-225,-359,-271,-252},{-225,-173,-356,-338,-202,-291},{-183,-240,-233,-367,-208,-241}}},{{{-293,-447,-227,-211,-273,-447},{-316,-296,-342,-431,-286,-247},{-359,-240,-332,-395,-345,-424},{-342,-349,-283,-217,-395,-454},{-266,-349,-293,-332,-201,-424},{-230,-286,-286,-418,-332,-349},{-296,-211,-408,-296,-296,-276},{-461,-332,-454,-280,-207,-401},{-204,-368,-368,-451,-293,-207},{-398,-401,-345,-273,-395,-418}},{{-338,-309,-204,-270,-286,-367},{-459,-386,-204,-440,-302,-412},{-440,-296,-246,-298,-422,-277},{-259,-235,-325,-421,-394,-295},{-384,-354,-278,-283,-293,-277},{-443,-232,-325,-440,-271,-310},{-200,-332,-233,-408,-360,-190},{-233,-229,-329,-267,-336,-394},{-210,-351,-386,-371,-407,-316},{-308,-354,-220,-424,-314,-208}},{{-378,-202,-190,-190,-360,-252},{-233,-259,-367,-215,-368,-162},{-239,-193,-258,-264,-313,-200},{-301,-354,-322,-199,-323,-316},{-251,-348,-207,-367,-170,-193},{-378,-279,-364,-307,-244,-290},{-177,-377,-297,-356,-215,-344},{-301,-268,-232,-169,-313,-293},{-254,-179,-364,-180,-310,-188},{-218,-242,-190,-185,-262,-211}}},{{{-91,-132,-118,-116,-94,-113},{-123,-82,-152,-152,-118,-168},{-68,-120,-100,-133,-104,-151},{-72,-106,-86,-101,-89,-128},{-121,-109,-155,-78,-171,-97},{-64,-143,-119,-150,-77,-124},{-121,-99,-125,-108,-102,-178},{-66,-68,-72,-99,-73,-128},{-134,-131,-136,-81,-94,-138},{-106,-112,-143,-111,-149,-108}},{{-115,-165,-182,-202,-151,-109},{-154,-106,-192,-208,-140,-155},{-109,-178,-133,-209,-101,-192},{-139,-120,-126,-126,-126,-108},{-161,-161,-192,-189,-172,-213},{-131,-127,-172,-104,-129,-131},{-108,-140,-160,-149,-124,-235},{-111,-124,-201,-208,-97,-166},{-116,-173,-126,-147,-148,-121},{-185,-134,-148,-136,-130,-128}},{{-164,-203,-249,-243,-151,-160},{-166,-115,-173,-120,-270,-269},{-136,-252,-173,-245,-210,-275},{-194,-133,-130,-226,-172,-184},{-205,-148,-201,-139,-245,-206},{-182,-247,-195,-152,-227,-176},{-243,-160,-121,-251,-182,-190},{-200,-144,-158,-158,-188,-251},{-135,-241,-143,-201,-190,-244},{-166,-124,-214,-241,-237,-162}}},{{{-308,-217,-314,-152,-219,-286},{-282,-267,-257,-269,-214,-317},{-308,-145,-317,-195,-324,-252},{-249,-217,-286,-302,-257,-228},{-301,-200,-281,-300,-278,-302},{-275,-195,-155,-143,-264,-193},{-163,-178,-295,-221,-309,-188},{-252,-148,-255,-188,-333,-155},{-270,-233,-274,-148,-288,-300},{-268,-307,-164,-178,-305,-155}},{{-159,-169,-294,-268,-136,-290},{-152,-300,-306,-249,-226,-232},{-207,-207,-242,-141,-142,-252},{-226,-298,-291,-291,-307,-148},{-157,-278,-157,-180,-160,-210},{-328,-248,-266,-157,-190,-252},{-205,-283,-181,-293,-217,-265},{-269,-328,-223,-303,-294,-212},{-224,-331,-266,-169,-316,-259},{-226,-324,-212,-268,-165,-278}},{{-200,-165,-261,-156,-114,-149},{-142,-278,-275,-195,-198,-252},{-166,-186,-238,-123,-161,-209},{-198,-161,-206,-265,-213,-187},{-194,-265,-267,-226,-122,-223},{-247,-215,-182,-119,-194,-160},{-262,-127,-149,-154,-236,-252},{-230,-127,-206,-127,-142,-166},{-185,-293,-204,-172,-116,-221},{-194,-130,-208,-152,-116,-146}}},{{{-274,-309,-221,-229,-205,-173},{-178,-168,-170,-197,-176,-309},{-372,-162,-253,-290,-255,-242},{-194,-317,-239,-327,-189,-247},{-356,-290,-223,-261,-207,-346},{-362,-176,-295,-346,-309,-279},{-354,-202,-242,-277,-239,-261},{-215,-250,-162,-266,-178,-356},{-282,-309,-322,-277,-351,-250},{-269,-314,-197,-178,-205,-346}},{{-250,-295,-207,-258,-275,-228},{-261,-322,-354,-338,-228,-218},{-311,-237,-207,-348,-238,-329},{-261,-210,-325,-197,-259,-181},{-285,-218,-186,-231,-367,-171},{-218,-170,-277,-367,-236,-171},{-207,-348,-269,-250,-196,-210},{-298,-351,-340,-189,-307,-269},{-319,-301,-335,-309,-225,-249},{-356,-263,-306,-335,-252,-212}},{{-282,-309,-202,-270,-206,-236},{-238,-316,-151,-226,-157,-174},{-332,-177,-265,-280,-299,-214},{-254,-200,-159,-169,-338,-193},{-357,-220,-272,-176,-218,-229},{-326,-157,-179,-211,-172,-241},{-155,-286,-285,-201,-316,-270},{-238,-354,-176,-221,-292,-333},{-300,-331,-285,-218,-255,-190},{-321,-326,-227,-315,-260,-222}}},{{{-304,-388,-196,-184,-355,-299},{-391,-391,-325,-265,-418,-385},{-289,-241,-322,-376,-343,-311},{-244,-334,-358,-358,-208,-201},{-334,-397,-268,-220,-298,-260},{-292,-277,-214,-268,-361,-317},{-199,-397,-202,-325,-277,-400},{-406,-304,-301,-406,-400,-355},{-262,-409,-397,-412,-325,-263},{-331,-421,-325,-331,-406,-260}},{{-290,-210,-216,-303,-355,-221},{-220,-298,-202,-284,-299,-265},{-396,-210,-350,-265,-310,-180},{-375,-187,-378,-311,-321,-167},{-396,-330,-361,-229,-207,-182},{-252,-184,-314,-232,-318,-154},{-214,-373,-342,-358,-178,-316},{-229,-281,-283,-284,-246,-334},{-328,-376,-392,-257,-262,-352},{-372,-373,-336,-246,-273,-159}},{{-159,-216,-286,-175,-178,-226},{-320,-307,-295,-292,-170,-133},{-253,-269,-286,-281,-151,-152},{-315,-211,-318,-298,-157,-261},{-161,-209,-206,-234,-261,-263},{-273,-161,-282,-148,-146,-147},{-332,-168,-279,-261,-214,-129},{-273,-334,-183,-141,-138,-216},{-179,-264,-156,-206,-259,-184},{-347,-310,-227,-234,-201,-149}}},{{{-220,-332,-273,-217,-357,-357},{-374,-298,-389,-241,-284,-252},{-214,-329,-315,-438,-413,-315},{-231,-410,-326,-270,-340,-368},{-214,-357,-458,-238,-357,-399},{-294,-466,-280,-270,-441,-402},{-231,-455,-241,-392,-262,-469},{-228,-238,-413,-357,-304,-256},{-266,-487,-480,-371,-434,-259},{-389,-430,-490,-224,-343,-322}},{{-369,-233,-237,-381,-302,-232},{-404,-322,-386,-321,-226,-264},{-480,-257,-325,-240,-207,-322},{-268,-220,-454,-367,-446,-444},{-414,-209,-451,-387,-390,-415},{-411,-295,-315,-237,-433,-264},{-372,-429,-278,-428,-230,-306},{-452,-271,-319,-204,-453,-374},{-484,-302,-386,-341,-371,-428},{-285,-425,-427,-210,-456,-309}},{{-233,-225,-396,-258,-348,-386},{-271,-293,-276,-284,-271,-297},{-350,-419,-390,-272,-171,-386},{-249,-253,-297,-378,-325,-181},{-359,-293,-327,-275,-197,-300},{-321,-256,-402,-176,-353,-217},{-394,-410,-282,-296,-339,-231},{-312,-394,-363,-252,-368,-186},{-296,-308,-336,-346,-325,-325},{-287,-197,-309,-360,-379,-178}}}}; // supply (positive for supply and negative for demand) under different scenarios 
int iniv[I]={1052,192,238,253,176,234,280,264,252}; // initial inventory 
int ubiv[I]={2104,384,476,507,352,468,350,495,504}; // the upper bounds of inventory 
int len[I1][I2]={{5,3,2,2,1,1,2,3}}; // the traveling time between two sites 
// cost parameters: 
double c1[I]={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}; // inventory holding cost 
double c2[I]={0.05,13.35,8.59,5.57,4.52,2.83,1.94,4.81,7.57}; // cost of leftover and unmet 
double c3[BN]={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}; // transportation cost for capacity contracts 
double c4[I1][I2]={{12.14,7.81,5.06,4.11,2.57,1.76,4.37,6.88}}; // cost of spot market 
// bid parameters: 
int RLBN[I1][I2]={{9,9,9,9,9,9,9,9}}; // number of bids on each arc 
int LBset[I1][I2][LBN]={{{0,1,2,3,4,5,6,7,8},{9,10,11,12,13,14,15,16,17},{18,19,20,21,22,23,24,25,26},{27,28,29,30,31,32,33,34,35},{36,37,38,39,40,41,42,43,44},{45,46,47,48,49,50,51,52,53},{54,55,56,57,58,59,60,61,62},{63,64,65,66,67,68,69,70,71}}}; // set of bids on each arc 
double frt[BN]={9.71,9.71,9.71,8.5,8.5,8.5,7.28,7.28,7.28,6.25,6.25,6.25,5.47,5.47,5.47,4.69,4.69,4.69,4.05,4.05,4.05,3.54,3.54,3.54,3.04,3.04,3.04,3.29,3.29,3.29,2.88,2.88,2.88,2.47,2.47,2.47,2.06,2.06,2.06,1.8,1.8,1.8,1.54,1.54,1.54,1.41,1.41,1.41,1.23,1.23,1.23,1.06,1.06,1.06,3.5,3.5,3.5,3.06,3.06,3.06,2.62,2.62,2.62,5.5,5.5,5.5,4.82,4.82,4.82,4.13,4.13,4.13}; // freight rate of each bid 
int lbcap[BN]={75,75,75,1,151,151,151,226,226,75,75,75,301,151,151,151,226,226,75,75,75,301,151,151,151,226,226,75,75,75,301,151,151,151,226,226,75,75,75,301,151,151,151,226,226,75,75,75,301,151,151,151,226,226,75,75,75,301,151,151,151,226,226,75,75,75,301,151,151,151,226,226}; // capacity lower bound of each bid 
int ubcap[BN]={150,150,150,225,225,225,300,300,300,150,150,150,225,225,225,300,300,300,150,150,150,225,225,225,300,300,300,150,150,150,225,225,225,300,300,300,150,150,150,225,225,225,300,300,300,150,150,150,225,225,225,300,300,300,150,150,150,225,225,225,300,300,300,150,150,150,225,225,225,300,300,300}; // capacity upper bound of each bid 
// shipment parameters: 
int SHN[BN]={6,4,2,7,3,2,7,4,3,8,4,3,8,4,3,7,4,3,8,4,3,8,4,3,7,4,3,7,4,3,8,4,3,7,4,3,9,4,3,8,4,3,9,5,3,8,4,3,9,4,3,8,4,3,8,4,3,7,4,3,8,4,3,8,4,3,8,4,3,7,4,3}; // number of shipment for each bid 
int SHset[BN][MBSN]={{0,1,2,3,4,5},{6,7,8,9},{10,11},{12,13,14,15,16,17,18},{19,20,21},{22,23},{24,25,26,27,28,29,30},{31,32,33,34},{35,36,37},{38,39,40,41,42,43,44,45},{46,47,48,49},{50,51,52},{53,54,55,56,57,58,59,60},{61,62,63,64},{65,66,67},{68,69,70,71,72,73,74},{75,76,77,78},{79,80,81},{82,83,84,85,86,87,88,89},{90,91,92,93},{94,95,96},{97,98,99,100,101,102,103,104},{105,106,107,108},{109,110,111},{112,113,114,115,116,117,118},{119,120,121,122},{123,124,125},{126,127,128,129,130,131,132},{133,134,135,136},{137,138,139},{140,141,142,143,144,145,146,147},{148,149,150,151},{152,153,154},{155,156,157,158,159,160,161},{162,163,164,165},{166,167,168},{169,170,171,172,173,174,175,176,177},{178,179,180,181},{182,183,184},{185,186,187,188,189,190,191,192},{193,194,195,196},{197,198,199},{200,201,202,203,204,205,206,207,208},{209,210,211,212,213},{214,215,216},{217,218,219,220,221,222,223,224},{225,226,227,228},{229,230,231},{232,233,234,235,236,237,238,239,240},{241,242,243,244},{245,246,247},{248,249,250,251,252,253,254,255},{256,257,258,259},{260,261,262},{263,264,265,266,267,268,269,270},{271,272,273,274},{275,276,277},{278,279,280,281,282,283,284},{285,286,287,288},{289,290,291},{292,293,294,295,296,297,298,299},{300,301,302,303},{304,305,306},{307,308,309,310,311,312,313,314},{315,316,317,318},{319,320,321},{322,323,324,325,326,327,328,329},{330,331,332,333},{334,335,336},{337,338,339,340,341,342,343},{344,345,346,347},{348,349,350}}; // set of shipments in each bid 
int SHsts[SPN]={1,3,5,7,9,11,0,4,8,12,2,8,0,2,4,6,8,10,12,1,5,9,2,8,0,2,4,6,8,10,12,0,4,8,12,0,6,12,0,2,4,6,8,10,12,14,0,4,8,12,1,7,13,0,2,4,6,8,10,12,14,0,4,8,12,1,7,13,1,3,5,7,9,11,13,1,5,9,13,2,8,14,0,2,4,6,8,10,12,14,2,6,10,14,1,7,13,1,3,5,7,9,11,13,15,2,6,10,14,2,8,14,2,4,6,8,10,12,14,2,6,10,14,2,8,14,2,4,6,8,10,12,14,0,4,8,12,0,6,12,0,2,4,6,8,10,12,14,1,5,9,13,1,7,13,2,4,6,8,10,12,14,0,4,8,12,0,6,12,0,2,4,6,8,10,12,14,16,2,6,10,14,1,7,13,1,3,5,7,9,11,13,15,1,5,9,13,2,8,14,0,2,4,6,8,10,12,14,16,0,4,8,12,16,2,8,14,2,4,6,8,10,12,14,16,2,6,10,14,2,8,14,0,2,4,6,8,10,12,14,16,1,5,9,13,0,6,12,1,3,5,7,9,11,13,15,1,5,9,13,2,8,14,0,2,4,6,8,10,12,14,0,4,8,12,0,6,12,2,4,6,8,10,12,14,2,6,10,14,1,7,13,0,2,4,6,8,10,12,14,1,5,9,13,0,6,12,0,2,4,6,8,10,12,14,0,4,8,12,1,7,13,0,2,4,6,8,10,12,14,2,6,10,14,2,8,14,2,4,6,8,10,12,14,2,6,10,14,2,8,14}; // set of start times of each shipment 
int SHets[SPN]={6,8,10,12,14,16,5,9,13,17,7,13,5,7,9,11,13,15,17,6,10,14,7,13,5,7,9,11,13,15,17,5,9,13,17,5,11,17,3,5,7,9,11,13,15,17,3,7,11,15,4,10,16,3,5,7,9,11,13,15,17,3,7,11,15,4,10,16,4,6,8,10,12,14,16,4,8,12,16,5,11,17,2,4,6,8,10,12,14,16,4,8,12,16,3,9,15,3,5,7,9,11,13,15,17,4,8,12,16,4,10,16,4,6,8,10,12,14,16,4,8,12,16,4,10,16,4,6,8,10,12,14,16,2,6,10,14,2,8,14,2,4,6,8,10,12,14,16,3,7,11,15,3,9,15,4,6,8,10,12,14,16,2,6,10,14,2,8,14,1,3,5,7,9,11,13,15,17,3,7,11,15,2,8,14,2,4,6,8,10,12,14,16,2,6,10,14,3,9,15,1,3,5,7,9,11,13,15,17,1,5,9,13,17,3,9,15,3,5,7,9,11,13,15,17,3,7,11,15,3,9,15,1,3,5,7,9,11,13,15,17,2,6,10,14,1,7,13,2,4,6,8,10,12,14,16,2,6,10,14,3,9,15,2,4,6,8,10,12,14,16,2,6,10,14,2,8,14,4,6,8,10,12,14,16,4,8,12,16,3,9,15,2,4,6,8,10,12,14,16,3,7,11,15,2,8,14,3,5,7,9,11,13,15,17,3,7,11,15,4,10,16,3,5,7,9,11,13,15,17,5,9,13,17,5,11,17,5,7,9,11,13,15,17,5,9,13,17,5,11,17}; // set of end times of each shipment 
