int Dev = 10;// Deviation
extern const int CNN = 3;// 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 = 346;//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]={{{{12664,0,0,0,0,0},{12579,0,0,0,0,0},{12501,0,0,0,0,0},{12192,0,0,0,0,0},{12493,0,0,0,0,0},{12506,0,0,0,0,0},{12153,0,0,0,0,0},{12374,0,0,0,0,0},{12398,0,0,0,0,0},{12374,0,0,0,0,0}},{{12526,0,0,0,0,0},{12399,0,0,0,0,0},{12299,0,0,0,0,0},{12348,0,0,0,0,0},{12273,0,0,0,0,0},{12146,0,0,0,0,0},{12505,0,0,0,0,0},{12415,0,0,0,0,0},{12426,0,0,0,0,0},{12549,0,0,0,0,0}},{{11694,0,0,0,0,0},{11618,0,0,0,0,0},{11484,0,0,0,0,0},{11593,0,0,0,0,0},{11575,0,0,0,0,0},{11665,0,0,0,0,0},{11593,0,0,0,0,0},{11796,0,0,0,0,0},{11453,0,0,0,0,0},{11669,0,0,0,0,0}}},{{{-291,-273,-306,-312,-309,-323},{-320,-279,-312,-297,-282,-297},{-291,-300,-303,-288,-273,-265},{-294,-309,-294,-285,-285,-285},{-276,-279,-282,-268,-288,-320},{-273,-291,-294,-309,-312,-323},{-285,-288,-306,-270,-270,-279},{-303,-291,-318,-270,-294,-315},{-312,-309,-265,-306,-282,-279},{-291,-309,-288,-312,-300,-294}},{{-290,-257,-274,-288,-246,-256},{-290,-292,-283,-247,-283,-280},{-307,-257,-274,-252,-283,-272},{-284,-312,-291,-249,-251,-254},{-278,-263,-308,-288,-259,-254},{-278,-277,-260,-290,-264,-241},{-281,-295,-297,-249,-280,-264},{-261,-312,-269,-258,-264,-254},{-310,-280,-283,-301,-270,-275},{-287,-312,-280,-269,-272,-277}},{{-270,-264,-256,-222,-199,-200},{-252,-223,-242,-237,-233,-196},{-270,-220,-214,-231,-199,-208},{-248,-257,-226,-206,-225,-220},{-255,-242,-240,-206,-218,-204},{-242,-227,-224,-220,-229,-198},{-250,-230,-226,-231,-220,-212},{-238,-259,-240,-231,-229,-206},{-228,-230,-219,-222,-212,-206},{-255,-242,-252,-242,-208,-227}}},{{{-185,-181,-161,-184,-177,-201},{-155,-161,-193,-174,-201,-204},{-180,-164,-178,-170,-180,-189},{-153,-162,-177,-174,-171,-178},{-158,-164,-166,-186,-186,-206},{-180,-184,-187,-193,-169,-191},{-185,-164,-187,-190,-167,-208},{-165,-172,-166,-177,-178,-206},{-158,-186,-182,-177,-169,-210},{-178,-167,-168,-161,-184,-202}},{{-200,-184,-209,-199,-220,-226},{-214,-226,-196,-239,-247,-236},{-184,-217,-200,-234,-215,-248},{-218,-187,-194,-234,-213,-236},{-198,-213,-196,-230,-211,-228},{-198,-195,-192,-236,-229,-221},{-214,-209,-200,-212,-206,-221},{-198,-203,-224,-201,-229,-259},{-206,-184,-215,-243,-224,-233},{-180,-221,-202,-228,-231,-217}},{{-269,-280,-254,-256,-302,-272},{-240,-258,-249,-292,-263,-303},{-237,-247,-246,-243,-260,-263},{-259,-270,-270,-297,-280,-303},{-227,-268,-272,-275,-291,-311},{-272,-260,-262,-267,-291,-266},{-247,-278,-265,-256,-266,-272},{-232,-237,-288,-284,-283,-300},{-240,-242,-286,-262,-249,-289},{-257,-247,-275,-246,-255,-303}}},{{{-322,-326,-329,-355,-342,-326},{-359,-329,-339,-336,-342,-352},{-352,-349,-322,-342,-336,-313},{-299,-362,-362,-329,-299,-313},{-339,-352,-316,-355,-332,-309},{-332,-316,-309,-319,-349,-322},{-352,-352,-299,-319,-299,-332},{-326,-332,-355,-319,-352,-345},{-326,-339,-352,-349,-322,-319},{-316,-303,-339,-362,-322,-355}},{{-338,-332,-329,-283,-326,-328},{-325,-293,-322,-333,-277,-331},{-298,-306,-319,-339,-314,-283},{-351,-322,-300,-333,-277,-301},{-354,-348,-300,-292,-290,-274},{-341,-299,-297,-317,-286,-319},{-312,-335,-316,-336,-305,-295},{-338,-351,-329,-308,-305,-325},{-302,-338,-309,-295,-326,-307},{-338,-345,-338,-333,-333,-316}},{{-322,-262,-297,-264,-249,-244},{-280,-268,-302,-258,-265,-270},{-322,-262,-294,-299,-278,-272},{-307,-285,-297,-272,-265,-252},{-277,-268,-269,-253,-289,-283},{-313,-291,-305,-269,-268,-283},{-266,-300,-305,-280,-284,-244},{-319,-294,-291,-250,-276,-265},{-280,-302,-269,-283,-262,-252},{-316,-262,-286,-248,-289,-267}}},{{{-104,-105,-109,-118,-132,-122},{-113,-117,-120,-115,-122,-129},{-100,-103,-103,-119,-131,-133},{-111,-104,-106,-124,-112,-128},{-98,-105,-121,-112,-133,-140},{-100,-100,-122,-110,-122,-125},{-100,-95,-101,-117,-110,-140},{-102,-99,-110,-116,-113,-141},{-111,-107,-110,-119,-126,-118},{-101,-103,-113,-124,-117,-141}},{{-122,-128,-155,-149,-169,-181},{-131,-155,-148,-170,-164,-176},{-142,-134,-145,-147,-161,-165},{-144,-151,-149,-164,-156,-151},{-134,-127,-141,-146,-163,-178},{-134,-155,-144,-144,-175,-160},{-143,-134,-155,-164,-147,-173},{-135,-135,-148,-146,-163,-155},{-123,-149,-144,-146,-145,-153},{-127,-127,-158,-169,-155,-180}},{{-180,-171,-195,-171,-180,-202},{-180,-178,-197,-188,-180,-200},{-178,-184,-197,-179,-196,-184},{-158,-169,-197,-173,-192,-218},{-187,-198,-177,-182,-204,-180},{-189,-189,-182,-182,-200,-182},{-184,-173,-188,-200,-186,-216},{-164,-198,-177,-207,-210,-200},{-184,-169,-186,-175,-202,-206},{-178,-187,-190,-173,-196,-210}}},{{{-238,-236,-262,-224,-245,-252},{-224,-214,-228,-233,-214,-259},{-217,-245,-255,-257,-224,-250},{-221,-221,-228,-228,-219,-262},{-249,-255,-238,-255,-259,-240},{-233,-259,-243,-248,-250,-226},{-214,-243,-243,-248,-231,-228},{-226,-252,-240,-250,-243,-240},{-226,-248,-252,-214,-248,-250},{-210,-233,-248,-224,-255,-240}},{{-248,-224,-228,-254,-246,-199},{-257,-219,-249,-226,-212,-210},{-248,-217,-230,-233,-249,-199},{-250,-259,-219,-222,-235,-236},{-214,-248,-214,-252,-233,-230},{-259,-262,-237,-219,-240,-206},{-259,-233,-244,-226,-215,-243},{-233,-233,-244,-224,-240,-208},{-262,-259,-240,-224,-237,-206},{-248,-257,-247,-233,-217,-219}},{{-224,-205,-184,-183,-193,-185},{-219,-194,-222,-201,-196,-180},{-194,-190,-210,-177,-194,-198},{-202,-203,-208,-197,-180,-193},{-211,-213,-192,-191,-178,-194},{-196,-203,-206,-213,-168,-171},{-224,-194,-220,-189,-198,-164},{-211,-213,-202,-197,-194,-178},{-230,-222,-208,-213,-174,-182},{-211,-209,-212,-179,-178,-164}}},{{{-239,-261,-271,-277,-242,-245},{-290,-293,-263,-290,-277,-263},{-239,-255,-290,-245,-261,-263},{-253,-253,-239,-263,-277,-263},{-271,-242,-269,-279,-261,-271},{-287,-279,-261,-266,-258,-258},{-266,-279,-242,-242,-258,-263},{-279,-242,-271,-250,-242,-266},{-263,-261,-271,-258,-277,-266},{-250,-277,-255,-279,-258,-255}},{{-290,-279,-247,-269,-288,-267},{-242,-242,-247,-274,-241,-254},{-242,-242,-242,-279,-236,-249},{-258,-282,-239,-269,-244,-262},{-258,-245,-245,-245,-236,-236},{-258,-247,-274,-253,-238,-246},{-271,-269,-287,-293,-257,-275},{-266,-245,-287,-293,-241,-264},{-263,-239,-247,-269,-236,-259},{-290,-261,-242,-250,-272,-280}},{{-277,-276,-234,-265,-257,-241},{-236,-263,-262,-258,-240,-231},{-251,-278,-247,-241,-243,-243},{-249,-268,-270,-233,-228,-227},{-277,-256,-237,-228,-245,-253},{-277,-240,-255,-253,-223,-222},{-236,-276,-229,-223,-230,-263},{-282,-230,-244,-265,-240,-231},{-269,-235,-257,-268,-267,-263},{-280,-230,-260,-250,-238,-231}}},{{{-301,-313,-310,-295,-304,-311},{-301,-289,-307,-295,-331,-308},{-325,-319,-316,-322,-331,-266},{-271,-298,-277,-319,-274,-296},{-286,-325,-286,-295,-295,-293},{-307,-271,-292,-280,-295,-269},{-271,-328,-325,-274,-292,-293},{-307,-274,-280,-310,-271,-305},{-328,-301,-328,-277,-271,-269},{-277,-331,-277,-325,-310,-287}},{{-296,-293,-308,-254,-254,-267},{-296,-258,-252,-254,-273,-270},{-305,-273,-302,-284,-281,-260},{-293,-270,-277,-262,-244,-252},{-311,-261,-272,-287,-252,-267},{-281,-270,-280,-295,-252,-267},{-316,-267,-288,-278,-265,-242},{-275,-301,-272,-254,-254,-267},{-290,-301,-291,-257,-276,-231},{-278,-316,-291,-295,-262,-254}},{{-246,-257,-252,-232,-193,-192},{-255,-252,-240,-239,-214,-188},{-273,-218,-236,-219,-191,-200},{-253,-226,-245,-214,-216,-182},{-246,-228,-208,-236,-193,-202},{-248,-230,-231,-212,-233,-202},{-231,-218,-224,-239,-233,-218},{-246,-254,-227,-243,-227,-216},{-243,-242,-215,-203,-199,-182},{-268,-245,-229,-241,-227,-210}}},{{{-385,-371,-382,-354,-385,-368},{-322,-364,-364,-326,-354,-322},{-364,-357,-326,-368,-382,-340},{-354,-371,-346,-329,-385,-329},{-343,-340,-354,-385,-371,-340},{-357,-340,-385,-364,-382,-364},{-336,-329,-318,-322,-315,-378},{-357,-357,-318,-318,-326,-385},{-360,-329,-318,-378,-357,-315},{-332,-350,-315,-336,-332,-368}},{{-379,-367,-346,-364,-361,-309},{-355,-377,-329,-331,-354,-319},{-369,-333,-349,-367,-295,-319},{-376,-350,-329,-351,-354,-293},{-383,-364,-339,-341,-348,-319},{-320,-319,-336,-314,-328,-293},{-369,-364,-319,-344,-348,-290},{-369,-343,-319,-334,-325,-354},{-369,-370,-336,-337,-341,-325},{-317,-329,-332,-344,-321,-299}},{{-340,-317,-303,-299,-291,-267},{-331,-311,-285,-281,-291,-275},{-284,-296,-330,-311,-296,-281},{-328,-302,-279,-287,-285,-272},{-296,-311,-324,-316,-311,-253},{-312,-336,-321,-311,-296,-295},{-343,-333,-300,-308,-262,-259},{-299,-339,-300,-322,-294,-264},{-315,-277,-276,-267,-288,-303},{-302,-330,-285,-293,-294,-292}}}}; // 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]={7,3,2,6,3,2,6,3,2,7,4,3,8,4,3,7,4,3,8,4,3,7,4,3,8,4,3,7,4,3,7,4,3,7,4,3,8,5,3,9,5,3,8,4,3,9,4,3,9,5,3,8,4,3,8,4,3,8,4,3,8,4,3,7,4,3,7,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}}; // set of shipments in each bid 
int SHsts[SPN]={0,2,4,6,8,10,12,2,6,10,2,8,2,4,6,8,10,12,2,6,10,1,7,1,3,5,7,9,11,2,6,10,1,7,2,4,6,8,10,12,14,1,5,9,13,1,7,13,0,2,4,6,8,10,12,14,0,4,8,12,0,6,12,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,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,0,4,8,12,0,6,12,2,4,6,8,10,12,14,2,6,10,14,1,7,13,2,4,6,8,10,12,14,1,5,9,13,1,7,13,2,4,6,8,10,12,14,2,6,10,14,1,7,13,1,3,5,7,9,11,13,15,0,4,8,12,16,1,7,13,0,2,4,6,8,10,12,14,16,0,4,8,12,16,1,7,13,1,3,5,7,9,11,13,15,1,5,9,13,1,7,13,0,2,4,6,8,10,12,14,16,2,6,10,14,2,8,14,0,2,4,6,8,10,12,14,16,0,4,8,12,16,0,6,12,2,4,6,8,10,12,14,16,2,6,10,14,1,7,13,1,3,5,7,9,11,13,15,2,6,10,14,1,7,13,0,2,4,6,8,10,12,14,0,4,8,12,2,8,14,1,3,5,7,9,11,13,15,2,6,10,14,1,7,13,1,3,5,7,9,11,13,0,4,8,12,0,6,12,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}; // set of start times of each shipment 
int SHets[SPN]={5,7,9,11,13,15,17,7,11,15,7,13,7,9,11,13,15,17,7,11,15,6,12,6,8,10,12,14,16,7,11,15,6,12,5,7,9,11,13,15,17,4,8,12,16,4,10,16,3,5,7,9,11,13,15,17,3,7,11,15,3,9,15,5,7,9,11,13,15,17,3,7,11,15,3,9,15,2,4,6,8,10,12,14,16,3,7,11,15,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,2,6,10,14,2,8,14,4,6,8,10,12,14,16,4,8,12,16,3,9,15,4,6,8,10,12,14,16,3,7,11,15,3,9,15,4,6,8,10,12,14,16,4,8,12,16,3,9,15,2,4,6,8,10,12,14,16,1,5,9,13,17,2,8,14,1,3,5,7,9,11,13,15,17,1,5,9,13,17,2,8,14,2,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,3,9,15,1,3,5,7,9,11,13,15,17,1,5,9,13,17,1,7,13,3,5,7,9,11,13,15,17,3,7,11,15,2,8,14,3,5,7,9,11,13,15,17,4,8,12,16,3,9,15,2,4,6,8,10,12,14,16,2,6,10,14,4,10,16,3,5,7,9,11,13,15,17,4,8,12,16,3,9,15,4,6,8,10,12,14,16,3,7,11,15,3,9,15,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}; // set of end times of each shipment 
