├── All Codes-Part 1 and 2.zip ├── Cpp_Cplex_for_Optimization_Problems.pdf ├── Cutting_Stock- Column Generation ├── Cutting_Stock.sln └── Cutting_Stock │ ├── Cutting_Stock.vcxproj │ ├── Cutting_Stock.vcxproj.filters │ ├── Cutting_Stock.vcxproj.user │ ├── Functions.h │ ├── KnapsackProblem.cpp │ ├── Main.cpp │ ├── ProblemData.cpp │ ├── ProblemData.h │ ├── RandGen.cpp │ └── RandGen.h ├── FCTP-Benders Decomposition ├── FCTP.sln └── FCTP │ ├── CutClass.cpp │ ├── Data-Funcs-Classes.h │ ├── FCTP.vcxproj │ ├── FCTP.vcxproj.filters │ ├── FCTP.vcxproj.user │ ├── Main.cpp │ ├── MasterProblem.cpp │ ├── ProblemData.cpp │ ├── RandGen.cpp │ ├── RandGen.h │ └── SubProblem.cpp ├── README.md ├── TP0 └── TP0 │ ├── Main.cpp │ ├── TP0.vcxproj │ ├── TP0.vcxproj.filters │ ├── TP0.vcxproj.user │ └── TP0 │ ├── Main.cpp │ ├── TP0.vcxproj │ ├── TP0.vcxproj.filters │ └── TP0.vcxproj.user ├── TP1 └── TP1 │ ├── TP0.sln │ └── TP0 │ ├── Main.cpp │ ├── TP0.vcxproj │ ├── TP0.vcxproj.filters │ └── TP0.vcxproj.user ├── TP2 └── TP2 │ ├── TP0.sln │ └── TP0 │ ├── Main.cpp │ ├── ProblemData.cpp │ ├── RandGen.cpp │ ├── RandGen.h │ ├── TP0.vcxproj │ ├── TP0.vcxproj.filters │ ├── TP0.vcxproj.user │ └── TP_Data.h ├── TP3 └── TP3 │ ├── TP0.sln │ └── TP0 │ ├── Main.cpp │ ├── ProblemData.cpp │ ├── RandGen.cpp │ ├── RandGen.h │ ├── TP-150-160.txt │ ├── TP-50-60.txt │ ├── TP0.vcxproj │ ├── TP0.vcxproj.filters │ ├── TP0.vcxproj.user │ ├── TP_Data.h │ └── TP_Results.txt └── TP4 └── TP4 ├── TP0.sln ├── TP0 ├── Main.cpp ├── ProblemData.cpp ├── RandGen.cpp ├── RandGen.h ├── TP-150-160.txt ├── TP-50-60.txt ├── TP0.vcxproj ├── TP0.vcxproj.filters ├── TP0.vcxproj.user ├── TP_Data.h └── TP_Results.txt └── x64 └── Debug ├── Problems2Run.bat ├── TP0.exe └── TP_Results.txt /All Codes-Part 1 and 2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RahmanKhorramfar91/Cpp-Cplex-Tutorial/5c35d3ab2f8af0ffe92de0f1e4514daf956837cb/All Codes-Part 1 and 2.zip -------------------------------------------------------------------------------- /Cpp_Cplex_for_Optimization_Problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RahmanKhorramfar91/Cpp-Cplex-Tutorial/5c35d3ab2f8af0ffe92de0f1e4514daf956837cb/Cpp_Cplex_for_Optimization_Problems.pdf -------------------------------------------------------------------------------- /Cutting_Stock- Column Generation/Cutting_Stock.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Cutting_Stock", "Cutting_Stock\Cutting_Stock.vcxproj", "{F47D4D58-5130-4A1C-B272-10ED8FD91EB1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F47D4D58-5130-4A1C-B272-10ED8FD91EB1}.Debug|x64.ActiveCfg = Debug|x64 17 | {F47D4D58-5130-4A1C-B272-10ED8FD91EB1}.Debug|x64.Build.0 = Debug|x64 18 | {F47D4D58-5130-4A1C-B272-10ED8FD91EB1}.Debug|x86.ActiveCfg = Debug|Win32 19 | {F47D4D58-5130-4A1C-B272-10ED8FD91EB1}.Debug|x86.Build.0 = Debug|Win32 20 | {F47D4D58-5130-4A1C-B272-10ED8FD91EB1}.Release|x64.ActiveCfg = Release|x64 21 | {F47D4D58-5130-4A1C-B272-10ED8FD91EB1}.Release|x64.Build.0 = Release|x64 22 | {F47D4D58-5130-4A1C-B272-10ED8FD91EB1}.Release|x86.ActiveCfg = Release|Win32 23 | {F47D4D58-5130-4A1C-B272-10ED8FD91EB1}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {4A1A4169-B5B6-40E0-9414-D8107AD0964B} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Cutting_Stock- Column Generation/Cutting_Stock/Cutting_Stock.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | {F47D4D58-5130-4A1C-B272-10ED8FD91EB1} 24 | CuttingStock 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v142 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Level3 87 | true 88 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 89 | true 90 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 91 | MultiThreadedDLL 92 | 93 | 94 | Console 95 | true 96 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 104 | true 105 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 106 | MultiThreadedDLL 107 | 108 | 109 | Console 110 | true 111 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 112 | 113 | 114 | 115 | 116 | Level3 117 | true 118 | true 119 | true 120 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 121 | true 122 | 123 | 124 | Console 125 | true 126 | true 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | true 134 | true 135 | true 136 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 137 | true 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /Cutting_Stock- Column Generation/Cutting_Stock/Cutting_Stock.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | -------------------------------------------------------------------------------- /Cutting_Stock- Column Generation/Cutting_Stock/Cutting_Stock.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Cutting_Stock- Column Generation/Cutting_Stock/Functions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"ProblemData.h" 3 | double SubProblem(double* Dual_Vals, int* NewPattern); // a knapsack problem -------------------------------------------------------------------------------- /Cutting_Stock- Column Generation/Cutting_Stock/KnapsackProblem.cpp: -------------------------------------------------------------------------------- 1 | #include"Functions.h"; 2 | 3 | 4 | 5 | double SubProblem(double* Dual_Vals, int* NewPattern) 6 | { 7 | #pragma region Fetch Data 8 | int Log_Length = ProblemData::LL; 9 | int nLength = ProblemData::nL; 10 | int* Req_Length = ProblemData::ReqL; 11 | int* b = ProblemData::b; 12 | #pragma endregion 13 | 14 | IloEnv env; 15 | IloModel Model(env); 16 | 17 | IloNumVarArray newPat(env, nLength, 0, IloInfinity, ILOINT); 18 | 19 | IloExpr exp0(env); 20 | for (int i = 0; i < nLength; i++) 21 | { 22 | exp0 += Dual_Vals[i] * newPat[i]; 23 | } 24 | Model.add(IloMaximize(env, exp0)); 25 | 26 | IloExpr exp1(env); 27 | for (int i = 0; i < nLength; i++) 28 | { 29 | exp1 += Req_Length[i] * newPat[i]; 30 | } 31 | Model.add(exp1 <= Log_Length); 32 | IloCplex cplex(Model); 33 | cplex.setOut(env.getNullStream()); 34 | if (!cplex.solve()) { 35 | env.error() << "Failed to optimize the Master Problem!!!" << endl; 36 | throw(-1); 37 | } 38 | //NewPattern = new int[nLength](); 39 | std::cout << "\t New patttern generated: ["; 40 | for (int i = 0; i < nLength; i++) 41 | { 42 | NewPattern[i] = cplex.getValue(newPat[i]); 43 | std::cout << " " << NewPattern[i]; 44 | } 45 | std::cout << "]" << endl; 46 | double obj = cplex.getObjValue(); 47 | std::cout << "\n\t\t SP obj is: " << obj << endl; 48 | std::cout << "\n\n\n\n"; 49 | return obj; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /Cutting_Stock- Column Generation/Cutting_Stock/Main.cpp: -------------------------------------------------------------------------------- 1 | #include"ProblemData.h" 2 | #include"Functions.h"; 3 | 4 | 5 | int main() 6 | { 7 | #pragma region Fetch Data and Initialize the algorithm 8 | int Log_Length = ProblemData::LL; // total length of a log 9 | int* Req_Length = ProblemData::ReqL; // order lengths 10 | int nLength = ProblemData::nL; 11 | int* b = ProblemData::b; // demand 12 | 13 | // generate initial patterns 14 | vector Pattern; 15 | for (int i = 0; i < nLength; i++) 16 | { 17 | int* Pat0 = new int[nLength](); 18 | Pat0[i] = std::floor(Log_Length / Req_Length[i]); 19 | 20 | Pattern.push_back(Pat0); 21 | } 22 | 23 | 24 | 25 | // print initial patterns 26 | cout << "Initial patterns" << endl; 27 | for (int p = 0; p < Pattern.size(); p++) 28 | { 29 | cout << "Pattern " << p << " ["; 30 | for (int i = 0; i < nLength; i++) 31 | { 32 | cout << " " << Pattern[p][i]; 33 | } 34 | cout << "]" << endl; 35 | } 36 | 37 | #pragma endregion 38 | 39 | 40 | int iter_count = 0; 41 | 42 | while (true) 43 | { 44 | iter_count++; 45 | // Solve the restricted master problem (RMP) 46 | IloEnv env; IloModel Model(env); 47 | 48 | 49 | IloNumVarArray X(env, Pattern.size(), 0, IloInfinity, ILOFLOAT); 50 | IloRangeArray cons_set1(env); // name constraints to get the duals later 51 | 52 | // define the objective function 53 | IloExpr exp0(env); 54 | for (int p = 0; p < Pattern.size(); p++) { exp0 += X[p]; } 55 | 56 | Model.add(IloMinimize(env, exp0)); exp0.end(); 57 | 58 | // constraint 59 | for (int i = 0; i < nLength; i++) 60 | { 61 | IloExpr exp1(env); 62 | for (int p = 0; p < Pattern.size(); p++) 63 | { 64 | exp1 += Pattern[p][i] * X[p]; 65 | } 66 | cons_set1.add(exp1 >= b[i]); 67 | // Model.add(exp1 >= b[i]); 68 | } 69 | Model.add(cons_set1); 70 | 71 | IloCplex cplex(Model); 72 | cplex.setOut(env.getNullStream()); 73 | cplex.solve(); 74 | double obj = cplex.getObjValue(); 75 | std::cout << "\n\t Iteration: " << iter_count << "\t Required Number of logs: " << obj << endl; 76 | 77 | // get the dual variables 78 | double* Duals = new double[nLength](); 79 | for (int i = 0; i < nLength; i++) 80 | { 81 | Duals[i] = cplex.getDual(cons_set1[i]); 82 | //cout << Duals[i] << endl; 83 | } 84 | int jj = 0; 85 | // generate a new pattern from the subproblem (knapsack problem) 86 | int* NewPat = new int[nLength]; 87 | double SP_obj = SubProblem(Duals, NewPat); 88 | 89 | // check the optimality condition/ add the new pattern 90 | if (1 - SP_obj >= 0) { break; } 91 | else 92 | { 93 | Pattern.push_back(NewPat); 94 | } 95 | } 96 | 97 | 98 | 99 | 100 | cout << "Final patterns" << endl; 101 | for (int p = 0; p < Pattern.size(); p++) 102 | { 103 | cout << "Pattern " << p << " ["; 104 | for (int i = 0; i < nLength; i++) 105 | { 106 | cout << " " << Pattern[p][i]; 107 | } 108 | cout << "]" << endl; 109 | } 110 | return 0; 111 | } 112 | 113 | 114 | //Range2D Const2D(env, M); for 2-D dual variables 115 | //for (int i = 0; i < 5; i++) 116 | //{ 117 | // Const2D[i] = IloRangeArray(env,M); 118 | //} 119 | 120 | -------------------------------------------------------------------------------- /Cutting_Stock- Column Generation/Cutting_Stock/ProblemData.cpp: -------------------------------------------------------------------------------- 1 | #include"ProblemData.h" 2 | 3 | int ProblemData::LL = 40; 4 | int ProblemData::nL = 6; 5 | int* ProblemData::ReqL= new int[nL] { 4, 2, 6, 7, 8, 12 }; 6 | int* ProblemData::b = new int[nL] {20, 41, 23, 12, 9, 34}; 7 | -------------------------------------------------------------------------------- /Cutting_Stock- Column Generation/Cutting_Stock/ProblemData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include ; // for cout cin 3 | #include; // for random number generation 4 | #include ; // to read and write from/on files 5 | #include; // for high resolution timing (elapsed time in microseconds and so on) 6 | #include"ilcplex/ilocplex.h"; 7 | typedef IloArray NumVar2D; 8 | typedef IloArray< IloRangeArray> Range2D; 9 | typedef IloArray NumVar3D; 10 | using namespace std; 11 | 12 | 13 | class ProblemData 14 | { 15 | public: 16 | static int LL; 17 | static int nL; 18 | static int* ReqL; 19 | static int* b; 20 | 21 | 22 | static void PopulateParamts(); 23 | }; -------------------------------------------------------------------------------- /Cutting_Stock- Column Generation/Cutting_Stock/RandGen.cpp: -------------------------------------------------------------------------------- 1 | #include"RandGen.h" 2 | double RandLib::rand() 3 | { 4 | static std::uniform_real_distribution rand2(0, 1); 5 | return rand2(Gen); 6 | } 7 | int RandLib::randint(int a, int b) { 8 | //static std::uniform_int_distribution randint2(a, b); 9 | int ub = a + std::round((b - a) * rand()); 10 | return std::min(b, ub); 11 | } 12 | double RandLib::unifrnd(double a, double b) 13 | { 14 | //static std::uniform_real_distribution unifrnd(a, b); 15 | //return unifrnd(Gen); 16 | return a + (b - a) * rand(); 17 | } 18 | -------------------------------------------------------------------------------- /Cutting_Stock- Column Generation/Cutting_Stock/RandGen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include; 3 | 4 | 5 | class RandLib 6 | { 7 | public: 8 | int Seed; 9 | std::default_random_engine Gen; 10 | 11 | double rand(); // continuous uniform distribution in [0,1] 12 | int randint(int, int); // discrete uniform distribution in [a,b] 13 | double unifrnd(double, double); // continuous uniform distribution in [a,b] 14 | 15 | RandLib(int sd) 16 | { 17 | this->Seed = sd; 18 | this->Gen.seed(sd); 19 | } 20 | //static pcg_extras::seed_seq_from seed_source; 21 | RandLib() {}; 22 | ~RandLib() {}; 23 | private: 24 | }; -------------------------------------------------------------------------------- /FCTP-Benders Decomposition/FCTP.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FCTP", "FCTP\FCTP.vcxproj", "{3448E493-588D-4AEC-8167-47AF510DF51B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {3448E493-588D-4AEC-8167-47AF510DF51B}.Debug|x64.ActiveCfg = Debug|x64 17 | {3448E493-588D-4AEC-8167-47AF510DF51B}.Debug|x64.Build.0 = Debug|x64 18 | {3448E493-588D-4AEC-8167-47AF510DF51B}.Debug|x86.ActiveCfg = Debug|Win32 19 | {3448E493-588D-4AEC-8167-47AF510DF51B}.Debug|x86.Build.0 = Debug|Win32 20 | {3448E493-588D-4AEC-8167-47AF510DF51B}.Release|x64.ActiveCfg = Release|x64 21 | {3448E493-588D-4AEC-8167-47AF510DF51B}.Release|x64.Build.0 = Release|x64 22 | {3448E493-588D-4AEC-8167-47AF510DF51B}.Release|x86.ActiveCfg = Release|Win32 23 | {3448E493-588D-4AEC-8167-47AF510DF51B}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {E4BD2146-7DA7-4CC7-85F4-33A491376E4F} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /FCTP-Benders Decomposition/FCTP/CutClass.cpp: -------------------------------------------------------------------------------- 1 | #include"Data-Funcs-Classes.h" 2 | 3 | 4 | Cut::Cut(bool is_init) 5 | { 6 | add_optimality_cut = false; 7 | add_feasibility_cut = false; 8 | int nS = 4; 9 | int nD = 3; 10 | Us = new double[nS](); 11 | Vs = new double[nD](); 12 | Ws = new double* [nS]; 13 | for (int s = 0; s < nS; s++) 14 | { 15 | Ws[s] = new double[nD](); 16 | } 17 | 18 | Us_ray = new double[nS](); 19 | Vs_ray = new double[nD](); 20 | Ws_ray = new double* [nS]; 21 | for (int s = 0; s < nS; s++) 22 | { 23 | Ws_ray[s] = new double[nD](); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /FCTP-Benders Decomposition/FCTP/Data-Funcs-Classes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include ; // for cout cin 3 | #include; // for random number generation 4 | #include ; // to read and write from/on files 5 | #include; // for high resolution timing (elapsed time in microseconds and so on) 6 | #include"ilcplex/ilocplex.h"; 7 | #include"RandGen.h" 8 | using namespace std; 9 | typedef IloArray NumVar2D; 10 | 11 | class Cut 12 | { 13 | public: 14 | int nS; 15 | int nD; 16 | double* Us; 17 | double* Vs; 18 | double** Ws; 19 | 20 | double* Us_ray; 21 | double* Vs_ray; 22 | double** Ws_ray; 23 | Cut(bool is_initialize); 24 | 25 | bool add_optimality_cut; 26 | bool add_feasibility_cut; 27 | }; 28 | 29 | 30 | double SubProblem(int** Ys, vector& Cuts); 31 | 32 | double MasterProblem(int** Ys, vector Cuts); 33 | 34 | class ProblemData 35 | { 36 | public: 37 | static int nS; 38 | static int nD; 39 | static int seed; 40 | 41 | static int BigM; 42 | static int* D; 43 | static int* S; 44 | static int** C; 45 | static int** f; 46 | static void Populate_Parameters(RandLib RL); 47 | }; 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /FCTP-Benders Decomposition/FCTP/FCTP.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | {3448E493-588D-4AEC-8167-47AF510DF51B} 24 | FCTP 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v142 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Level3 87 | true 88 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 89 | true 90 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 91 | MultiThreadedDLL 92 | 93 | 94 | Console 95 | true 96 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 104 | true 105 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 106 | MultiThreadedDLL 107 | 108 | 109 | Console 110 | true 111 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 112 | 113 | 114 | 115 | 116 | Level3 117 | true 118 | true 119 | true 120 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 121 | true 122 | 123 | 124 | Console 125 | true 126 | true 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | true 134 | true 135 | true 136 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 137 | true 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /FCTP-Benders Decomposition/FCTP/FCTP.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | -------------------------------------------------------------------------------- /FCTP-Benders Decomposition/FCTP/FCTP.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /FCTP-Benders Decomposition/FCTP/Main.cpp: -------------------------------------------------------------------------------- 1 | #include"Data-Funcs-Classes.h" 2 | 3 | int main(int argc, char* argv[]) 4 | { 5 | 6 | #pragma region Set Problem Params 7 | // assume that the problem 8 | if (argc >= 2) 9 | { 10 | ProblemData::nS = atoi(argv[1]); 11 | ProblemData::nD = atoi(argv[2]); 12 | ProblemData::seed = atoi(argv[3]); 13 | } 14 | else 15 | { 16 | ProblemData::nS = 4; 17 | ProblemData::nD = 3; 18 | ProblemData::seed = 39; 19 | } 20 | #pragma endregion 21 | 22 | RandLib RL(ProblemData::seed); 23 | ProblemData::Populate_Parameters(RL); 24 | 25 | 26 | 27 | #pragma region Fetch Data 28 | int nS = ProblemData::nS; 29 | int nD = ProblemData::nD; 30 | int* S = ProblemData::S; 31 | int* D = ProblemData::D; 32 | int** C = ProblemData::C; 33 | int** F = ProblemData::f; 34 | int BigM = ProblemData::BigM; 35 | #pragma endregion 36 | 37 | #pragma region initialization (get a feasible solution) 38 | // create and initialize the y vairable 39 | int** Ys = new int* [nS]; 40 | for (int s = 0; s < nS; s++) 41 | { 42 | Ys[s] = new int[nD](); 43 | for (int d = 0; d < nD; d++) { Ys[s][d] = 1; } 44 | } 45 | 46 | // set bounds 47 | double UB = 10e6; 48 | double LB = -10e6; 49 | #pragma endregion 50 | 51 | #pragma region Main Loop 52 | 53 | vector Cuts; 54 | 55 | double SP_obj = 0; double MP_obj = 0; int iter_count = 0; 56 | 57 | while (std::abs(UB - LB) > 10e-3) 58 | { 59 | iter_count++; 60 | cout << "\n\n \t\t Iteration: " << iter_count << "\t UB: " << UB << "\t LB: " << LB << endl; 61 | 62 | 63 | // solve the subproblem 64 | SP_obj = SubProblem(Ys, Cuts); 65 | MP_obj = MasterProblem(Ys, Cuts); 66 | 67 | // update bounds 68 | UB = std::min(UB, SP_obj); 69 | LB = MP_obj; 70 | 71 | } 72 | #pragma endregion 73 | 74 | 75 | 76 | return 0; 77 | } -------------------------------------------------------------------------------- /FCTP-Benders Decomposition/FCTP/MasterProblem.cpp: -------------------------------------------------------------------------------- 1 | #include"Data-Funcs-Classes.h" 2 | 3 | 4 | double MasterProblem(int** Ys, vector Cuts) 5 | { 6 | 7 | #pragma region Fetch Data 8 | int nS = ProblemData::nS; 9 | int nD = ProblemData::nD; 10 | int* S = ProblemData::S; 11 | int* D = ProblemData::D; 12 | int** C = ProblemData::C; 13 | int** F = ProblemData::f; 14 | int BigM = ProblemData::BigM; 15 | #pragma endregion 16 | 17 | IloEnv env; 18 | IloModel Model(env); 19 | 20 | IloNumVar Z(env, -IloInfinity, IloInfinity, ILOFLOAT); 21 | NumVar2D Y(env, nS); 22 | for (int s = 0; s < nS; s++) 23 | { 24 | Y[s] = IloNumVarArray(env, nD, 0, 1, ILOBOOL); 25 | } 26 | 27 | Model.add(IloMinimize(env, Z)); 28 | 29 | // add the feasibility cuts 30 | int nCuts = Cuts.size(); 31 | for (int c = 0; c < nCuts; c++) 32 | { 33 | if (Cuts[c].add_optimality_cut) 34 | { 35 | IloExpr exp1(env); 36 | for (int s = 0; s < nS; s++) 37 | { 38 | exp1 += -S[s] * Cuts[c].Us[s]; 39 | for (int d = 0; d < nD; d++) 40 | { 41 | exp1 += F[s][d] * Y[s][d]; 42 | exp1 += -BigM * Cuts[c].Ws[s][d] * Y[s][d]; 43 | } 44 | } 45 | for (int d = 0; d < nD; d++) 46 | { 47 | exp1 += D[d] * Cuts[c].Vs[d]; 48 | } 49 | Model.add(Z >= exp1); 50 | exp1.end(); 51 | } 52 | } 53 | 54 | 55 | // add optimality cuts 56 | for (int c = 0; c < nCuts; c++) 57 | { 58 | if (Cuts[c].add_feasibility_cut) 59 | { 60 | IloExpr exp2(env); 61 | for (int s = 0; s < nS; s++) 62 | { 63 | exp2 += -S[s] * Cuts[c].Us_ray[s]; 64 | for (int d = 0; d < nD; d++) 65 | { 66 | exp2 += -BigM * Cuts[c].Ws_ray[s][d] * Y[s][d]; 67 | } 68 | } 69 | for (int d = 0; d < nD; d++) 70 | { 71 | exp2 += D[d] * Cuts[c].Vs_ray[d]; 72 | } 73 | Model.add(exp2 <= 0); 74 | exp2.end(); 75 | } 76 | } 77 | #pragma region Solve the problem 78 | IloCplex cplex(Model); 79 | //cplex.setParam(IloCplex::TiLim, EF_time); 80 | //cplex.setParam(IloCplex::EpGap, 0.60); 81 | cplex.setOut(env.getNullStream()); 82 | 83 | if (!cplex.solve()) { 84 | env.error() << "Failed to optimize the Master Problem!!!" << endl; 85 | throw(-1); 86 | } 87 | 88 | double obj = cplex.getObjValue(); 89 | std::cout << "\t MP obj value is: " << obj << endl; 90 | double gap = cplex.getMIPRelativeGap(); 91 | #pragma endregion 92 | 93 | for (int s = 0; s < nS; s++) 94 | { 95 | for (int d = 0; d < nD; d++) 96 | { 97 | Ys[s][d] = cplex.getValue(Y[s][d]); 98 | if (Ys[s][d] > 0.2) 99 | { 100 | //std::cout << "Y[" << s << "][" << d << "] = " << Ys[s][d] << endl; 101 | } 102 | } 103 | } 104 | 105 | return obj; 106 | } 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /FCTP-Benders Decomposition/FCTP/ProblemData.cpp: -------------------------------------------------------------------------------- 1 | #include"Data-Funcs-Classes.h" 2 | 3 | 4 | 5 | 6 | int ProblemData::nS; 7 | int ProblemData::nD; 8 | int ProblemData::seed; 9 | int ProblemData::BigM; 10 | int* ProblemData::D; 11 | int* ProblemData::S; 12 | int** ProblemData::C; 13 | int** ProblemData::f; 14 | 15 | void ProblemData::Populate_Parameters(RandLib RL) 16 | { 17 | D = new int[nD](); 18 | S = new int[nS]; 19 | C = new int* [nS](); 20 | f = new int* [nS](); 21 | int Dsum = 0; 22 | for (int d = 0; d < nD; d++) 23 | { 24 | D[d] = RL.randint(20, 150); 25 | Dsum += D[d]; 26 | } 27 | 28 | // Assumption: Supply ~= Demand 29 | int Ssum = 0; 30 | for (int s = 0; s < nS; s++) 31 | { 32 | S[s] = RL.randint(150, 190); 33 | Ssum += S[s]; 34 | } 35 | 36 | for (int s = 0; s < nS; s++) 37 | { 38 | S[s] = std::round((S[s] * Dsum) / Ssum) + 1; 39 | //cout << "S[" << s << "] = " << S[s] << endl; 40 | } 41 | 42 | for (int s = 0; s < nS; s++) 43 | { 44 | for (int d = 0; d < nD; d++) 45 | { 46 | BigM = std::max(D[d], S[s]); 47 | } 48 | } 49 | 50 | // populate C matrix 51 | for (int s = 0; s < nS; s++) 52 | { 53 | C[s] = new int[nD]; 54 | for (int d = 0; d < nD; d++) 55 | { 56 | C[s][d] = RL.randint(1,10); 57 | } 58 | } 59 | 60 | 61 | // populate f matrix 62 | for (int s = 0; s < nS; s++) 63 | { 64 | f[s] = new int[nD]; 65 | for (int d = 0; d < nD; d++) 66 | { 67 | f[s][d] = RL.randint(15,30); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /FCTP-Benders Decomposition/FCTP/RandGen.cpp: -------------------------------------------------------------------------------- 1 | #include"RandGen.h" 2 | double RandLib::rand() 3 | { 4 | static std::uniform_real_distribution rand2(0, 1); 5 | return rand2(Gen); 6 | } 7 | int RandLib::randint(int a, int b) { 8 | //static std::uniform_int_distribution randint2(a, b); 9 | int ub = a + std::round((b - a) * rand()); 10 | return std::min(b, ub); 11 | } 12 | double RandLib::unifrnd(double a, double b) 13 | { 14 | //static std::uniform_real_distribution unifrnd(a, b); 15 | //return unifrnd(Gen); 16 | return a + (b - a) * rand(); 17 | } 18 | -------------------------------------------------------------------------------- /FCTP-Benders Decomposition/FCTP/RandGen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include; 3 | 4 | 5 | class RandLib 6 | { 7 | public: 8 | int Seed; 9 | std::default_random_engine Gen; 10 | 11 | double rand(); // continuous uniform distribution in [0,1] 12 | int randint(int, int); // discrete uniform distribution in [a,b] 13 | double unifrnd(double, double); // continuous uniform distribution in [a,b] 14 | 15 | 16 | void Reseed(int); 17 | RandLib(int sd) 18 | { 19 | this->Seed = sd; 20 | this->Gen.seed(sd); 21 | } 22 | //static pcg_extras::seed_seq_from seed_source; 23 | RandLib() {}; 24 | ~RandLib() {}; 25 | private: 26 | }; -------------------------------------------------------------------------------- /FCTP-Benders Decomposition/FCTP/SubProblem.cpp: -------------------------------------------------------------------------------- 1 | #include"Data-Funcs-Classes.h" 2 | 3 | double SubProblem(int** Ys, vector& Cuts) 4 | { 5 | 6 | #pragma region Fetch Data 7 | int nS = ProblemData::nS; 8 | int nD = ProblemData::nD; 9 | int* S = ProblemData::S; 10 | int* D = ProblemData::D; 11 | int** C = ProblemData::C; 12 | int** F = ProblemData::f; 13 | int BigM = ProblemData::BigM; 14 | #pragma endregion 15 | 16 | #pragma region Create and solve the problem 17 | IloEnv env; 18 | IloModel Model(env); 19 | IloNumVarArray U(env, nS, 0, IloInfinity, ILOFLOAT); 20 | IloNumVarArray V(env, nD, 0, IloInfinity, ILOFLOAT); 21 | NumVar2D W(env, nS); 22 | for (int s = 0; s < nS; s++) 23 | { 24 | W[s] = IloNumVarArray(env, nD, 0, IloInfinity, ILOFLOAT); 25 | } 26 | 27 | 28 | // Objective function 29 | IloExpr exp0(env); 30 | for (int s = 0; s < nS; s++){ exp0 -= S[s] * U[s]; } 31 | for (int d = 0; d < nD; d++){ exp0 += D[d] * V[d]; } 32 | for (int s = 0; s < nS; s++) 33 | { 34 | for (int d = 0; d < nD; d++) 35 | { 36 | exp0 -= BigM* Ys[s][d] * W[s][d]; 37 | exp0 += F[s][d] * Ys[s][d]; 38 | } 39 | } 40 | Model.add(IloMaximize(env, exp0)); 41 | exp0.end(); 42 | 43 | // constraints 44 | for (int s = 0; s < nS; s++) 45 | { 46 | for (int d = 0; d < nD; d++) 47 | { 48 | Model.add(-U[s] + V[d] - W[s][d] <= C[s][d]); 49 | } 50 | } 51 | IloCplex cplex(Model); 52 | 53 | // turn off the presolve to distinguish between infeasibility and unboundedness 54 | cplex.setParam(IloCplex::Param::Preprocessing::Presolve, 0); 55 | //cplex.setParam(IloCplex::TiLim, EF_time); 56 | //cplex.setParam(IloCplex::EpGap, 0.60); 57 | cplex.setOut(env.getNullStream()); 58 | cplex.solve(); 59 | std::cout << "\t The Subproblem is: "; 60 | std::cout << cplex.getStatus() << endl; 61 | #pragma endregion 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 | // create and initialize a new cut 89 | Cut new_cut(true); 90 | 91 | #pragma region Get the extreme ray coefficients for the feasibility cut, if the problem is unbounded 92 | if (cplex.getStatus() == IloAlgorithm::Unbounded) 93 | { 94 | //std::cout << cplex.getStatus() << endl; 95 | new_cut.add_feasibility_cut = true; 96 | IloNumArray Vals(env); 97 | IloNumVarArray Vars(env); 98 | cplex.getRay(Vals, Vars); 99 | 100 | // find the index for U variable 101 | for (int h = 0; h < Vals.getSize(); h++) 102 | { 103 | for (int s = 0; s < nS; s++) 104 | { 105 | if (U[s].getId() == Vars[h].getId()) 106 | { 107 | new_cut.Us_ray[s] = Vals[h]; break; 108 | } 109 | } 110 | } 111 | 112 | // find the index for V variable 113 | for (int h = 0; h < Vals.getSize(); h++) 114 | { 115 | for (int d = 0; d < nD; d++) 116 | { 117 | if (V[d].getId() == Vars[h].getId()) 118 | { 119 | new_cut.Vs_ray[d] = Vals[h]; 120 | // std::cout << "Vs_ray: " << new_cut.Vs_ray[d] << endl; 121 | break; 122 | } 123 | } 124 | } 125 | 126 | // find the index for W variable 127 | for (int h = 0; h < Vals.getSize(); h++) 128 | { 129 | for (int s = 0; s < nS; s++) 130 | { 131 | for (int d = 0; d < nD; d++) 132 | { 133 | if (W[s][d].getId() == Vars[h].getId()) 134 | { 135 | new_cut.Ws_ray[s][d] = Vals[h]; 136 | // std::cout << "Ws_ray: " << new_cut.Ws_ray[s][d] << endl; 137 | break; 138 | } 139 | 140 | } 141 | } 142 | } 143 | 144 | //env.error() << "Failed to optimize the Master Problem!!!" << endl; 145 | Model.end(); 146 | 147 | // add the cut 148 | Cuts.push_back(new_cut); 149 | return INFINITY; // maximization problem is unbounded 150 | } 151 | #pragma endregion 152 | 153 | 154 | 155 | #pragma region Get the values for decision variables (duals) for the optimality cut 156 | new_cut.add_optimality_cut = true; 157 | double obj = cplex.getObjValue(); 158 | std::cout << "\t SP obj value is: " << obj << endl; 159 | double gap = cplex.getMIPRelativeGap(); 160 | 161 | 162 | for (int s = 0; s < nS; s++) 163 | { 164 | new_cut.Us[s] = cplex.getValue(U[s]); 165 | //std::cout << "Us: " << new_cut.Us[s] << endl; 166 | } 167 | 168 | for (int d = 0; d < nD; d++) 169 | { 170 | new_cut.Vs[d] = cplex.getValue(V[d]); 171 | //std::cout << "Vs: " << new_cut.Vs[d] << endl; 172 | } 173 | 174 | //new_cut.Ws = new double* [nS]; 175 | for (int s = 0; s < nS; s++) 176 | { 177 | //new_cut.Ws[s] = new double[nD](); 178 | for (int d = 0; d < nD; d++) 179 | { 180 | new_cut.Ws[s][d] = cplex.getValue(W[s][d]); 181 | if (new_cut.Ws[s][d] > 0.2) 182 | { 183 | //std::cout << "Ws[" << s << "][" << d << "] = " << new_cut.Ws[s][d] << endl; 184 | } 185 | } 186 | } 187 | #pragma endregion 188 | 189 | 190 | // add the cut 191 | Cuts.push_back(new_cut); 192 | Model.end(); 193 | return obj; 194 | } 195 | 196 | 197 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C++/Cplex-Tutorial 2 | 3 | The codes for the C++-Cplex-Tutorial given on the virtual session organized by ISE-GSA and Informs NCSU Student Chapter. 4 | The tutorial designed for any OR practitioner planning to start coding OR problems in C++ and solve by ILOG Cplex. 5 | 6 | Video of Part 1: https://www.youtube.com/watch?v=k_Z-F8nbXjU&t=0s&ab_channel=INFORMSNCSUStudentChapter 7 | 8 | Video of Part 2: https://www.youtube.com/watch?v=1pahj3lX9ms&t=2501s&ab_channel=INFORMSNCSUStudentChapter 9 | 10 | 11 | In the first part of the tutorial, I start with why C++ and Cplex and explain how to setup Cplex for C++ and Visual Studio. I then build and solve a simple problem (transportation problem). I develop several versions of this problem, each with an additional layer of automation. The last version allows the user to run a batch of instances from the command window. For each instance, a proper set of parameters is randomly generated, and the results is stored in a text file. 12 | 13 | 14 | The second part of the tutorial presented on March 11th where implementation of column generation and Bender's decomposition algorithms discussed for two problems. I picked two simple problem that are general enough for educational purposed and simple enough for our limited time. As such, a column generation algorithm is implemented for a cutting-stock problem and Bender's decomposition for a fixed cost transportation problem (FCTP). 15 | 16 | 17 | Comments and Suggestions are very much appreciated (rkhorra@ncsu.edu). 18 | -------------------------------------------------------------------------------- /TP0/TP0/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"ilcplex/ilocplex.h"; 3 | #include; 4 | 5 | 6 | using namespace std; 7 | typedef IloArray NumVar2D; // enables us to defien a 2-D decision varialbe 8 | typedef IloArray NumVar3D; 9 | 10 | 11 | int main() 12 | { 13 | auto start = chrono::high_resolution_clock::now(); 14 | 15 | #pragma region Problem Data 16 | int nS = 4; 17 | int nD = 3; 18 | 19 | int* S = new int[nS] {10, 30, 40, 20}; 20 | int* D = new int[nD] {20, 50, 30}; 21 | 22 | int** C = new int* [nS]; 23 | C[0] = new int[nD] {2, 3, 4}; 24 | C[1] = new int[nD] {3, 2, 1}; 25 | C[2] = new int[nD] {1, 4, 3}; 26 | C[3] = new int[nD] {4, 5, 2}; 27 | #pragma endregion 28 | 29 | IloEnv env; 30 | IloModel Model(env); 31 | 32 | #pragma region Define decision variable 33 | NumVar2D X(env, nS); 34 | 35 | for (int s = 0; s < nS; s++) 36 | { 37 | X[s] = IloNumVarArray(env, nD, 0, IloInfinity, ILOINT); 38 | } 39 | #pragma endregion 40 | 41 | #pragma region Objective Function 42 | 43 | IloExpr exp0(env); 44 | 45 | for (int s = 0; s < nS; s++) 46 | { 47 | for (int d = 0; d < nD; d++) 48 | { 49 | exp0 += C[s][d] * X[s][d]; 50 | } 51 | } 52 | 53 | Model.add(IloMinimize(env, exp0)); 54 | 55 | #pragma endregion 56 | 57 | 58 | #pragma region Constraints 59 | // the total outgoing shipment cannot exceed S[s] 60 | for (int s = 0; s < nS; s++) 61 | { 62 | IloExpr exp1(env); 63 | for (int d = 0; d < nD; d++) 64 | { 65 | exp1 += X[s][d]; 66 | } 67 | 68 | Model.add(exp1 <= S[s]); 69 | } 70 | 71 | 72 | for (int d = 0; d < nD; d++) 73 | { 74 | IloExpr exp2(env); 75 | for (int s = 0; s < nS; s++) 76 | { 77 | exp2 += X[s][d]; 78 | } 79 | 80 | Model.add(exp2 >= D[d]); 81 | } 82 | #pragma endregion 83 | 84 | 85 | 86 | IloCplex cplex(Model); 87 | cplex.setOut(env.getNullStream()); 88 | if (!cplex.solve()) { 89 | env.error() << "Failed to optimize the Master Problem!!!" << endl; 90 | throw(-1); 91 | } 92 | 93 | double obj = cplex.getObjValue(); 94 | 95 | auto end = chrono::high_resolution_clock::now(); 96 | auto Elapsed = chrono::duration_cast(end - start); 97 | cout << "\t Elapsed Time(ms): " << Elapsed.count() << endl; 98 | 99 | cout << "\n\n\t The objective value is: " << obj << endl; 100 | 101 | for (int s = 0; s < nS; s++) 102 | { 103 | for (int d = 0; d < nD; d++) 104 | { 105 | double Xval = cplex.getValue(X[s][d]); 106 | if (Xval > 0) 107 | { 108 | cout << "\t\t\t X[" << s << "][" << d << "] = " << Xval << endl; 109 | } 110 | 111 | } 112 | } 113 | 114 | 115 | } -------------------------------------------------------------------------------- /TP0/TP0/TP0.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5} 24 | TP0 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v142 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Level3 87 | true 88 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 89 | true 90 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 91 | MultiThreadedDLL 92 | 93 | 94 | Console 95 | true 96 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 104 | true 105 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 106 | MultiThreadedDLL 107 | 108 | 109 | Console 110 | true 111 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 112 | 113 | 114 | 115 | 116 | Level3 117 | true 118 | true 119 | true 120 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 121 | true 122 | 123 | 124 | Console 125 | true 126 | true 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | true 134 | true 135 | true 136 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 137 | true 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /TP0/TP0/TP0.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /TP0/TP0/TP0.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /TP0/TP0/TP0/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"ilcplex/ilocplex.h"; 3 | #include; 4 | 5 | 6 | using namespace std; 7 | typedef IloArray NumVar2D; // enables us to defien a 2-D decision varialbe 8 | typedef IloArray NumVar3D; 9 | 10 | 11 | int main() 12 | { 13 | auto start = chrono::high_resolution_clock::now(); 14 | 15 | #pragma region Problem Data 16 | int nS = 4; 17 | int nD = 3; 18 | 19 | int* S = new int[nS] {10, 30, 40, 20}; 20 | int* D = new int[nD] {20, 50, 30}; 21 | 22 | int** C = new int* [nS]; 23 | C[0] = new int[nD] {2, 3, 4}; 24 | C[1] = new int[nD] {3, 2, 1}; 25 | C[2] = new int[nD] {1, 4, 3}; 26 | C[3] = new int[nD] {4, 5, 2}; 27 | #pragma endregion 28 | 29 | IloEnv env; 30 | IloModel Model(env); 31 | 32 | #pragma region Define decision variable 33 | NumVar2D X(env, nS); 34 | 35 | for (int s = 0; s < nS; s++) 36 | { 37 | X[s] = IloNumVarArray(env, nD, 0, IloInfinity, ILOINT); 38 | } 39 | #pragma endregion 40 | 41 | #pragma region Objective Function 42 | 43 | IloExpr exp0(env); 44 | 45 | for (int s = 0; s < nS; s++) 46 | { 47 | for (int d = 0; d < nD; d++) 48 | { 49 | exp0 += C[s][d] * X[s][d]; 50 | } 51 | } 52 | 53 | Model.add(IloMinimize(env, exp0)); 54 | 55 | #pragma endregion 56 | 57 | 58 | #pragma region Constraints 59 | // the total outgoing shipment cannot exceed S[s] 60 | for (int s = 0; s < nS; s++) 61 | { 62 | IloExpr exp1(env); 63 | for (int d = 0; d < nD; d++) 64 | { 65 | exp1 += X[s][d]; 66 | } 67 | 68 | Model.add(exp1 <= S[s]); 69 | } 70 | 71 | 72 | for (int d = 0; d < nD; d++) 73 | { 74 | IloExpr exp2(env); 75 | for (int s = 0; s < nS; s++) 76 | { 77 | exp2 += X[s][d]; 78 | } 79 | 80 | Model.add(exp2 >= D[d]); 81 | } 82 | #pragma endregion 83 | 84 | 85 | 86 | IloCplex cplex(Model); 87 | cplex.setOut(env.getNullStream()); 88 | if (!cplex.solve()) { 89 | env.error() << "Failed to optimize the Master Problem!!!" << endl; 90 | throw(-1); 91 | } 92 | 93 | double obj = cplex.getObjValue(); 94 | 95 | auto end = chrono::high_resolution_clock::now(); 96 | auto Elapsed = chrono::duration_cast(end - start); 97 | cout << "\t Elapsed Time(ms): " << Elapsed.count() << endl; 98 | 99 | cout << "\n\n\t The objective value is: " << obj << endl; 100 | 101 | for (int s = 0; s < nS; s++) 102 | { 103 | for (int d = 0; d < nD; d++) 104 | { 105 | double Xval = cplex.getValue(X[s][d]); 106 | if (Xval > 0) 107 | { 108 | cout << "\t\t\t X[" << s << "][" << d << "] = " << Xval << endl; 109 | } 110 | 111 | } 112 | } 113 | 114 | 115 | } -------------------------------------------------------------------------------- /TP0/TP0/TP0/TP0.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5} 24 | TP0 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v142 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Level3 87 | true 88 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 89 | true 90 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 91 | MultiThreadedDLL 92 | 93 | 94 | Console 95 | true 96 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 104 | true 105 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 106 | MultiThreadedDLL 107 | 108 | 109 | Console 110 | true 111 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 112 | 113 | 114 | 115 | 116 | Level3 117 | true 118 | true 119 | true 120 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 121 | true 122 | 123 | 124 | Console 125 | true 126 | true 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | true 134 | true 135 | true 136 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 137 | true 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /TP0/TP0/TP0/TP0.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /TP0/TP0/TP0/TP0.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /TP1/TP1/TP0.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TP0", "TP0\TP0.vcxproj", "{C51B69D2-F22F-435E-BD61-E05A0A932BC5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x64.ActiveCfg = Debug|x64 17 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x64.Build.0 = Debug|x64 18 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x86.ActiveCfg = Debug|Win32 19 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x86.Build.0 = Debug|Win32 20 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x64.ActiveCfg = Release|x64 21 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x64.Build.0 = Release|x64 22 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x86.ActiveCfg = Release|Win32 23 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {30D5F504-5A55-4625-8D88-1E02EC4F6C7E} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /TP1/TP1/TP0/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"ilcplex/ilocplex.h"; 3 | #include; 4 | #include; 5 | using namespace std; 6 | typedef IloArray NumVar2D; // enables us to defien a 2-D decision varialbe 7 | typedef IloArray NumVar3D; 8 | 9 | class RandLib 10 | { 11 | public: 12 | int Seed; 13 | std::default_random_engine Gen; 14 | 15 | double rand(); // continuous uniform distribution in [0,1] 16 | int randint(int, int); // discrete uniform distribution in [a,b] 17 | double unifrnd(double, double); // continuous uniform distribution in [a,b] 18 | 19 | RandLib(int sd) 20 | { 21 | this->Seed = sd; 22 | this->Gen.seed(sd); 23 | } 24 | RandLib() {}; 25 | ~RandLib() {}; 26 | }; 27 | 28 | double RandLib::rand() 29 | { 30 | static std::uniform_real_distribution rand2(0, 1); 31 | return rand2(Gen); 32 | } 33 | 34 | int RandLib::randint(int a, int b) { 35 | //static std::uniform_int_distribution randint2(a, b); 36 | int ub = a + std::round((b - a) * rand()); 37 | return std::min(b, ub); 38 | } 39 | double RandLib::unifrnd(double a, double b) 40 | { 41 | //static std::uniform_real_distribution unifrnd(a, b); 42 | //return unifrnd(Gen); 43 | return a + (b - a) * rand(); 44 | } 45 | 46 | int main() 47 | { 48 | auto start = chrono::high_resolution_clock::now(); 49 | 50 | #pragma region Problem Data 51 | 52 | int nS = 100; 53 | int nD = 95; 54 | int seed = 24; 55 | // create and object of RandLib 56 | RandLib RL(seed); 57 | 58 | 59 | 60 | int* S = new int[nS]; 61 | int* D = new int[nD]; 62 | 63 | int** C = new int* [nS]; 64 | 65 | int Dsum = 0; 66 | for (int d = 0; d < nD; d++) 67 | { 68 | D[d] = RL.randint(20, 150); 69 | Dsum += D[d]; 70 | //cout <<"D["<(end - start); 168 | cout << "\t Elapsed Time(ms): " << Elapsed.count() << endl; 169 | 170 | cout << "\n\n\t The objective value is: " << obj << endl; 171 | 172 | /*for (int s = 0; s < nS; s++) 173 | { 174 | for (int d = 0; d < nD; d++) 175 | { 176 | double Xval = cplex.getValue(X[s][d]); 177 | if (Xval > 0) 178 | { 179 | cout << "\t\t\t X[" << s << "][" << d << "] = " << Xval << endl; 180 | } 181 | 182 | } 183 | }*/ 184 | 185 | 186 | } -------------------------------------------------------------------------------- /TP1/TP1/TP0/TP0.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5} 24 | TP0 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v142 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Level3 87 | true 88 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 89 | true 90 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 91 | MultiThreadedDLL 92 | 93 | 94 | Console 95 | true 96 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 104 | true 105 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 106 | MultiThreadedDLL 107 | 108 | 109 | Console 110 | true 111 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 112 | 113 | 114 | 115 | 116 | Level3 117 | true 118 | true 119 | true 120 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 121 | true 122 | 123 | 124 | Console 125 | true 126 | true 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | true 134 | true 135 | true 136 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 137 | true 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /TP1/TP1/TP0/TP0.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /TP1/TP1/TP0/TP0.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /TP2/TP2/TP0.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TP0", "TP0\TP0.vcxproj", "{C51B69D2-F22F-435E-BD61-E05A0A932BC5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x64.ActiveCfg = Debug|x64 17 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x64.Build.0 = Debug|x64 18 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x86.ActiveCfg = Debug|Win32 19 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x86.Build.0 = Debug|Win32 20 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x64.ActiveCfg = Release|x64 21 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x64.Build.0 = Release|x64 22 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x86.ActiveCfg = Release|Win32 23 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {30D5F504-5A55-4625-8D88-1E02EC4F6C7E} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /TP2/TP2/TP0/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"ilcplex/ilocplex.h"; 3 | #include; 4 | #include; 5 | #include"RandGen.h" 6 | #include"TP_Data.h" 7 | 8 | 9 | using namespace std; 10 | typedef IloArray NumVar2D; // enables us to defien a 2-D decision varialbe 11 | typedef IloArray NumVar3D; 12 | 13 | 14 | int main() 15 | { 16 | auto start = chrono::high_resolution_clock::now(); 17 | #pragma region Problem Setting 18 | ProblemData::nS = 50; 19 | ProblemData::nD = 60; 20 | 21 | ProblemData::seed = 39; 22 | RandLib RL(ProblemData::seed); 23 | ProblemData::Populate_Parameters(RL); 24 | #pragma endregion 25 | 26 | 27 | #pragma region Fetch Data 28 | int nS = ProblemData::nS; 29 | int nD = ProblemData::nD; 30 | int seed = 24; 31 | // create and object of RandLib 32 | int* S = ProblemData::S; 33 | int* D = ProblemData::D; 34 | int** C = ProblemData::C; 35 | #pragma endregion 36 | 37 | IloEnv env; 38 | IloModel Model(env); 39 | 40 | #pragma region Define decision variable 41 | NumVar2D X(env, nS); 42 | 43 | for (int s = 0; s < nS; s++) 44 | { 45 | X[s] = IloNumVarArray(env, nD, 0, IloInfinity, ILOINT); 46 | } 47 | #pragma endregion 48 | 49 | #pragma region Objective Function 50 | 51 | IloExpr exp0(env); 52 | 53 | for (int s = 0; s < nS; s++) 54 | { 55 | for (int d = 0; d < nD; d++) 56 | { 57 | exp0 += C[s][d] * X[s][d]; 58 | } 59 | } 60 | 61 | Model.add(IloMinimize(env, exp0)); 62 | 63 | #pragma endregion 64 | 65 | 66 | #pragma region Constraints 67 | // the total outgoing shipment cannot exceed S[s] 68 | for (int s = 0; s < nS; s++) 69 | { 70 | IloExpr exp1(env); 71 | for (int d = 0; d < nD; d++) 72 | { 73 | exp1 += X[s][d]; 74 | } 75 | 76 | Model.add(exp1 <= S[s]); 77 | } 78 | 79 | 80 | for (int d = 0; d < nD; d++) 81 | { 82 | IloExpr exp2(env); 83 | for (int s = 0; s < nS; s++) 84 | { 85 | exp2 += X[s][d]; 86 | } 87 | 88 | Model.add(exp2 >= D[d]); 89 | } 90 | #pragma endregion 91 | 92 | 93 | 94 | IloCplex cplex(Model); 95 | cplex.setOut(env.getNullStream()); 96 | if (!cplex.solve()) { 97 | env.error() << "Failed to optimize the Master Problem!!!" << endl; 98 | throw(-1); 99 | } 100 | 101 | double obj = cplex.getObjValue(); 102 | 103 | auto end = chrono::high_resolution_clock::now(); 104 | auto Elapsed = chrono::duration_cast(end - start); 105 | cout << "\t Elapsed Time(ms): " << Elapsed.count() << endl; 106 | 107 | cout << "\n\n\t The objective value is: " << obj << endl; 108 | 109 | /*for (int s = 0; s < nS; s++) 110 | { 111 | for (int d = 0; d < nD; d++) 112 | { 113 | double Xval = cplex.getValue(X[s][d]); 114 | if (Xval > 0) 115 | { 116 | cout << "\t\t\t X[" << s << "][" << d << "] = " << Xval << endl; 117 | } 118 | 119 | } 120 | }*/ 121 | 122 | 123 | } -------------------------------------------------------------------------------- /TP2/TP2/TP0/ProblemData.cpp: -------------------------------------------------------------------------------- 1 | // declare static fields in the cpp file 2 | #include"TP_Data.h" 3 | 4 | 5 | 6 | int ProblemData::nS; 7 | int ProblemData::nD; 8 | int ProblemData::seed; 9 | int* ProblemData::D; 10 | int* ProblemData::S; 11 | int** ProblemData::C; 12 | 13 | void ProblemData::Populate_Parameters(RandLib RL) 14 | { 15 | 16 | D = new int[nD](); 17 | S = new int[nS]; 18 | C = new int* [nS](); 19 | int Dsum = 0; 20 | for (int d = 0; d < nD; d++) 21 | { 22 | D[d] = RL.randint(20, 150); 23 | Dsum += D[d]; 24 | //cout << "D[" << d << "] = " << D[d] << endl; 25 | } 26 | 27 | // Assumption: Supply ~= Demand 28 | int Ssum = 0; 29 | for (int s = 0; s < nS; s++) 30 | { 31 | S[s] = RL.randint(150, 190); 32 | Ssum += S[s]; 33 | } 34 | int gg = 0; 35 | for (int s = 0; s < nS; s++) 36 | { 37 | S[s] = std::round((S[s] * Dsum) / Ssum) + 1; 38 | //cout << "S[" << s << "] = " << S[s] << endl; 39 | gg += S[s]; 40 | } 41 | 42 | // populate C matrix 43 | for (int s = 0; s < nS; s++) 44 | { 45 | C[s] = new int[nD]; 46 | for (int d = 0; d < nD; d++) 47 | { 48 | C[s][d] = RL.randint(5, 99); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /TP2/TP2/TP0/RandGen.cpp: -------------------------------------------------------------------------------- 1 | #include"RandGen.h" 2 | 3 | double RandLib::rand() 4 | { 5 | static std::uniform_real_distribution rand2(0, 1); 6 | return rand2(Gen); 7 | } 8 | int RandLib::randint(int a, int b) { 9 | //static std::uniform_int_distribution randint2(a, b); 10 | int ub = a + std::round((b - a) * rand()); 11 | return std::min(b, ub); 12 | } 13 | double RandLib::unifrnd(double a, double b) 14 | { 15 | //static std::uniform_real_distribution unifrnd(a, b); 16 | //return unifrnd(Gen); 17 | return a + (b - a) * rand(); 18 | } 19 | -------------------------------------------------------------------------------- /TP2/TP2/TP0/RandGen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include; 3 | 4 | class RandLib 5 | { 6 | public: 7 | int Seed; 8 | std::default_random_engine Gen; 9 | 10 | double rand(); // continuous uniform distribution in [0,1] 11 | int randint(int, int); // discrete uniform distribution in [a,b] 12 | double unifrnd(double, double); // continuous uniform distribution in [a,b] 13 | 14 | RandLib(int sd) 15 | { 16 | this->Seed = sd; 17 | this->Gen.seed(sd); 18 | } 19 | 20 | RandLib() {}; 21 | ~RandLib() {}; 22 | }; 23 | -------------------------------------------------------------------------------- /TP2/TP2/TP0/TP0.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5} 24 | TP0 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v142 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Level3 87 | true 88 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 89 | true 90 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 91 | MultiThreadedDLL 92 | 93 | 94 | Console 95 | true 96 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 104 | true 105 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 106 | MultiThreadedDLL 107 | 108 | 109 | Console 110 | true 111 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 112 | 113 | 114 | 115 | 116 | Level3 117 | true 118 | true 119 | true 120 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 121 | true 122 | 123 | 124 | Console 125 | true 126 | true 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | true 134 | true 135 | true 136 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 137 | true 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /TP2/TP2/TP0/TP0.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | -------------------------------------------------------------------------------- /TP2/TP2/TP0/TP0.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /TP2/TP2/TP0/TP_Data.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include"RandGen.h" 4 | 5 | 6 | 7 | class ProblemData 8 | { 9 | public: 10 | static int nS; 11 | static int nD; 12 | static int seed; 13 | 14 | static int* D; 15 | static int* S; 16 | static int** C; 17 | static void Populate_Parameters(RandLib RL); 18 | }; -------------------------------------------------------------------------------- /TP3/TP3/TP0.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TP0", "TP0\TP0.vcxproj", "{C51B69D2-F22F-435E-BD61-E05A0A932BC5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x64.ActiveCfg = Debug|x64 17 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x64.Build.0 = Debug|x64 18 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x86.ActiveCfg = Debug|Win32 19 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x86.Build.0 = Debug|Win32 20 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x64.ActiveCfg = Release|x64 21 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x64.Build.0 = Release|x64 22 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x86.ActiveCfg = Release|Win32 23 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {30D5F504-5A55-4625-8D88-1E02EC4F6C7E} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /TP3/TP3/TP0/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"ilcplex/ilocplex.h"; 3 | #include; 4 | #include; 5 | #include; 6 | #include"RandGen.h" 7 | #include"TP_Data.h" 8 | 9 | 10 | using namespace std; 11 | typedef IloArray NumVar2D; // enables us to defien a 2-D decision varialbe 12 | typedef IloArray NumVar3D; 13 | 14 | 15 | int main() 16 | { 17 | auto start = chrono::high_resolution_clock::now(); 18 | #pragma region Problem Setting 19 | ProblemData::nS = 17; 20 | ProblemData::nD = 10; 21 | 22 | ProblemData::seed = 39; 23 | RandLib RL(ProblemData::seed); 24 | ProblemData::Populate_Parameters(RL); 25 | #pragma endregion 26 | 27 | 28 | #pragma region Fetch Data 29 | int nS = ProblemData::nS; 30 | int nD = ProblemData::nD; 31 | int seed = 24; 32 | // create and object of RandLib 33 | int* S = ProblemData::S; 34 | int* D = ProblemData::D; 35 | int** C = ProblemData::C; 36 | #pragma endregion 37 | 38 | IloEnv env; 39 | IloModel Model(env); 40 | 41 | #pragma region Define decision variable 42 | NumVar2D X(env, nS); 43 | 44 | for (int s = 0; s < nS; s++) 45 | { 46 | X[s] = IloNumVarArray(env, nD, 0, IloInfinity, ILOINT); 47 | } 48 | #pragma endregion 49 | 50 | #pragma region Objective Function 51 | 52 | IloExpr exp0(env); 53 | 54 | for (int s = 0; s < nS; s++) 55 | { 56 | for (int d = 0; d < nD; d++) 57 | { 58 | exp0 += C[s][d] * X[s][d]; 59 | } 60 | } 61 | 62 | Model.add(IloMinimize(env, exp0)); 63 | 64 | #pragma endregion 65 | 66 | 67 | #pragma region Constraints 68 | // the total outgoing shipment cannot exceed S[s] 69 | for (int s = 0; s < nS; s++) 70 | { 71 | IloExpr exp1(env); 72 | for (int d = 0; d < nD; d++) 73 | { 74 | exp1 += X[s][d]; 75 | } 76 | 77 | Model.add(exp1 <= S[s]); 78 | } 79 | 80 | 81 | for (int d = 0; d < nD; d++) 82 | { 83 | IloExpr exp2(env); 84 | for (int s = 0; s < nS; s++) 85 | { 86 | exp2 += X[s][d]; 87 | } 88 | 89 | Model.add(exp2 >= D[d]); 90 | } 91 | #pragma endregion 92 | 93 | 94 | 95 | IloCplex cplex(Model); 96 | cplex.setOut(env.getNullStream()); 97 | if (!cplex.solve()) { 98 | env.error() << "Failed to optimize the Master Problem!!!" << endl; 99 | throw(-1); 100 | } 101 | 102 | double obj = cplex.getObjValue(); 103 | 104 | auto end = chrono::high_resolution_clock::now(); 105 | auto Elapsed = chrono::duration_cast(end - start); 106 | cout << "\t Elapsed Time(ms): " << Elapsed.count() << endl; 107 | 108 | cout << "\n\n\t The objective value is: " << obj << endl; 109 | 110 | 111 | #pragma region write on a text file 112 | //ofstream fid; 113 | //string FileName = "TP-" + std::to_string(nS) + "-" + std::to_string(nD) + ".txt"; 114 | 115 | //fid.open(FileName); 116 | //fid<< "\n\n\n\tProblem Size (nS x nD):" << nS << "x" << nD << endl; 117 | //fid << "\tCPU Time(sec): " << Elapsed.count() / 100 << endl; 118 | //fid << "\tObj Value: " << obj << endl; 119 | 120 | //// write X values... 121 | 122 | //fid.close(); 123 | 124 | ofstream fid2; 125 | fid2.open("TP_Results.txt", std::ios::app); 126 | fid2 << "\n\t" << nS; 127 | fid2 << "-" << nD; 128 | fid2 << "-" << ProblemData::seed; 129 | 130 | fid2 << "\t\t" << obj; 131 | fid2 << "\t" << Elapsed.count() / 100; 132 | 133 | fid2.close(); 134 | #pragma endregion 135 | 136 | 137 | /*for (int s = 0; s < nS; s++) 138 | { 139 | for (int d = 0; d < nD; d++) 140 | { 141 | double Xval = cplex.getValue(X[s][d]); 142 | if (Xval > 0) 143 | { 144 | cout << "\t\t\t X[" << s << "][" << d << "] = " << Xval << endl; 145 | } 146 | 147 | } 148 | }*/ 149 | 150 | 151 | } -------------------------------------------------------------------------------- /TP3/TP3/TP0/ProblemData.cpp: -------------------------------------------------------------------------------- 1 | // declare static fields in the cpp file 2 | #include"TP_Data.h" 3 | 4 | 5 | 6 | int ProblemData::nS; 7 | int ProblemData::nD; 8 | int ProblemData::seed; 9 | int* ProblemData::D; 10 | int* ProblemData::S; 11 | int** ProblemData::C; 12 | 13 | void ProblemData::Populate_Parameters(RandLib RL) 14 | { 15 | 16 | D = new int[nD](); 17 | S = new int[nS]; 18 | C = new int* [nS](); 19 | int Dsum = 0; 20 | for (int d = 0; d < nD; d++) 21 | { 22 | D[d] = RL.randint(20, 150); 23 | Dsum += D[d]; 24 | //cout << "D[" << d << "] = " << D[d] << endl; 25 | } 26 | 27 | // Assumption: Supply ~= Demand 28 | int Ssum = 0; 29 | for (int s = 0; s < nS; s++) 30 | { 31 | S[s] = RL.randint(150, 190); 32 | Ssum += S[s]; 33 | } 34 | int gg = 0; 35 | for (int s = 0; s < nS; s++) 36 | { 37 | S[s] = std::round((S[s] * Dsum) / Ssum) + 1; 38 | //cout << "S[" << s << "] = " << S[s] << endl; 39 | gg += S[s]; 40 | } 41 | 42 | // populate C matrix 43 | for (int s = 0; s < nS; s++) 44 | { 45 | C[s] = new int[nD]; 46 | for (int d = 0; d < nD; d++) 47 | { 48 | C[s][d] = RL.randint(5, 99); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /TP3/TP3/TP0/RandGen.cpp: -------------------------------------------------------------------------------- 1 | #include"RandGen.h" 2 | 3 | double RandLib::rand() 4 | { 5 | static std::uniform_real_distribution rand2(0, 1); 6 | return rand2(Gen); 7 | } 8 | int RandLib::randint(int a, int b) { 9 | //static std::uniform_int_distribution randint2(a, b); 10 | int ub = a + std::round((b - a) * rand()); 11 | return std::min(b, ub); 12 | } 13 | double RandLib::unifrnd(double a, double b) 14 | { 15 | //static std::uniform_real_distribution unifrnd(a, b); 16 | //return unifrnd(Gen); 17 | return a + (b - a) * rand(); 18 | } 19 | -------------------------------------------------------------------------------- /TP3/TP3/TP0/RandGen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include; 3 | 4 | class RandLib 5 | { 6 | public: 7 | int Seed; 8 | std::default_random_engine Gen; 9 | 10 | double rand(); // continuous uniform distribution in [0,1] 11 | int randint(int, int); // discrete uniform distribution in [a,b] 12 | double unifrnd(double, double); // continuous uniform distribution in [a,b] 13 | 14 | RandLib(int sd) 15 | { 16 | this->Seed = sd; 17 | this->Gen.seed(sd); 18 | } 19 | 20 | RandLib() {}; 21 | ~RandLib() {}; 22 | }; 23 | -------------------------------------------------------------------------------- /TP3/TP3/TP0/TP-150-160.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Problem Size (nS x nD):150x160 5 | CPU Time(sec): 2 6 | Obj Value: 78963 7 | -------------------------------------------------------------------------------- /TP3/TP3/TP0/TP-50-60.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Problem Size (nS x nD):50x60 5 | CPU Time(sec): 0 6 | Obj Value: 38906 7 | -------------------------------------------------------------------------------- /TP3/TP3/TP0/TP0.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5} 24 | TP0 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v142 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Level3 87 | true 88 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 89 | true 90 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 91 | MultiThreadedDLL 92 | 93 | 94 | Console 95 | true 96 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 104 | true 105 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 106 | MultiThreadedDLL 107 | 108 | 109 | Console 110 | true 111 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 112 | 113 | 114 | 115 | 116 | Level3 117 | true 118 | true 119 | true 120 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 121 | true 122 | 123 | 124 | Console 125 | true 126 | true 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | true 134 | true 135 | true 136 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 137 | true 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /TP3/TP3/TP0/TP0.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | -------------------------------------------------------------------------------- /TP3/TP3/TP0/TP0.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /TP3/TP3/TP0/TP_Data.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include"RandGen.h" 4 | 5 | 6 | 7 | class ProblemData 8 | { 9 | public: 10 | static int nS; 11 | static int nD; 12 | static int seed; 13 | 14 | static int* D; 15 | static int* S; 16 | static int** C; 17 | static void Populate_Parameters(RandLib RL); 18 | }; -------------------------------------------------------------------------------- /TP3/TP3/TP0/TP_Results.txt: -------------------------------------------------------------------------------- 1 | 2 | 150-160-39 78963 2 3 | 12-10-39 16295 0 4 | 17-10-39 20478 0 -------------------------------------------------------------------------------- /TP4/TP4/TP0.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TP0", "TP0\TP0.vcxproj", "{C51B69D2-F22F-435E-BD61-E05A0A932BC5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x64.ActiveCfg = Debug|x64 17 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x64.Build.0 = Debug|x64 18 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x86.ActiveCfg = Debug|Win32 19 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Debug|x86.Build.0 = Debug|Win32 20 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x64.ActiveCfg = Release|x64 21 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x64.Build.0 = Release|x64 22 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x86.ActiveCfg = Release|Win32 23 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {30D5F504-5A55-4625-8D88-1E02EC4F6C7E} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /TP4/TP4/TP0/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"ilcplex/ilocplex.h"; 3 | #include; 4 | #include; 5 | #include; 6 | #include"RandGen.h" 7 | #include"TP_Data.h" 8 | 9 | 10 | using namespace std; 11 | typedef IloArray NumVar2D; // enables us to defien a 2-D decision varialbe 12 | typedef IloArray NumVar3D; 13 | 14 | 15 | int main(int argc, char* argv[]) 16 | { 17 | auto start = chrono::high_resolution_clock::now(); 18 | 19 | if (argc >= 2) 20 | { 21 | ProblemData::nS = std::atoi(argv[1]); 22 | ProblemData::nD = atoi(argv[2]); 23 | ProblemData::seed = atoi(argv[3]); 24 | } 25 | else 26 | { 27 | ProblemData::nS = 17; 28 | ProblemData::nD = 10; 29 | ProblemData::seed = 39; 30 | } 31 | 32 | #pragma region Problem Setting 33 | 34 | RandLib RL(ProblemData::seed); 35 | ProblemData::Populate_Parameters(RL); 36 | #pragma endregion 37 | 38 | 39 | #pragma region Fetch Data 40 | int nS = ProblemData::nS; 41 | int nD = ProblemData::nD; 42 | int seed = 24; 43 | // create and object of RandLib 44 | int* S = ProblemData::S; 45 | int* D = ProblemData::D; 46 | int** C = ProblemData::C; 47 | #pragma endregion 48 | 49 | IloEnv env; 50 | IloModel Model(env); 51 | 52 | #pragma region Define decision variable 53 | NumVar2D X(env, nS); 54 | 55 | for (int s = 0; s < nS; s++) 56 | { 57 | X[s] = IloNumVarArray(env, nD, 0, IloInfinity, ILOINT); 58 | } 59 | #pragma endregion 60 | 61 | #pragma region Objective Function 62 | 63 | IloExpr exp0(env); 64 | 65 | for (int s = 0; s < nS; s++) 66 | { 67 | for (int d = 0; d < nD; d++) 68 | { 69 | exp0 += C[s][d] * X[s][d]; 70 | } 71 | } 72 | 73 | Model.add(IloMinimize(env, exp0)); 74 | 75 | #pragma endregion 76 | 77 | 78 | #pragma region Constraints 79 | // the total outgoing shipment cannot exceed S[s] 80 | for (int s = 0; s < nS; s++) 81 | { 82 | IloExpr exp1(env); 83 | for (int d = 0; d < nD; d++) 84 | { 85 | exp1 += X[s][d]; 86 | } 87 | 88 | Model.add(exp1 <= S[s]); 89 | } 90 | 91 | 92 | for (int d = 0; d < nD; d++) 93 | { 94 | IloExpr exp2(env); 95 | for (int s = 0; s < nS; s++) 96 | { 97 | exp2 += X[s][d]; 98 | } 99 | 100 | Model.add(exp2 >= D[d]); 101 | } 102 | #pragma endregion 103 | 104 | 105 | 106 | IloCplex cplex(Model); 107 | cplex.setOut(env.getNullStream()); 108 | if (!cplex.solve()) { 109 | env.error() << "Failed to optimize the Master Problem!!!" << endl; 110 | throw(-1); 111 | } 112 | 113 | double obj = cplex.getObjValue(); 114 | 115 | auto end = chrono::high_resolution_clock::now(); 116 | auto Elapsed = chrono::duration_cast(end - start); 117 | cout << "\t Elapsed Time(ms): " << Elapsed.count() << endl; 118 | 119 | cout << "\n\n\t The objective value is: " << obj << endl; 120 | 121 | 122 | #pragma region write on a text file 123 | //ofstream fid; 124 | //string FileName = "TP-" + std::to_string(nS) + "-" + std::to_string(nD) + ".txt"; 125 | 126 | //fid.open(FileName); 127 | //fid<< "\n\n\n\tProblem Size (nS x nD):" << nS << "x" << nD << endl; 128 | //fid << "\tCPU Time(sec): " << Elapsed.count() / 100 << endl; 129 | //fid << "\tObj Value: " << obj << endl; 130 | 131 | //// write X values... 132 | 133 | //fid.close(); 134 | 135 | ofstream fid2; 136 | fid2.open("TP_Results.txt", std::ios::app); 137 | fid2 << "\n\t" << nS; 138 | fid2 << "-" << nD; 139 | fid2 << "-" << ProblemData::seed; 140 | 141 | fid2 << "\t\t" << obj; 142 | fid2 << "\t" << Elapsed.count() / 100; 143 | 144 | fid2.close(); 145 | #pragma endregion 146 | 147 | 148 | /*for (int s = 0; s < nS; s++) 149 | { 150 | for (int d = 0; d < nD; d++) 151 | { 152 | double Xval = cplex.getValue(X[s][d]); 153 | if (Xval > 0) 154 | { 155 | cout << "\t\t\t X[" << s << "][" << d << "] = " << Xval << endl; 156 | } 157 | 158 | } 159 | }*/ 160 | 161 | 162 | } -------------------------------------------------------------------------------- /TP4/TP4/TP0/ProblemData.cpp: -------------------------------------------------------------------------------- 1 | // declare static fields in the cpp file 2 | #include"TP_Data.h" 3 | 4 | 5 | 6 | int ProblemData::nS; 7 | int ProblemData::nD; 8 | int ProblemData::seed; 9 | int* ProblemData::D; 10 | int* ProblemData::S; 11 | int** ProblemData::C; 12 | 13 | void ProblemData::Populate_Parameters(RandLib RL) 14 | { 15 | 16 | D = new int[nD](); 17 | S = new int[nS]; 18 | C = new int* [nS](); 19 | int Dsum = 0; 20 | for (int d = 0; d < nD; d++) 21 | { 22 | D[d] = RL.randint(20, 150); 23 | Dsum += D[d]; 24 | //cout << "D[" << d << "] = " << D[d] << endl; 25 | } 26 | 27 | // Assumption: Supply ~= Demand 28 | int Ssum = 0; 29 | for (int s = 0; s < nS; s++) 30 | { 31 | S[s] = RL.randint(150, 190); 32 | Ssum += S[s]; 33 | } 34 | int gg = 0; 35 | for (int s = 0; s < nS; s++) 36 | { 37 | S[s] = std::round((S[s] * Dsum) / Ssum) + 1; 38 | //cout << "S[" << s << "] = " << S[s] << endl; 39 | gg += S[s]; 40 | } 41 | 42 | // populate C matrix 43 | for (int s = 0; s < nS; s++) 44 | { 45 | C[s] = new int[nD]; 46 | for (int d = 0; d < nD; d++) 47 | { 48 | C[s][d] = RL.randint(5, 99); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /TP4/TP4/TP0/RandGen.cpp: -------------------------------------------------------------------------------- 1 | #include"RandGen.h" 2 | 3 | double RandLib::rand() 4 | { 5 | static std::uniform_real_distribution rand2(0, 1); 6 | return rand2(Gen); 7 | } 8 | int RandLib::randint(int a, int b) { 9 | //static std::uniform_int_distribution randint2(a, b); 10 | int ub = a + std::round((b - a) * rand()); 11 | return std::min(b, ub); 12 | } 13 | double RandLib::unifrnd(double a, double b) 14 | { 15 | //static std::uniform_real_distribution unifrnd(a, b); 16 | //return unifrnd(Gen); 17 | return a + (b - a) * rand(); 18 | } 19 | -------------------------------------------------------------------------------- /TP4/TP4/TP0/RandGen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include; 3 | 4 | class RandLib 5 | { 6 | public: 7 | int Seed; 8 | std::default_random_engine Gen; 9 | 10 | double rand(); // continuous uniform distribution in [0,1] 11 | int randint(int, int); // discrete uniform distribution in [a,b] 12 | double unifrnd(double, double); // continuous uniform distribution in [a,b] 13 | 14 | RandLib(int sd) 15 | { 16 | this->Seed = sd; 17 | this->Gen.seed(sd); 18 | } 19 | 20 | RandLib() {}; 21 | ~RandLib() {}; 22 | }; 23 | -------------------------------------------------------------------------------- /TP4/TP4/TP0/TP-150-160.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Problem Size (nS x nD):150x160 5 | CPU Time(sec): 2 6 | Obj Value: 78963 7 | -------------------------------------------------------------------------------- /TP4/TP4/TP0/TP-50-60.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Problem Size (nS x nD):50x60 5 | CPU Time(sec): 0 6 | Obj Value: 38906 7 | -------------------------------------------------------------------------------- /TP4/TP4/TP0/TP0.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | {C51B69D2-F22F-435E-BD61-E05A0A932BC5} 24 | TP0 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v142 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Level3 87 | true 88 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 89 | true 90 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 91 | MultiThreadedDLL 92 | 93 | 94 | Console 95 | true 96 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | NDEBUG;_CONSOLE;IL_STD;%(PreprocessorDefinitions) 104 | true 105 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\include;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\include;%(AdditionalIncludeDirectories) 106 | MultiThreadedDLL 107 | 108 | 109 | Console 110 | true 111 | C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\cplex1290.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\lib\x64_windows_vs2017\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio129\concert\lib\x64_windows_vs2017\stat_mda\concert.lib;%(AdditionalDependencies) 112 | 113 | 114 | 115 | 116 | Level3 117 | true 118 | true 119 | true 120 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 121 | true 122 | 123 | 124 | Console 125 | true 126 | true 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | true 134 | true 135 | true 136 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 137 | true 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /TP4/TP4/TP0/TP0.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | -------------------------------------------------------------------------------- /TP4/TP4/TP0/TP0.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /TP4/TP4/TP0/TP_Data.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include"RandGen.h" 4 | 5 | 6 | 7 | class ProblemData 8 | { 9 | public: 10 | static int nS; 11 | static int nD; 12 | static int seed; 13 | 14 | static int* D; 15 | static int* S; 16 | static int** C; 17 | static void Populate_Parameters(RandLib RL); 18 | }; -------------------------------------------------------------------------------- /TP4/TP4/TP0/TP_Results.txt: -------------------------------------------------------------------------------- 1 | 2 | 150-160-39 78963 2 3 | 12-10-39 16295 0 4 | 17-10-39 20478 0 5 | 17-10-39 20478 0 -------------------------------------------------------------------------------- /TP4/TP4/x64/Debug/Problems2Run.bat: -------------------------------------------------------------------------------- 1 | 2 | 3 | cd C:\Users\rkhorra\source\repos\Cpp-Cplex Examples\TP4\x64\Debug 4 | 5 | TP0.exe 25 30 15 6 | TP0.exe 25 30 389 7 | TP0.exe 25 30 194 8 | TP0.exe 25 30 984 9 | TP0.exe 25 30 715 10 | 11 | TP0.exe 50 30 15 12 | TP0.exe 50 30 389 13 | TP0.exe 50 30 194 14 | TP0.exe 50 30 984 15 | TP0.exe 50 30 715 16 | 17 | TP0.exe 25 50 15 18 | TP0.exe 25 50 389 19 | TP0.exe 25 50 194 20 | TP0.exe 25 50 984 21 | TP0.exe 25 50 715 22 | 23 | TP0.exe 50 50 15 24 | TP0.exe 50 50 389 25 | TP0.exe 50 50 194 26 | TP0.exe 50 50 984 27 | TP0.exe 50 50 715 28 | 29 | TP0.exe 550 300 15 30 | TP0.exe 550 300 389 31 | TP0.exe 550 300 194 32 | TP0.exe 550 300 984 33 | TP0.exe 550 300 715 34 | 35 | -------------------------------------------------------------------------------- /TP4/TP4/x64/Debug/TP0.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RahmanKhorramfar91/Cpp-Cplex-Tutorial/5c35d3ab2f8af0ffe92de0f1e4514daf956837cb/TP4/TP4/x64/Debug/TP0.exe -------------------------------------------------------------------------------- /TP4/TP4/x64/Debug/TP_Results.txt: -------------------------------------------------------------------------------- 1 | 2 | 25-30-15 29158 0 3 | 25-30-389 31064 0 4 | 25-30-194 27585 0 5 | 25-30-984 28148 0 6 | 25-30-715 23734 0 7 | 50-30-15 24529 0 8 | 50-30-389 27970 0 9 | 50-30-194 23951 0 10 | 50-30-984 26218 0 11 | 50-30-715 20650 0 12 | 25-50-15 41636 0 13 | 25-50-389 52014 0 14 | 25-50-194 46474 0 15 | 25-50-984 46097 0 16 | 25-50-715 44810 0 17 | 50-50-15 36004 0 18 | 50-50-389 40495 0 19 | 50-50-194 36703 0 20 | 50-50-984 36000 0 21 | 50-50-715 32824 0 22 | 550-300-15 138397 26 23 | 550-300-389 140516 24 24 | 550-300-194 136308 27 25 | 550-300-984 134735 25 26 | 550-300-715 135685 35 27 | --------------------------------------------------------------------------------