├── .gitattributes ├── .idea ├── .gitignore ├── .name ├── MicrogridOptimization.iml ├── inspectionProfiles │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── MultiMG ├── 0mg.png ├── 1mg.png ├── 2mg.png ├── Centralized │ ├── 0_output.csv │ ├── 1_output.csv │ ├── 2_output.csv │ ├── All_output.csv │ ├── EMS.cpp │ ├── EMS.h │ ├── ModelLP.lp │ ├── Source.cpp │ ├── centralized.sln │ ├── centralized.vcxproj │ ├── centralized.vcxproj.filters │ ├── centralized.vcxproj.user │ └── x64 │ │ └── Debug │ │ ├── Centralzied.exe │ │ ├── Centralzied.exe.recipe │ │ ├── Centralzied.ilk │ │ ├── Centralzied.pdb │ │ ├── Centralzied.tlog │ │ ├── CL.command.1.tlog │ │ ├── CL.read.1.tlog │ │ ├── CL.write.1.tlog │ │ ├── Centralzied.lastbuildstate │ │ ├── Cl.items.tlog │ │ ├── link.command.1.tlog │ │ ├── link.read.1.tlog │ │ └── link.write.1.tlog │ │ ├── EMS.obj │ │ ├── Source.obj │ │ ├── centralized.log │ │ ├── centralized.vcxproj.FileListAbsolute.txt │ │ ├── vc143.idb │ │ └── vc143.pdb ├── Decentralized │ ├── EMS.cpp │ ├── EMS.h │ ├── ModelLP.lp │ ├── Source.cpp │ ├── decentralizedMG.sln │ ├── decentralizedMG.vcxproj │ ├── decentralizedMG.vcxproj.filters │ ├── decentralizedMG.vcxproj.user │ ├── global_output.csv │ ├── mg1_output.csv │ ├── mg2_output.csv │ ├── mg3_output.csv │ └── x64 │ │ └── Debug │ │ ├── Decentralized.Build.CppClean.log │ │ ├── Decentralized.exe │ │ ├── Decentralized.exe.recipe │ │ ├── Decentralized.ilk │ │ ├── Decentralized.pdb │ │ ├── Decentralized.tlog │ │ ├── CL.command.1.tlog │ │ ├── CL.read.1.tlog │ │ ├── CL.write.1.tlog │ │ ├── Cl.items.tlog │ │ ├── Decentralized.lastbuildstate │ │ ├── link.command.1.tlog │ │ ├── link.read.1.tlog │ │ └── link.write.1.tlog │ │ ├── EMS.obj │ │ ├── Source.obj │ │ ├── decentralizedMG.log │ │ ├── decentralizedMG.vcxproj.FileListAbsolute.txt │ │ ├── vc143.idb │ │ └── vc143.pdb └── a.png ├── Plotting.ipynb ├── SingleMG ├── README.md ├── SingleMG_ElecHeatCoolNetAndEV │ ├── ModelLP.lp │ ├── SingleMG_ElecHeatCoolNetAndEV.sln │ ├── SingleMG_ElecHeatCoolNetAndEV.vcxproj │ ├── SingleMG_ElecHeatCoolNetAndEV.vcxproj.filters │ ├── SingleMG_ElecHeatCoolNetAndEV.vcxproj.user │ ├── Source.cpp │ ├── output.csv │ └── x64 │ │ └── Debug │ │ ├── SingleMG.92fc16a1.tlog │ │ ├── CL.command.1.tlog │ │ ├── CL.read.1.tlog │ │ ├── CL.write.1.tlog │ │ ├── Cl.items.tlog │ │ ├── SingleMG_ElectHeatCoolNetAndEv.lastbuildstate │ │ ├── link.command.1.tlog │ │ ├── link.read.1.tlog │ │ └── link.write.1.tlog │ │ ├── SingleMG_ElecHeatCoolNetAndEV.log │ │ ├── SingleMG_ElecHeatCoolNetAndEV.vcxproj.FileListAbsolute.txt │ │ ├── SingleMG_ElectHeatCoolNetAndEv.exe │ │ ├── SingleMG_ElectHeatCoolNetAndEv.exe.recipe │ │ ├── SingleMG_ElectHeatCoolNetAndEv.ilk │ │ ├── SingleMG_ElectHeatCoolNetAndEv.pdb │ │ ├── Source.obj │ │ ├── vc143.idb │ │ └── vc143.pdb ├── SingleMG_ElecHeatNetAndEV │ ├── ModelLP.lp │ ├── SingleMG_ElecHeatNetAndEV.sln │ ├── SingleMG_ElecHeatNetAndEV.vcxproj │ ├── SingleMG_ElecHeatNetAndEV.vcxproj.filters │ ├── SingleMG_ElecHeatNetAndEV.vcxproj.user │ ├── Source.cpp │ └── output.csv ├── SingleMG_ElectAndHeatNet │ ├── ModelLP.lp │ ├── SingleMG_ElectAndHeatNet.sln │ ├── SingleMG_ElectAndHeatNet.vcxproj │ ├── SingleMG_ElectAndHeatNet.vcxproj.filters │ ├── SingleMG_ElectAndHeatNet.vcxproj.user │ ├── Source.cpp │ └── output.csv └── SingleMG_ElectNet │ ├── ModelLP.lp │ ├── SingleMG_ElectNet.sln │ ├── SingleMG_ElectNet.vcxproj │ ├── SingleMG_ElectNet.vcxproj.filters │ ├── SingleMG_ElectNet.vcxproj.user │ ├── Source.cpp │ └── output.csv └── graphics └── SingleMG.PNG /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Source.cpp -------------------------------------------------------------------------------- /.idea/MicrogridOptimization.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /MultiMG/0mg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/0mg.png -------------------------------------------------------------------------------- /MultiMG/1mg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/1mg.png -------------------------------------------------------------------------------- /MultiMG/2mg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/2mg.png -------------------------------------------------------------------------------- /MultiMG/Centralized/0_output.csv: -------------------------------------------------------------------------------- 1 | Time,Pload+Pec,Hload+Hac,Cload,CGbuy,CGsell,CHsell,CHbuy,Rdg,PGshort/sur,statoc,Bchg/dischg,Pdg,Pchp,Hhob,Hchp,HGshort/sur,Hchg/dischg,MgSend/rec,Pevchg/dischg1,Pevchg/dischg2,Pevchg/dischg3,Pevchg/dischg4,Pevchg/dischg5 2 | 1,274.263,130,100,138,128,135,138,0,0,1,-126.316,100,140,80,136,0,0,160.579,0,0,0,0,0 3 | 2,280.263,125,100,139,129,135,138,0,0,1,-2.31913e-06,100,140,80,136,0,0,40.2632,0,0,0,0,0 4 | 3,263.211,120,80,143,133,135,138,0,0,1,0,180,140,80,136,0,0,-48.2784,-8.51111,0,0,0,0 5 | 4,276.263,120,100,149,139,135,138,0,0,1,0,133.789,140,80,136,-228,0,2.47368,0,0,0,0,0 6 | 5,307.316,125,120,150,140,135,138,0,99.4474,1,0,180,140,80,136,0,0,-96.2982,0,-15.8333,0,0,0 7 | 6,332.105,135,135,152,142,135,138,0,0,1,0,180,140,80,136,0,0,12.1053,0,0,0,0,0 8 | 7,270,326.471,150,155,145,135,138,0,0,1,0,180,140,80,136,389.647,0,-50,0,0,0,0,0 9 | 8,264,318.824,135,158,148,135,138,10,0,1,0,180,140,80,136,0,0,-66,0,0,0,0,0 10 | 9,404.579,175,125,160,150,144,149,15,7.66268,0.140351,122.5,180,140,80,136,0,0,-60.5837,0,0,0,0,0 11 | 10,417.842,190,130,154,144,144,149,20,0,0.140351,0,180,140,80,136,17,0,80.6066,0,0,-12.8444,10.08,0 12 | 11,447.368,195,140,153,143,144,149,23,0,0.140351,0,180,140,80,136,27.25,0,104.368,0,0,0,0,0 13 | 12,477.895,200,150,153,143,144,149,28,549.684,0.140351,0,180,140,80,136,4.49999,23.75,-419.789,0,0,0,0,0 14 | 13,437.895,195,150,152,142,144,149,33,394.684,0.140351,0,180,140,80,136,0,0,-309.789,0,0,0,0,0 15 | 14,396.842,195,130,150,140,144,149,35,0,0.140351,0,180,140,80,136,0,0,41.8421,0,0,0,0,0 16 | 15,376.316,180,120,149,139,144,149,34,0,0.140351,0,180,140,80,136,0,0,22.3158,0,0,0,0,0 17 | 16,315.789,170,110,149,139,144,149,31,0,0.140351,0,180,140,80,136,-53,0,-35.2105,0,0,0,0,0 18 | 17,274.737,185,90,154,144,144,149,28,0,0.140351,0,180,140,80,136,0,0,-67.4854,0,0,0,0,-5.77778 19 | 18,274.211,190,80,156,146,144,149,10,0,0.140351,0,180,140,80,136,0,0,-55.7895,0,0,0,0,0 20 | 19,240,353.824,135,163,153,140,140,0,0,0.140351,0,180,140,80,136,137.824,0,-80,0,0,0,0,0 21 | 20,280,376.471,150,164,154,140,140,0,0,0,20,180,140,80,136,160.471,0,-60,0,0,0,0,0 22 | 21,325,353.824,135,164,154,140,140,0,0,0,0,180,140,80,136,137.824,0,5,0,0,0,0,0 23 | 22,350,354.706,140,160,150,140,140,0,0,0,0,180,140,80,136,138.706,0,30,0,0,0,0,0 24 | 23,415.789,180,110,150,140,140,140,0,0,0,0,180,140,80,136,-36,0,95.7895,0,0,0,0,0 25 | 24,381.579,175,125,148,138,140,140,0,0,0,0,180,140,80,136,-41,0,61.5789,0,0,0,0,0 26 | -------------------------------------------------------------------------------- /MultiMG/Centralized/1_output.csv: -------------------------------------------------------------------------------- 1 | Time,Pload+Pec,Hload+Hac,Cload,CGbuy,CGsell,CHsell,CHbuy,Rdg,PGshort/sur,statoc,Bchg/dischg,Pdg,Pchp,Hhob,Hchp,HGshort/sur,Hchg/dischg,MgSend/rec,Pevchg/dischg1,Pevchg/dischg2,Pevchg/dischg3,Pevchg/dischg4,Pevchg/dischg5 2 | 1,189.263,65,100,138,128,135,138,0,565.737,1,-126.316,100,140,80,136,0,0,-490.158,0,0,0,0,0 3 | 2,192.263,62,100,139,129,135,138,0,0,1,-2.31913e-06,100,140,80,136,-211,0,-47.7368,0,0,0,0,0 4 | 3,173.211,60,80,143,133,135,138,0,0,1,0,124.165,140,80,136,-228,0,-82.4433,-8.51111,0,0,0,0 5 | 4,190.263,60,100,149,139,135,138,0,0,1,0,180,140,80,136,0,0,-129.737,0,0,0,0,0 6 | 5,216.316,62,120,150,140,135,138,0,0,1,0,180,140,80,136,0,0,-87.8509,0,-15.8333,0,0,0 7 | 6,237.105,67,135,152,142,135,138,0,0,1,0,180,140,80,136,0,0,-82.8947,0,0,0,0,0 8 | 7,150,234.706,150,155,145,135,138,0,0,1,0,180,140,80,136,0,0,-170,0,0,0,0,0 9 | 8,132,238.824,135,158,148,135,138,10,0,1,0,180,140,80,136,314.706,0,-198,0,0,0,0,0 10 | 9,267.579,87,125,160,150,144,149,15,0,0.252111,106.574,180,140,80,136,0,0,-173.995,0,0,0,0,0 11 | 10,276.842,95,130,154,144,144,149,20,381.82,0.252111,0,180,140,80,136,0,0,-442.213,0,0,-12.8444,10.08,0 12 | 11,297.368,97,140,153,143,144,149,23,463.105,0.252111,0,180,140,80,136,0,6.75001,-508.737,0,0,0,0,0 13 | 12,317.895,100,150,153,143,144,149,28,0,0.252111,0,180,140,80,136,0,0,-30.1053,0,0,0,0,0 14 | 13,297.895,97,150,152,142,144,149,33,0,0.252111,0,180,140,80,136,0,0,-55.1053,0,0,0,0,0 15 | 14,266.842,97,130,150,140,144,149,35,0,0.252111,0,180,140,80,136,0,0,-88.1579,0,0,0,0,0 16 | 15,251.316,90,120,149,139,144,149,34,191.947,0.252111,0,180,140,80,136,-18,0,-294.632,0,0,0,0,0 17 | 16,215.789,85,110,149,139,144,149,31,0,0.252111,0,180,140,80,136,0,0,-129.579,0,0,0,0,-5.63158 18 | 17,184.737,92,90,154,144,144,149,28,0,1,-118.088,180,140,80,136,0,0,-45.0292,0,0,0,0,-0.146199 19 | 18,179.211,95,80,156,146,144,149,10,-72.3684,1,0,180,140,80,136,0,17,-78.4211,0,0,0,0,0 20 | 19,240,121.706,135,163,153,140,140,0,0,1,0,180,140,80,136,-94.2941,0,-80,0,0,0,0,0 21 | 20,140,276.471,150,164,154,140,140,0,0,1,0,180,140,80,136,60.4706,0,-180,0,0,0,0,0 22 | 21,162,255.824,135,164,154,140,140,0,0,0,142.5,180,140,80,136,39.8235,0,-300.5,0,0,0,0,0 23 | 22,175,259.706,140,160,150,140,140,0,0,0,0,180,140,80,136,43.7059,0,-145,0,0,0,0,0 24 | 23,265.789,90,110,150,140,140,140,0,437.368,0,0,180,140,80,136,-126,0,-491.579,0,0,0,0,0 25 | 24,256.579,87,125,148,138,140,140,0,0,0,0,180,140,80,136,-129,0,-63.4211,0,0,0,0,0 26 | -------------------------------------------------------------------------------- /MultiMG/Centralized/2_output.csv: -------------------------------------------------------------------------------- 1 | Time,Pload+Pec,Hload+Hac,Cload,CGbuy,CGsell,CHsell,CHbuy,Rdg,PGshort/sur,statoc,Bchg/dischg,Pdg,Pchp,Hhob,Hchp,HGshort/sur,Hchg/dischg,MgSend/rec,Pevchg/dischg1,Pevchg/dischg2,Pevchg/dischg3,Pevchg/dischg4,Pevchg/dischg5 2 | 1,443.263,260,100,138,128,135,138,0,0,1,-126.316,100,140,80,136,-193,0,329.579,0,0,0,0,0 3 | 2,455.263,250,100,139,129,135,138,0,207.789,1,-2.31913e-06,100,140,80,136,0,0,7.47368,0,0,0,0,0 4 | 3,442.211,240,80,143,133,135,138,0,0,1,0,180,140,80,136,0,0,130.722,-8.51111,0,0,0,0 5 | 4,447.263,240,100,149,139,135,138,0,0,1,0,180,140,80,136,0,0,127.263,0,0,0,0,0 6 | 5,488.316,250,120,150,140,135,138,0,0,1,0,180,140,80,136,-211,0,184.149,0,-15.8333,0,0,0 7 | 6,390.789,416.765,135,152,142,135,138,0,0,1,0,180,140,80,136,-29.2353,0,70.7895,0,0,0,0,0 8 | 7,540,476.471,150,155,145,135,138,0,0,1,0,180,140,80,136,0,0,220,0,0,0,0,0 9 | 8,594,405.059,135,158,148,135,138,10,0,1,0,180,140,80,136,0,0,264,0,0,0,0,0 10 | 9,677.579,350,125,160,150,144,149,15,0,0.242105,108,180,140,80,136,-36,0,234.579,0,0,0,0,0 11 | 10,698.842,380,130,154,144,144,149,20,0,0.242105,0,180,140,80,136,0,0,361.607,0,0,-12.8444,10.08,0 12 | 11,747.368,390,140,153,143,144,149,23,0,0.242105,0,180,140,80,136,0,0,404.368,0,0,0,0,0 13 | 12,797.895,400,150,153,143,144,149,28,0,0.242105,0,180,140,80,136,0,23.75,449.895,0,0,0,0,0 14 | 13,717.895,390,150,152,142,144,149,33,0,0.242105,0,180,140,80,136,34,0,364.895,0,0,0,0,0 15 | 14,656.842,390,130,150,140,144,149,35,255.526,0.242105,0,180,140,80,136,34,0,46.3158,0,0,0,0,0 16 | 15,626.316,360,120,149,139,144,149,34,0,0.242105,0,180,140,80,136,0,0,272.316,0,0,0,0,0 17 | 16,515.789,340,110,149,139,144,149,31,0,0.242105,0,180,140,80,136,0,0,164.789,0,0,0,0,0 18 | 17,454.737,370,90,154,144,144,149,28,0,0.242105,0,180,140,80,136,-1.00001,0,112.515,0,0,0,0,-5.77778 19 | 18,464.211,380,80,156,146,144,149,10,0,0.242105,0,180,140,80,136,0,0,134.211,0,0,0,0,0 20 | 19,480,548.824,135,163,153,140,140,0,0,0.242105,0,180,140,80,136,332.824,0,160,0,0,0,0,0 21 | 20,560,576.471,150,164,154,140,140,0,0,0.242105,0,180,140,80,136,360.471,0,240,0,0,0,0,0 22 | 21,650,548.824,135,164,154,140,140,0,0,0,34.5,180,140,80,136,332.824,0,295.5,0,0,0,0,0 23 | 22,700,544.706,140,160,150,140,140,0,265,0,0,180,140,80,136,328.706,0,115,0,0,0,0,0 24 | 23,715.789,360,110,150,140,140,140,0,0,0,0,180,140,80,136,144,0,395.789,0,0,0,0,0 25 | 24,631.579,350,125,148,138,140,140,0,309.737,0,0,180,140,80,136,134,0,1.84211,0,0,0,0,0 26 | -------------------------------------------------------------------------------- /MultiMG/Centralized/All_output.csv: -------------------------------------------------------------------------------- 1 | Mg1Send/rec,mg1buy_sell,Mg2Send/rec,mg2buy_sell,Mg3Send/rec,mg3buy_sell 2 | 160.579,0,-490.158,565.737,329.579,0, 3 | 40.2632,0,-47.7368,0,7.47368,207.789, 4 | -48.2784,0,-82.4433,0,130.722,0, 5 | 2.47368,0,-129.737,0,127.263,0, 6 | -96.2982,99.4474,-87.8509,0,184.149,0, 7 | 12.1053,0,-82.8947,0,70.7895,0, 8 | -50,0,-170,0,220,0, 9 | -66,0,-198,0,264,0, 10 | -60.5837,7.66268,-173.995,0,234.579,0, 11 | 80.6066,0,-442.213,381.82,361.607,0, 12 | 104.368,0,-508.737,463.105,404.368,0, 13 | -419.789,549.684,-30.1053,0,449.895,0, 14 | -309.789,394.684,-55.1053,0,364.895,0, 15 | 41.8421,0,-88.1579,0,46.3158,255.526, 16 | 22.3158,0,-294.632,191.947,272.316,0, 17 | -35.2105,0,-129.579,0,164.789,0, 18 | -67.4854,0,-45.0292,0,112.515,0, 19 | -55.7895,0,-78.4211,-72.3684,134.211,0, 20 | -80,0,-80,0,160,0, 21 | -60,0,-180,0,240,0, 22 | 5,0,-300.5,0,295.5,0, 23 | 30,0,-145,0,115,265, 24 | 95.7895,0,-491.579,437.368,395.789,0, 25 | 61.5789,0,-63.4211,0,1.84211,309.737, 26 | -------------------------------------------------------------------------------- /MultiMG/Centralized/EMS.cpp: -------------------------------------------------------------------------------- 1 | #include"EMS.h" 2 | 3 | 4 | 5 | 6 | 7 | void EMS::MgOptimizationModel() { 8 | 9 | #pragma region Objective Function 10 | IloExpr objective(env_); 11 | 12 | 13 | for (int t = 0; t < T_; t++) 14 | { 15 | objective += intConstants_["Cdg1"] * Pdg1[t] + intConstants_["Cdg2"] * Pdg2[t] + CGbuy_[t] * PGbuy[t] - CGsell_[t] * PGsell[t] + CHbuy_[t] * HGbuy[t] - CHsell_[t] * HGsell[t] + intConstants_["Chob"] * Hhob[t] + intConstants_["Cchp1"] * Pchp1[t] + intConstants_["Cchp2"] * Pchp2[t]; 16 | } 17 | 18 | 19 | // Objective: minimize cost 20 | model_.add(IloMinimize(env_, objective)); 21 | 22 | #pragma endregion 23 | 24 | 25 | 26 | #pragma region Constraints 27 | 28 | 29 | // Constraint: meet demand 30 | 31 | for (int t = 0; t < T_; t++) 32 | { 33 | 34 | model_.add(0 <= Pdg1[t]); 35 | model_.add(Pdg1[t] <= 100); 36 | 37 | model_.add(0 <= Pdg2[t]); 38 | model_.add(Pdg2[t] <= 80); 39 | 40 | model_.add(0 <= Hhob[t]); 41 | model_.add(Hhob[t] <= 80); 42 | 43 | model_.add(30 <= Pchp1[t]); 44 | model_.add(Pchp1[t] <= 60); 45 | 46 | model_.add(50 <= Pchp2[t]); 47 | model_.add(Pchp2[t] <= 100); 48 | 49 | model_.add(Hchp1[t] == (floatConstants_["k1"]) * Pchp1[t]); 50 | model_.add(Hchp2[t] == (floatConstants_["k2"]) * Pchp2[t]); 51 | 52 | model_.add(0 <= HSSsoc[t]); 53 | model_.add(HSSsoc[t] <= 1); 54 | 55 | for (int n = 0; n < numEvs_; n++) 56 | { 57 | 58 | // soc bounds 59 | model_.add(0 <= evsoc[n][t]); 60 | model_.add(evsoc[n][t] <= 1); 61 | 62 | // Ev battery Constraints 63 | if (t == ta_[n]) 64 | { 65 | model_.add(evsoc[n][t] == evsocini_[n] + (floatConstants_["Eveffin"] * Pevchg[n][t] - Pevdischg[n][t] / floatConstants_["Eveffin"]) / evcap_[n]); 66 | model_.add(0 <= Pevchg[n][t]); 67 | model_.add(0 <= Pevdischg[n][t]); 68 | model_.add(Pevchg[n][t] <= (evcap_[n] * (1 - evsocini_[n]) / floatConstants_["Eveffin"])); 69 | model_.add(Pevdischg[n][t] <= (evcap_[n] * evsocini_[n] * floatConstants_["Eveffin"])); 70 | } 71 | else if (t > ta_[n] && t <= td_[n]) 72 | 73 | { 74 | model_.add(evsoc[n][t] == evsoc[n][t - 1] + ((floatConstants_["Eveffin"] * Pevchg[n][t] - (Pevdischg[n][t] / floatConstants_["Eveffin"])) / evcap_[n])); 75 | model_.add(0 <= Pevchg[n][t]); 76 | model_.add(0 <= Pevdischg[n][t]); 77 | model_.add(Pevchg[n][t] <= (evcap_[n] * (1 - evsoc[n][t - 1])) / floatConstants_["Eveffin"]); 78 | model_.add(Pevdischg[n][t] <= evcap_[n] * evsoc[n][t - 1] * floatConstants_["Eveffin"]); 79 | 80 | 81 | if (t == td_[n]) { model_.add(evsoc[n][t] >= 0.5); } 82 | 83 | } 84 | else 85 | { 86 | 87 | model_.add(Pevchg[n][t] == 0); 88 | model_.add(Pevdischg[n][t] == 0); 89 | 90 | } 91 | 92 | } 93 | 94 | 95 | // Adding the HSS and BSS Constraints constraints 96 | model_.add(0 <= statoc[t]); 97 | model_.add(statoc[t] <= 1); 98 | 99 | 100 | if (t == 0) 101 | { 102 | model_.add(statoc[t] == floatConstants_["socini"] + ((floatConstants_["effin"] * Bchg[t] - (Bdischg[t] / floatConstants_["effin"])) / intConstants_["Pbmax"])); 103 | model_.add(0 <= Bchg[t]); 104 | model_.add(0 <= Bdischg[t]); 105 | model_.add(Bchg[t] <= (intConstants_["Pbmax"] * (1 - floatConstants_["socini"]) / floatConstants_["effin"])); 106 | model_.add(Bdischg[t] <= (intConstants_["Pbmax"] * floatConstants_["socini"] * floatConstants_["effin"])); 107 | 108 | 109 | model_.add(HSSsoc[t] == 0.5 + ((floatConstants_["Heffin"] * Hchg[t] - (Hdischg[t] / floatConstants_["Heffin"])) / intConstants_["Hssmax"])); 110 | model_.add(0 <= Hchg[t]); 111 | model_.add(0 <= Hdischg[t]); 112 | //model_add(0 == Hdischg[t] * Hchg[t]); 113 | model_.add(Hchg[t] <= (intConstants_["Hssmax"] * (1 - 0.5) / floatConstants_["Heffin"])); 114 | model_.add(Hdischg[t] <= (intConstants_["Hssmax"] * 0.5 * floatConstants_["Heffin"])); 115 | 116 | } 117 | else 118 | { 119 | model_.add(statoc[t] == statoc[t - 1] + ((floatConstants_["effin"] * Bchg[t] - (Bdischg[t] / floatConstants_["effin"])) / intConstants_["Pbmax"])); 120 | model_.add(0 <= Bchg[t]); 121 | model_.add(0 <= Bdischg[t]); 122 | model_.add(Bchg[t] <= (intConstants_["Pbmax"] * (1 - statoc[t - 1])) / floatConstants_["effin"]); 123 | model_.add(Bdischg[t] <= intConstants_["Pbmax"] * statoc[t - 1] * floatConstants_["effin"]); 124 | 125 | 126 | model_.add(HSSsoc[t] == HSSsoc[t - 1] + ((floatConstants_["Heffin"] * Hchg[t] - (Hdischg[t] / floatConstants_["Heffin"])) / intConstants_["Hssmax"])); 127 | model_.add(0 <= Hchg[t]); 128 | model_.add(0 <= Hdischg[t]); 129 | //model_add(0 == Hdischg[t] * Hchg[t]); 130 | model_.add(Hchg[t] <= (intConstants_["Hssmax"] * (1 - HSSsoc[t - 1]) / floatConstants_["Heffin"])); 131 | model_.add(Hdischg[t] <= (intConstants_["Hssmax"] * HSSsoc[t - 1] * floatConstants_["Heffin"])); 132 | } 133 | 134 | 135 | // Preparing electric vehicles expression for the power balance equation 136 | IloExpr exp0(env_); 137 | IloExpr exp1(env_); 138 | for (int n = 0; n < numEvs_; n++) 139 | { 140 | exp0 += Pevchg[n][t]; 141 | exp1 += Pevdischg[n][t]; 142 | } 143 | 144 | // Adding the Electric power balance constraint 145 | 146 | model_.add(Pdg1[t] - Pec[t] + Pdg2[t] + Rdg1_[t] + Pchp1[t] + Pchp2[t] + Bdischg[t] + exp1 - exp0 - Bchg[t] + PGbuy[t] - PGsell[t] == Pload_[t]); 147 | 148 | model_.add(Hhob[t] - Hac[t] + Hchp1[t] + Hchp2[t] + HGbuy[t] - HGsell[t] - Hchg[t] + Hdischg[t] == Hload_[t]); 149 | 150 | model_.add(0.85 * Hac[t] + 0.95 * Pec[t] == Cload_[t]); 151 | 152 | } 153 | #pragma endregion 154 | 155 | 156 | } 157 | 158 | 159 | void EMS::save_result() { 160 | 161 | } 162 | 163 | resi EMS::solve() { 164 | 165 | MgOptimizationModel(); 166 | 167 | IloCplex cplex(env_); 168 | cplex.extract(model_); 169 | cplex.exportModel("ModelLP.lp"); 170 | cplex.setOut(env_.getNullStream()); 171 | cplex.solve(); 172 | obj = cplex.getObjValue(); 173 | cout << "Solution status: " << cplex.getStatus() << endl; 174 | cout << "Minimized Objective Funtion of "<< name_ << " is : " << obj << endl; 175 | 176 | 177 | int* pmgsur = new int[T_]; 178 | int* pmgshort = new int[T_]; 179 | int* Hmgsur = new int[T_]; 180 | int* Hmgshort = new int[T_]; 181 | 182 | for (int t = 0; t < T_; t++) 183 | { 184 | pmgsur[t] = cplex.getValue(PGsell[t]); 185 | pmgshort[t] = cplex.getValue(PGbuy[t]); 186 | 187 | Hmgsur[t] = cplex.getValue(HGsell[t]); 188 | Hmgshort[t] = cplex.getValue(HGbuy[t]); 189 | } 190 | 191 | 192 | resi results; 193 | results.pmgsur = pmgsur; 194 | results.pmgshort = pmgshort; 195 | results.Hmgsur = Hmgsur; 196 | results.Hmgshort = Hmgshort; 197 | 198 | IloNum eps = cplex.getParam( 199 | IloCplex::Param::MIP::Tolerances::Integrality); 200 | 201 | 202 | return results; 203 | 204 | } 205 | 206 | 207 | -------------------------------------------------------------------------------- /MultiMG/Centralized/EMS.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | typedef IloArray NumVar2D; 10 | 11 | 12 | struct resi { 13 | int* pmgsur; 14 | int* pmgshort; 15 | int* Hmgsur; 16 | int* Hmgshort; 17 | }; 18 | 19 | 20 | class EMS { 21 | 22 | public: 23 | void MgOptimizationModel(); 24 | void save_result(); 25 | resi solve(); 26 | double obj; 27 | 28 | IloNumVarArray PGbuy; 29 | IloNumVarArray PGsell; 30 | IloNumVarArray HGbuy; 31 | IloNumVarArray HGsell; 32 | 33 | 34 | EMS(string name,int T, int numEvs, const std::map& intConstants, const std::map& floatConstants, int* ta, int* td, float* evsocini, float* evcap, int* Pload, int* Hload, int* Cload, int* CGbuy, int* CGsell, int* CHbuy, int* CHsell, float* Rdg1) 35 | :name_(name), T_(T), numEvs_(numEvs), intConstants_(intConstants), floatConstants_(floatConstants), ta_(ta), td_(td), evsocini_(evsocini), evcap_(evcap), Pload_(Pload), Hload_(Hload), Cload_(Cload), CGbuy_(CGbuy), CGsell_(CGsell), CHbuy_(CHbuy), CHsell_(CHsell), Rdg1_(Rdg1) { 36 | 37 | env_ = IloEnv(); 38 | model_ = IloModel(env_); 39 | 40 | InitializeVariables(); 41 | } 42 | 43 | ~EMS() { 44 | env_.end(); 45 | } 46 | 47 | 48 | private: 49 | IloEnv env_; 50 | IloModel model_; 51 | string name_; 52 | int T_; 53 | int numEvs_; 54 | std::map intConstants_; 55 | std::map floatConstants_; 56 | int* ta_; 57 | int* td_; 58 | float* evsocini_; 59 | float* evcap_; 60 | int* Pload_; 61 | int* Hload_; 62 | int* Cload_; 63 | int* CGbuy_; 64 | int* CGsell_; 65 | int* CHbuy_; 66 | int* CHsell_; 67 | float* Rdg1_; 68 | 69 | IloNumVarArray statoc; 70 | IloNumVarArray Bchg; 71 | IloNumVarArray Bdischg; 72 | IloNumVarArray HSSsoc; 73 | IloNumVarArray Hchg; 74 | IloNumVarArray Hdischg; 75 | IloNumVarArray Pdg1; 76 | IloNumVarArray Pdg2; 77 | IloNumVarArray Pchp1; 78 | IloNumVarArray Pchp2; 79 | IloNumVarArray Hhob; 80 | IloNumVarArray Hchp1; 81 | IloNumVarArray Hchp2; 82 | IloNumVarArray Hac; 83 | IloNumVarArray Pec; 84 | 85 | // Electric Vehicles Decision Variables 86 | NumVar2D Pevchg; 87 | NumVar2D Pevdischg; 88 | NumVar2D evsoc; 89 | 90 | void InitializeVariables() { 91 | // Initialize decision variables 92 | PGbuy = IloNumVarArray(env_, T_, 0, IloInfinity, ILOINT);//Grid power bought 93 | PGsell = IloNumVarArray(env_, T_, 0, IloInfinity, ILOINT);//Grid power sold 94 | HGbuy = IloNumVarArray(env_, T_, 0, IloInfinity, ILOINT);//Grid Heat bought 95 | HGsell = IloNumVarArray(env_, T_, 0, IloInfinity, ILOINT);//Grid Heat sold 96 | statoc = IloNumVarArray(env_, T_, 0, 1); //battery storage capacity 97 | Bchg = IloNumVarArray(env_, T_, 0, 100); //battery charging 98 | Bdischg = IloNumVarArray(env_, T_, 0, 100); //battery discharging 99 | HSSsoc = IloNumVarArray(env_, T_, 0, 1); //battery storage capacity 100 | Hchg = IloNumVarArray(env_, T_, 0, 50, ILOINT); //battery charging 101 | Hdischg = IloNumVarArray(env_, T_, 0, 50, ILOINT); //battery discharging 102 | Pdg1 = IloNumVarArray(env_, T_, 0, 100, ILOINT); //DGA power generation range 103 | Pdg2 = IloNumVarArray(env_, T_, 0, 80, ILOINT); //DGA power generation range 104 | Pchp1 = IloNumVarArray(env_, T_, 30, 60, ILOINT); //CHP1 power generation range 105 | Pchp2 = IloNumVarArray(env_, T_, 50, 100, ILOINT); //CHP2 power generation range 106 | Hhob = IloNumVarArray(env_, T_, 0, 80, ILOINT); //HOB heat power generation range 107 | Hchp1 = IloNumVarArray(env_, T_, 0, IloInfinity); //CHP1 heat power generation range 108 | Hchp2 = IloNumVarArray(env_, T_, 0, IloInfinity); //CHP2 heat generation range 109 | Hac = IloNumVarArray(env_, T_, 0, IloInfinity); // AC 110 | Pec = IloNumVarArray(env_, T_, 0, IloInfinity); // Electric Chiller 111 | 112 | // Electric Vehicles Decision Variables 113 | Pevchg = NumVar2D(env_, numEvs_); 114 | Pevdischg = NumVar2D(env_, numEvs_); 115 | evsoc = NumVar2D(env_, numEvs_); 116 | 117 | for (int n = 0; n < numEvs_; n++) { 118 | Pevchg[n] = IloNumVarArray(env_, T_, 0, evcap_[n], ILOFLOAT); 119 | Pevdischg[n] = IloNumVarArray(env_, T_, 0, evcap_[n], ILOFLOAT); 120 | evsoc[n] = IloNumVarArray(env_, T_, 0, 1, ILOFLOAT); 121 | } 122 | } 123 | 124 | }; -------------------------------------------------------------------------------- /MultiMG/Centralized/centralized.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34024.191 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "Project1.vcxproj", "{92FC16A1-661B-40D1-833F-FA53A83C04DF}" 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 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x64.ActiveCfg = Debug|x64 17 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x64.Build.0 = Debug|x64 18 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x86.ActiveCfg = Debug|Win32 19 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x86.Build.0 = Debug|Win32 20 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x64.ActiveCfg = Release|x64 21 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x64.Build.0 = Release|x64 22 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x86.ActiveCfg = Release|Win32 23 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {89DA0DA7-D26C-4CE9-B98A-A7D76BE1D820} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /MultiMG/Centralized/centralized.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 | 17.0 23 | Win32Proj 24 | {92fc16a1-661b-40d1-833f-fa53a83c04df} 25 | Project1 26 | 10.0 27 | Centralzied 28 | 29 | 30 | 31 | Application 32 | true 33 | v143 34 | Unicode 35 | 36 | 37 | Application 38 | false 39 | v143 40 | true 41 | Unicode 42 | 43 | 44 | Application 45 | true 46 | v143 47 | Unicode 48 | 49 | 50 | Application 51 | false 52 | v143 53 | true 54 | Unicode 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Level3 77 | true 78 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 79 | true 80 | 81 | 82 | Console 83 | true 84 | 85 | 86 | 87 | 88 | Level3 89 | true 90 | true 91 | true 92 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | true 99 | true 100 | 101 | 102 | 103 | 104 | Level3 105 | true 106 | WIN64;_CONSOLE;IL_STD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 107 | true 108 | C:\Program Files\IBM\ILOG\CPLEX_Studio221\concert\include;C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\include;%(AdditionalIncludeDirectories) 109 | MultiThreadedDLL 110 | 111 | 112 | Console 113 | true 114 | C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\lib\x64_windows_msvc14\stat_mda\cplex2210.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\lib\x64_windows_msvc14\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio221\concert\lib\x64_windows_msvc14\stat_mda\concert.lib;%(AdditionalDependencies) 115 | 116 | 117 | 118 | 119 | Level3 120 | true 121 | true 122 | true 123 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 124 | true 125 | 126 | 127 | Console 128 | true 129 | true 130 | true 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /MultiMG/Centralized/centralized.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;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 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /MultiMG/Centralized/centralized.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Centralzied.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/Centralzied.exe -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Centralzied.exe.recipe: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\x64\Debug\Centralzied.exe 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Centralzied.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/Centralzied.ilk -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Centralzied.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/Centralzied.pdb -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Centralzied.tlog/CL.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/Centralzied.tlog/CL.command.1.tlog -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Centralzied.tlog/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/Centralzied.tlog/CL.read.1.tlog -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Centralzied.tlog/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/Centralzied.tlog/CL.write.1.tlog -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Centralzied.tlog/Centralzied.lastbuildstate: -------------------------------------------------------------------------------- 1 | PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.37.32822:TargetPlatformVersion=10.0.22621.0: 2 | Debug|x64|D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\| 3 | -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Centralzied.tlog/Cl.items.tlog: -------------------------------------------------------------------------------- 1 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp;D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\x64\Debug\Source.obj 2 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\EMS.cpp;D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\x64\Debug\EMS.obj 3 | -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Centralzied.tlog/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/Centralzied.tlog/link.command.1.tlog -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Centralzied.tlog/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/Centralzied.tlog/link.read.1.tlog -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Centralzied.tlog/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/Centralzied.tlog/link.write.1.tlog -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/EMS.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/EMS.obj -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/Source.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/Source.obj -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/centralized.log: -------------------------------------------------------------------------------- 1 |  Source.cpp 2 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(35,35): warning C4305: 'initializing': truncation from 'double' to 'float' 3 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(35,40): warning C4305: 'initializing': truncation from 'double' to 'float' 4 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(35,76): warning C4305: 'initializing': truncation from 'double' to 'float' 5 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(35,81): warning C4305: 'initializing': truncation from 'double' to 'float' 6 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(35,117): warning C4305: 'initializing': truncation from 'double' to 'float' 7 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(35,122): warning C4305: 'initializing': truncation from 'double' to 'float' 8 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(42,39): warning C4305: 'initializing': truncation from 'double' to 'float' 9 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(42,44): warning C4305: 'initializing': truncation from 'double' to 'float' 10 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(42,49): warning C4305: 'initializing': truncation from 'double' to 'float' 11 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(45,38): warning C4305: 'initializing': truncation from 'double' to 'float' 12 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(45,44): warning C4305: 'initializing': truncation from 'double' to 'float' 13 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(45,50): warning C4305: 'initializing': truncation from 'double' to 'float' 14 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(45,56): warning C4305: 'initializing': truncation from 'double' to 'float' 15 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(45,62): warning C4305: 'initializing': truncation from 'double' to 'float' 16 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(46,38): warning C4305: 'initializing': truncation from 'double' to 'float' 17 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(46,44): warning C4305: 'initializing': truncation from 'double' to 'float' 18 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(46,50): warning C4305: 'initializing': truncation from 'double' to 'float' 19 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(46,56): warning C4305: 'initializing': truncation from 'double' to 'float' 20 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(46,62): warning C4305: 'initializing': truncation from 'double' to 'float' 21 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(47,38): warning C4305: 'initializing': truncation from 'double' to 'float' 22 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(47,44): warning C4305: 'initializing': truncation from 'double' to 'float' 23 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(47,50): warning C4305: 'initializing': truncation from 'double' to 'float' 24 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(47,56): warning C4305: 'initializing': truncation from 'double' to 'float' 25 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(47,62): warning C4305: 'initializing': truncation from 'double' to 'float' 26 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(58,38): warning C4305: 'initializing': truncation from 'double' to 'float' 27 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(58,44): warning C4305: 'initializing': truncation from 'double' to 'float' 28 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(58,50): warning C4305: 'initializing': truncation from 'double' to 'float' 29 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(58,56): warning C4305: 'initializing': truncation from 'double' to 'float' 30 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(58,62): warning C4305: 'initializing': truncation from 'double' to 'float' 31 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(59,38): warning C4305: 'initializing': truncation from 'double' to 'float' 32 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(59,44): warning C4305: 'initializing': truncation from 'double' to 'float' 33 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(59,50): warning C4305: 'initializing': truncation from 'double' to 'float' 34 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(59,56): warning C4305: 'initializing': truncation from 'double' to 'float' 35 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(59,62): warning C4305: 'initializing': truncation from 'double' to 'float' 36 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(60,38): warning C4305: 'initializing': truncation from 'double' to 'float' 37 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(60,44): warning C4305: 'initializing': truncation from 'double' to 'float' 38 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(60,50): warning C4305: 'initializing': truncation from 'double' to 'float' 39 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(60,56): warning C4305: 'initializing': truncation from 'double' to 'float' 40 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(60,62): warning C4305: 'initializing': truncation from 'double' to 'float' 41 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(62,35): warning C4305: 'initializing': truncation from 'double' to 'float' 42 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(62,47): warning C4305: 'initializing': truncation from 'double' to 'float' 43 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(63,35): warning C4305: 'initializing': truncation from 'double' to 'float' 44 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(63,47): warning C4305: 'initializing': truncation from 'double' to 'float' 45 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(64,35): warning C4305: 'initializing': truncation from 'double' to 'float' 46 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(64,47): warning C4305: 'initializing': truncation from 'double' to 'float' 47 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(67,39): warning C4305: 'initializing': truncation from 'double' to 'float' 48 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(67,45): warning C4305: 'initializing': truncation from 'double' to 'float' 49 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(67,51): warning C4305: 'initializing': truncation from 'double' to 'float' 50 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(68,39): warning C4305: 'initializing': truncation from 'double' to 'float' 51 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(68,45): warning C4305: 'initializing': truncation from 'double' to 'float' 52 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\Source.cpp(68,51): warning C4305: 'initializing': truncation from 'double' to 'float' 53 | centralized.vcxproj -> D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\x64\Debug\Centralzied.exe 54 | -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/centralized.vcxproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Centralized\x64\Debug\Centralzied.exe 2 | -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/vc143.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/vc143.idb -------------------------------------------------------------------------------- /MultiMG/Centralized/x64/Debug/vc143.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Centralized/x64/Debug/vc143.pdb -------------------------------------------------------------------------------- /MultiMG/Decentralized/EMS.cpp: -------------------------------------------------------------------------------- 1 | #include"EMS.h" 2 | 3 | 4 | 5 | 6 | 7 | void EMS::MgOptimizationModel() { 8 | 9 | #pragma region Objective Function 10 | IloExpr objective(env_); 11 | 12 | 13 | for (int t = 0; t < T_; t++) 14 | { 15 | objective += intConstants_["Cdg1"] * Pdg1[t] + intConstants_["Cdg2"] * Pdg2[t] + CGbuy_[t] * PGbuy[t] - CGsell_[t] * PGsell[t] + CHbuy_[t] * HGbuy[t] - CHsell_[t] * HGsell[t] + intConstants_["Chob"] * Hhob[t] + intConstants_["Cchp1"] * Pchp1[t] + intConstants_["Cchp2"] * Pchp2[t]; 16 | } 17 | 18 | 19 | // Objective: minimize cost 20 | model_.add(IloMinimize(env_, objective)); 21 | 22 | #pragma endregion 23 | 24 | 25 | 26 | #pragma region Constraints 27 | 28 | 29 | // Constraint: meet demand 30 | 31 | for (int t = 0; t < T_; t++) 32 | { 33 | 34 | model_.add(0 <= Pdg1[t]); 35 | model_.add(Pdg1[t] <= 100); 36 | 37 | model_.add(0 <= Pdg2[t]); 38 | model_.add(Pdg2[t] <= 80); 39 | 40 | model_.add(0 <= Hhob[t]); 41 | model_.add(Hhob[t] <= 80); 42 | 43 | model_.add(30 <= Pchp1[t]); 44 | model_.add(Pchp1[t] <= 60); 45 | 46 | model_.add(50 <= Pchp2[t]); 47 | model_.add(Pchp2[t] <= 100); 48 | 49 | model_.add(Hchp1[t] == (floatConstants_["k1"]) * Pchp1[t]); 50 | model_.add(Hchp2[t] == (floatConstants_["k2"]) * Pchp2[t]); 51 | 52 | model_.add(0 <= HSSsoc[t]); 53 | model_.add(HSSsoc[t] <= 1); 54 | 55 | for (int n = 0; n < numEvs_; n++) 56 | { 57 | 58 | // soc bounds 59 | model_.add(0 <= evsoc[n][t]); 60 | model_.add(evsoc[n][t] <= 1); 61 | 62 | // Ev battery Constraints 63 | if (t == ta_[n]) 64 | { 65 | model_.add(evsoc[n][t] == evsocini_[n] + (floatConstants_["Eveffin"] * Pevchg[n][t] - Pevdischg[n][t] / floatConstants_["Eveffin"]) / evcap_[n]); 66 | model_.add(0 <= Pevchg[n][t]); 67 | model_.add(0 <= Pevdischg[n][t]); 68 | model_.add(Pevchg[n][t] <= (evcap_[n] * (1 - evsocini_[n]) / floatConstants_["Eveffin"])); 69 | model_.add(Pevdischg[n][t] <= (evcap_[n] * evsocini_[n] * floatConstants_["Eveffin"])); 70 | } 71 | else if (t > ta_[n] && t <= td_[n]) 72 | 73 | { 74 | model_.add(evsoc[n][t] == evsoc[n][t - 1] + ((floatConstants_["Eveffin"] * Pevchg[n][t] - (Pevdischg[n][t] / floatConstants_["Eveffin"])) / evcap_[n])); 75 | model_.add(0 <= Pevchg[n][t]); 76 | model_.add(0 <= Pevdischg[n][t]); 77 | model_.add(Pevchg[n][t] <= (evcap_[n] * (1 - evsoc[n][t - 1])) / floatConstants_["Eveffin"]); 78 | model_.add(Pevdischg[n][t] <= evcap_[n] * evsoc[n][t - 1] * floatConstants_["Eveffin"]); 79 | 80 | 81 | if (t == td_[n]) { model_.add(evsoc[n][t] >= 0.5); } 82 | 83 | } 84 | else 85 | { 86 | 87 | model_.add(Pevchg[n][t] == 0); 88 | model_.add(Pevdischg[n][t] == 0); 89 | 90 | } 91 | 92 | } 93 | 94 | 95 | // Adding the HSS and BSS Constraints constraints 96 | model_.add(0 <= statoc[t]); 97 | model_.add(statoc[t] <= 1); 98 | 99 | 100 | if (t == 0) 101 | { 102 | model_.add(statoc[t] == floatConstants_["socini"] + ((floatConstants_["effin"] * Bchg[t] - (Bdischg[t] / floatConstants_["effin"])) / intConstants_["Pbmax"])); 103 | model_.add(0 <= Bchg[t]); 104 | model_.add(0 <= Bdischg[t]); 105 | model_.add(Bchg[t] <= (intConstants_["Pbmax"] * (1 - floatConstants_["socini"]) / floatConstants_["effin"])); 106 | model_.add(Bdischg[t] <= (intConstants_["Pbmax"] * floatConstants_["socini"] * floatConstants_["effin"])); 107 | 108 | 109 | model_.add(HSSsoc[t] == 0.5 + ((floatConstants_["Heffin"] * Hchg[t] - (Hdischg[t] / floatConstants_["Heffin"])) / intConstants_["Hssmax"])); 110 | model_.add(0 <= Hchg[t]); 111 | model_.add(0 <= Hdischg[t]); 112 | //model_add(0 == Hdischg[t] * Hchg[t]); 113 | model_.add(Hchg[t] <= (intConstants_["Hssmax"] * (1 - 0.5) / floatConstants_["Heffin"])); 114 | model_.add(Hdischg[t] <= (intConstants_["Hssmax"] * 0.5 * floatConstants_["Heffin"])); 115 | 116 | } 117 | else 118 | { 119 | model_.add(statoc[t] == statoc[t - 1] + ((floatConstants_["effin"] * Bchg[t] - (Bdischg[t] / floatConstants_["effin"])) / intConstants_["Pbmax"])); 120 | model_.add(0 <= Bchg[t]); 121 | model_.add(0 <= Bdischg[t]); 122 | model_.add(Bchg[t] <= (intConstants_["Pbmax"] * (1 - statoc[t - 1])) / floatConstants_["effin"]); 123 | model_.add(Bdischg[t] <= intConstants_["Pbmax"] * statoc[t - 1] * floatConstants_["effin"]); 124 | 125 | 126 | model_.add(HSSsoc[t] == HSSsoc[t - 1] + ((floatConstants_["Heffin"] * Hchg[t] - (Hdischg[t] / floatConstants_["Heffin"])) / intConstants_["Hssmax"])); 127 | model_.add(0 <= Hchg[t]); 128 | model_.add(0 <= Hdischg[t]); 129 | //model_add(0 == Hdischg[t] * Hchg[t]); 130 | model_.add(Hchg[t] <= (intConstants_["Hssmax"] * (1 - HSSsoc[t - 1]) / floatConstants_["Heffin"])); 131 | model_.add(Hdischg[t] <= (intConstants_["Hssmax"] * HSSsoc[t - 1] * floatConstants_["Heffin"])); 132 | } 133 | 134 | 135 | // Preparing electric vehicles expression for the power balance equation 136 | IloExpr exp0(env_); 137 | IloExpr exp1(env_); 138 | for (int n = 0; n < numEvs_; n++) 139 | { 140 | exp0 += Pevchg[n][t]; 141 | exp1 += Pevdischg[n][t]; 142 | } 143 | 144 | // Adding the Electric power balance constraint 145 | 146 | model_.add(Pdg1[t] - Pec[t] + Pdg2[t] + Rdg1_[t] + Pchp1[t] + Pchp2[t] + Bdischg[t] + exp1 - exp0 - Bchg[t] + PGbuy[t] - PGsell[t] == Pload_[t]); 147 | 148 | model_.add(Hhob[t] - Hac[t] + Hchp1[t] + Hchp2[t] + HGbuy[t] - HGsell[t] - Hchg[t] + Hdischg[t] == Hload_[t]); 149 | 150 | model_.add(0.85 * Hac[t] + 0.95 * Pec[t] == Cload_[t]); 151 | 152 | } 153 | #pragma endregion 154 | 155 | 156 | } 157 | 158 | 159 | resi EMS::solve() { 160 | 161 | MgOptimizationModel(); 162 | 163 | 164 | IloCplex cplex(env_); 165 | cplex.extract(model_); 166 | cplex.exportModel("ModelLP.lp"); 167 | cplex.setOut(env_.getNullStream()); 168 | cplex.solve(); 169 | obj = cplex.getObjValue(); 170 | cout << "Solution status: " << cplex.getStatus() << endl; 171 | cout << "Minimized Objective Funtion of "<< name_ << " is : " << obj << endl; 172 | 173 | 174 | int* pmgsur = new int[T_]; 175 | int* pmgshort = new int[T_]; 176 | int* Hmgsur = new int[T_]; 177 | int* Hmgshort = new int[T_]; 178 | 179 | for (int t = 0; t < T_; t++) 180 | { 181 | pmgsur[t] = cplex.getValue(PGsell[t]); 182 | pmgshort[t] = cplex.getValue(PGbuy[t]); 183 | 184 | Hmgsur[t] = cplex.getValue(HGsell[t]); 185 | Hmgshort[t] = cplex.getValue(HGbuy[t]); 186 | } 187 | 188 | 189 | resi results; 190 | results.pmgsur = pmgsur; 191 | results.pmgshort = pmgshort; 192 | results.Hmgsur = Hmgsur; 193 | results.Hmgshort = Hmgshort; 194 | 195 | IloNum eps = cplex.getParam( 196 | IloCplex::Param::MIP::Tolerances::Integrality); 197 | 198 | saveResultsToFile(cplex); 199 | 200 | 201 | return results; 202 | 203 | } 204 | 205 | 206 | void EMS::saveResultsToFile( 207 | IloCplex& cplex) { 208 | 209 | // Create and open the CSV file for writing 210 | ofstream outputFile(name_ + "_output.csv"); 211 | 212 | if (outputFile.is_open()) { 213 | // Write the header row 214 | outputFile << "Time,Pload+Pec,Hload+Hac,Cload,CGbuy,CGsell,CHsell,CHbuy,Rdg1,PGshort/sur,statoc,Bchg/dischg,Pdg1,Pdg2,Pchp1,Pchp2,Hhob,Hchp1,Hchp2,HGshort/sur,Hchg/dischg"; 215 | for (int mg = 0; mg < numEvs_; mg++) { 216 | outputFile << ",Pevchg/dischg" << mg + 1; 217 | } 218 | 219 | outputFile << std::endl; 220 | 221 | // Write the data rows 222 | for (int i = 0; i < T_; i++) { 223 | outputFile << i + 1 << "," << Pload_[i] + cplex.getValue(Pec[i]) << "," << Hload_[i] + cplex.getValue(Hac[i]) << "," << Cload_[i] << "," << CGbuy_[i] << "," 224 | << CGsell_[i] << "," << CHsell_[i] << "," 225 | << CHbuy_[i] << "," << Rdg1_[i] << "," 226 | << cplex.getValue(PGbuy[i]) - cplex.getValue(PGsell[i]) << "," 227 | << cplex.getValue(statoc[i]) << "," << -cplex.getValue(Bchg[i]) + cplex.getValue(Bdischg[i]) << "," << cplex.getValue(Pdg1[i]) << "," 228 | << cplex.getValue(Pdg2[i]) << "," 229 | << cplex.getValue(Pchp1[i]) << "," << cplex.getValue(Pchp2[i]) << "," 230 | << cplex.getValue(Hhob[i]) << "," << cplex.getValue(Hchp1[i]) << "," 231 | << cplex.getValue(Hchp2[i]) << "," << cplex.getValue(HGbuy[i]) - cplex.getValue(HGsell[i]) << "," << -cplex.getValue(Hchg[i]) + cplex.getValue(Hdischg[i]); 232 | 233 | for (int mg = 0; mg < numEvs_; mg++) { 234 | outputFile << "," << -cplex.getValue(Pevchg[mg][i]) + cplex.getValue(Pevdischg[mg][i]); 235 | } 236 | 237 | outputFile << std::endl; 238 | } 239 | 240 | // Close the CSV file 241 | outputFile.close(); 242 | std::cout << "Data saved to " << name_ << std::endl; 243 | } 244 | else { 245 | std::cerr << "Failed to open the " << name_ << " file for writing." << std::endl; 246 | } 247 | } 248 | 249 | 250 | 251 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/EMS.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | typedef IloArray NumVar2D; 10 | 11 | 12 | struct resi { 13 | int* pmgsur; 14 | int* pmgshort; 15 | int* Hmgsur; 16 | int* Hmgshort; 17 | }; 18 | 19 | 20 | class EMS { 21 | 22 | public: 23 | void MgOptimizationModel(); 24 | void saveResultsToFile(IloCplex& cplex); 25 | resi solve(); 26 | double obj; 27 | 28 | IloNumVarArray PGbuy; 29 | IloNumVarArray PGsell; 30 | IloNumVarArray HGbuy; 31 | IloNumVarArray HGsell; 32 | 33 | 34 | EMS(string name,int T, int numEvs, const std::map& intConstants, const std::map& floatConstants, int* ta, int* td, float* evsocini, float* evcap, int* Pload, int* Hload, int* Cload, int* CGbuy, int* CGsell, int* CHbuy, int* CHsell, float* Rdg1) 35 | :name_(name), T_(T), numEvs_(numEvs), intConstants_(intConstants), floatConstants_(floatConstants), ta_(ta), td_(td), evsocini_(evsocini), evcap_(evcap), Pload_(Pload), Hload_(Hload), Cload_(Cload), CGbuy_(CGbuy), CGsell_(CGsell), CHbuy_(CHbuy), CHsell_(CHsell), Rdg1_(Rdg1) { 36 | 37 | env_ = IloEnv(); 38 | model_ = IloModel(env_); 39 | 40 | InitializeVariables(); 41 | } 42 | 43 | ~EMS() { 44 | env_.end(); 45 | } 46 | 47 | 48 | private: 49 | IloEnv env_; 50 | IloModel model_; 51 | string name_; 52 | int T_; 53 | int numEvs_; 54 | std::map intConstants_; 55 | std::map floatConstants_; 56 | int* ta_; 57 | int* td_; 58 | float* evsocini_; 59 | float* evcap_; 60 | int* Pload_; 61 | int* Hload_; 62 | int* Cload_; 63 | int* CGbuy_; 64 | int* CGsell_; 65 | int* CHbuy_; 66 | int* CHsell_; 67 | float* Rdg1_; 68 | 69 | IloNumVarArray statoc; 70 | IloNumVarArray Bchg; 71 | IloNumVarArray Bdischg; 72 | IloNumVarArray HSSsoc; 73 | IloNumVarArray Hchg; 74 | IloNumVarArray Hdischg; 75 | IloNumVarArray Pdg1; 76 | IloNumVarArray Pdg2; 77 | IloNumVarArray Pchp1; 78 | IloNumVarArray Pchp2; 79 | IloNumVarArray Hhob; 80 | IloNumVarArray Hchp1; 81 | IloNumVarArray Hchp2; 82 | IloNumVarArray Hac; 83 | IloNumVarArray Pec; 84 | 85 | // Electric Vehicles Decision Variables 86 | NumVar2D Pevchg; 87 | NumVar2D Pevdischg; 88 | NumVar2D evsoc; 89 | 90 | void InitializeVariables() { 91 | // Initialize decision variables 92 | PGbuy = IloNumVarArray(env_, T_, 0, IloInfinity, ILOINT);//Grid power bought 93 | PGsell = IloNumVarArray(env_, T_, 0, IloInfinity, ILOINT);//Grid power sold 94 | HGbuy = IloNumVarArray(env_, T_, 0, IloInfinity, ILOINT);//Grid Heat bought 95 | HGsell = IloNumVarArray(env_, T_, 0, IloInfinity, ILOINT);//Grid Heat sold 96 | statoc = IloNumVarArray(env_, T_, 0, 1); //battery storage capacity 97 | Bchg = IloNumVarArray(env_, T_, 0, 100); //battery charging 98 | Bdischg = IloNumVarArray(env_, T_, 0, 100); //battery discharging 99 | HSSsoc = IloNumVarArray(env_, T_, 0, 1); //battery storage capacity 100 | Hchg = IloNumVarArray(env_, T_, 0, 50, ILOINT); //battery charging 101 | Hdischg = IloNumVarArray(env_, T_, 0, 50, ILOINT); //battery discharging 102 | Pdg1 = IloNumVarArray(env_, T_, 0, 100, ILOINT); //DGA power generation range 103 | Pdg2 = IloNumVarArray(env_, T_, 0, 80, ILOINT); //DGA power generation range 104 | Pchp1 = IloNumVarArray(env_, T_, 30, 60, ILOINT); //CHP1 power generation range 105 | Pchp2 = IloNumVarArray(env_, T_, 50, 100, ILOINT); //CHP2 power generation range 106 | Hhob = IloNumVarArray(env_, T_, 0, 80, ILOINT); //HOB heat power generation range 107 | Hchp1 = IloNumVarArray(env_, T_, 0, IloInfinity); //CHP1 heat power generation range 108 | Hchp2 = IloNumVarArray(env_, T_, 0, IloInfinity); //CHP2 heat generation range 109 | Hac = IloNumVarArray(env_, T_, 0, IloInfinity); // AC 110 | Pec = IloNumVarArray(env_, T_, 0, IloInfinity); // Electric Chiller 111 | 112 | // Electric Vehicles Decision Variables 113 | Pevchg = NumVar2D(env_, numEvs_); 114 | Pevdischg = NumVar2D(env_, numEvs_); 115 | evsoc = NumVar2D(env_, numEvs_); 116 | 117 | for (int n = 0; n < numEvs_; n++) { 118 | Pevchg[n] = IloNumVarArray(env_, T_, 0, evcap_[n], ILOFLOAT); 119 | Pevdischg[n] = IloNumVarArray(env_, T_, 0, evcap_[n], ILOFLOAT); 120 | evsoc[n] = IloNumVarArray(env_, T_, 0, 1, ILOFLOAT); 121 | } 122 | } 123 | 124 | }; -------------------------------------------------------------------------------- /MultiMG/Decentralized/Source.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include"EMS.h" 7 | ILOSTLBEGIN 8 | 9 | 10 | typedef IloArray NumVar2D; 11 | typedef IloArray NumVar3D; 12 | 13 | 14 | void printIntArray(int* arr, int size) { 15 | for (int i = 0; i < size; i++) { 16 | std::cout << arr[i] << " "; 17 | } 18 | std::cout << std::endl; 19 | } 20 | 21 | 22 | int 23 | main(int, char**) 24 | { 25 | 26 | auto start = chrono::high_resolution_clock::now(); 27 | IloEnv env; 28 | IloModel model(env); 29 | 30 | 31 | #pragma region Microgrid Input Data 32 | 33 | // Some Constants 34 | 35 | 36 | int T = 24; //One day 37 | int numEvs = 5; // Total Nmber of Electric vehicles 38 | 39 | map int_constant = { 40 | {"Cdg1", 135}, 41 | {"Cdg2", 140}, 42 | {"Chob", 80}, 43 | {"Cchp1", 150}, 44 | {"Cchp2", 145}, 45 | {"Pbmax", 150}, 46 | {"Hssmax", 50}, 47 | }; 48 | 49 | 50 | map float_constant = { 51 | {"socini", 0.2}, 52 | {"effin", 0.95}, 53 | {"Eveffin", 0.90}, 54 | {"k1", 1.2}, 55 | {"k2", 0.8}, 56 | {"Heffin", 0.95} 57 | }; 58 | 59 | 60 | // Arrival and Departure time of Evs 61 | int* ta = new int[numEvs] {2,4,6,9,9}; 62 | int* td = new int[numEvs] {6, 7, 9, 12, 16}; 63 | float* evsocini = new float[numEvs] {0.30,0.20,0.10,0.70,0.40}; 64 | float* evcap = new float[numEvs] {38.3, 47.5, 28.9, 56, 52}; 65 | 66 | // Electric and Heat Demand 67 | int* Pload_arr = new int[T] {169, 175, 179, 171, 181, 190, 270, 264, 273, 281, 300, 320, 280, 260, 250, 200, 180, 190, 240, 280, 325, 350, 300, 250}; //Electicity demand w.r.t tim 68 | int* Hload_arr = new int[T] {130, 125, 120, 120, 125, 135, 150, 160, 175, 190, 195, 200, 195, 195, 180, 170, 185, 190, 195, 200, 195, 190, 180, 175}; //Heat Demand 69 | int* Cload_arr = new int[T] {100, 100, 80, 100, 120, 135, 150, 135, 125, 130, 140, 150, 150, 130, 120, 110, 90, 80, 135, 150, 135, 140, 110, 125}; //Heat Demand 70 | 71 | 72 | // Electric, Heat and Cooling Demand // add the randomly populating 73 | int** Pload = new int* [3]; //Electicity demand w 74 | int** Hload = new int* [3]; //Heat Demand 75 | int** Cload = new int* [3]; //Cooling Demand 76 | 77 | float* scaling = new float[3] {1,0.5,2}; 78 | 79 | for (int i = 0; i < 3; i++) 80 | { 81 | Pload[i] = new int[T]; 82 | Hload[i] = new int[T]; 83 | Cload[i] = new int[T]; 84 | 85 | for (int t = 0; t < T; t++) 86 | { 87 | Pload[i][t] = static_cast(Pload_arr[t] * scaling[i]); 88 | Hload[i][t] = static_cast(Hload_arr[t] * scaling[i]); 89 | Cload[i][t] = static_cast(Cload_arr[t] * 1); 90 | } 91 | 92 | } 93 | 94 | 95 | 96 | 97 | 98 | // Trading Prices Electric and Heat 99 | int* CGbuy = new int[T] { 138, 139, 143, 149, 150, 152, 155, 158, 160, 154, 153, 153, 152, 150, 149, 149, 154, 156, 163, 164, 164, 160, 150, 148}; //buying price of electricity 100 | int* CGsell = new int[T] { 128, 129, 133, 139, 140, 142, 145, 148, 150, 144, 143, 143, 142, 140, 139, 139, 144, 146, 153, 154, 154, 150, 140, 138}; //selling price of electricity 101 | int* CHbuy = new int[T] {77, 77, 77, 77, 77, 77, 77, 77, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 78, 78, 78, 78, 78, 78}; // buying price of heat 102 | int* CHsell = new int[T] {75, 75, 75, 75, 75, 75, 75, 75, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 78, 78, 78, 78, 78, 78 }; // selling price of heat 103 | // Scale the prices by a factor of 1.8 104 | const double scalingFactor = 1.8; 105 | for (int i = 0; i < T; ++i) { 106 | CHbuy[i] = static_cast(CHbuy[i] * scalingFactor); 107 | CHsell[i] = static_cast(CHsell[i] * scalingFactor); 108 | } 109 | 110 | 111 | 112 | // Renewable Infeeds 113 | float* Rdg1 = new float[T] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10, 15, 20, 23, 28, 33, 35, 34, 31, 28, 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; //Power generated by PV w.r.t time 114 | //float* Rdg2 = new float[T] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10, 15, 20, 23, 28, 33, 35, 34, 31, 28, 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; //Power generated by PV w.r.t time 115 | 116 | #pragma endregion 117 | 118 | 119 | EMS mg1("mg1" , T, numEvs, int_constant, float_constant, ta, td, evsocini, evcap, Pload[0], Hload[0], Cload[0], CGbuy, CGsell, CHbuy, CHsell, Rdg1); 120 | EMS mg2("mg2" , T, numEvs, int_constant, float_constant, ta, td, evsocini, evcap, Pload[1], Hload[1], Cload[1], CGbuy, CGsell, CHbuy, CHsell, Rdg1); 121 | EMS mg3("mg3" , T, numEvs, int_constant, float_constant, ta, td, evsocini, evcap, Pload[2], Hload[2], Cload[2], CGbuy, CGsell, CHbuy, CHsell, Rdg1); 122 | resi mg1Result = mg1.solve(); 123 | resi mg2Result = mg2.solve(); 124 | resi mg3Result = mg3.solve(); 125 | 126 | 127 | 128 | int NumMg = 3; 129 | 130 | 131 | int** pshort = new int* [NumMg] {mg1Result.pmgshort, mg2Result.pmgshort, mg3Result.pmgshort}; 132 | int** psur = new int* [NumMg] {mg1Result.pmgsur, mg2Result.pmgsur, mg3Result.pmgsur}; 133 | int** hshort = new int* [NumMg] {mg1Result.Hmgshort, mg2Result.Hmgshort, mg3Result.Hmgshort}; 134 | int** hsur = new int* [NumMg] {mg1Result.Hmgsur, mg2Result.Hmgsur, mg3Result.Hmgsur}; 135 | 136 | 137 | int* ptotalshort = new int[T]; 138 | int* ptotalsur = new int[T]; 139 | int* htotalshort = new int[T]; 140 | int* htotalsur = new int[T]; 141 | 142 | for (int t = 0; t < T; t++) { 143 | ptotalshort[t] = 0; // Initialize to 0 for each time step 144 | ptotalsur[t] = 0; // Initialize to 0 for each time step 145 | htotalshort[t] = 0; // Initialize to 0 for each time step 146 | htotalsur[t] = 0; // Initialize to 0 for each time step 147 | 148 | for (int mg = 0; mg < NumMg; mg++) { 149 | ptotalshort[t] += pshort[mg][t]; 150 | ptotalsur[t] += psur[mg][t]; 151 | htotalshort[t] += hshort[mg][t]; 152 | htotalsur[t] += hsur[mg][t]; 153 | } 154 | } 155 | 156 | 157 | #pragma region CEMS 158 | 159 | 160 | 161 | IloEnv envcems; 162 | IloModel cmodel(envcems); 163 | 164 | 165 | #pragma region CEMS decision variables 166 | 167 | 168 | NumVar2D powergridbuy(envcems, NumMg); 169 | NumVar2D powergridsell(envcems, NumMg); 170 | NumVar2D heatgridbuy(envcems, NumMg); 171 | NumVar2D heatgridsell(envcems, NumMg); 172 | 173 | 174 | NumVar3D powersend(envcems, NumMg); 175 | NumVar3D powersrec(envcems, NumMg); 176 | NumVar3D heatsend(envcems, NumMg); 177 | NumVar3D heatrec(envcems, NumMg); 178 | 179 | 180 | for (int mg = 0; mg < NumMg; mg++) 181 | { 182 | powergridbuy[mg] = IloNumVarArray(envcems, T, 0, IloInfinity); 183 | powergridsell[mg] = IloNumVarArray(envcems, T, 0, IloInfinity); 184 | heatgridbuy[mg] = IloNumVarArray(envcems, T, 0, IloInfinity); 185 | heatgridsell[mg] = IloNumVarArray(envcems, T, 0, IloInfinity); 186 | 187 | 188 | powersend[mg] = NumVar2D(envcems, NumMg); 189 | powersrec[mg] = NumVar2D(envcems, NumMg); 190 | heatsend[mg] = NumVar2D(envcems, NumMg); 191 | heatrec[mg] = NumVar2D(envcems, NumMg); 192 | 193 | 194 | for (int l = 0; l < NumMg; l++) 195 | { 196 | powersend[mg][l] = IloNumVarArray(envcems, T, 0, IloInfinity); 197 | powersrec[mg][l] = IloNumVarArray(envcems, T, 0, IloInfinity); 198 | heatsend[mg][l] = IloNumVarArray(envcems, T, 0, IloInfinity); 199 | heatrec[mg][l] = IloNumVarArray(envcems, T, 0, IloInfinity); 200 | 201 | } 202 | 203 | } 204 | 205 | #pragma endregion 206 | 207 | 208 | #pragma region Objective Function 209 | 210 | IloExpr cemsobjective(envcems); 211 | 212 | for (int mg = 0; mg < NumMg; mg++) 213 | { 214 | for (int t = 0; t < T; t++) 215 | { 216 | cemsobjective += CGbuy[t] * powergridbuy[mg][t] - CGsell[t] * powergridsell[mg][t] - CHsell[t] * heatgridsell[mg][t] + CHbuy[t] * heatgridbuy[mg][t]; 217 | } 218 | } 219 | 220 | cmodel.add(IloMinimize(envcems, cemsobjective)); 221 | 222 | #pragma endregion 223 | 224 | 225 | #pragma region constraints 226 | 227 | IloExpr exp0(envcems); 228 | IloExpr exp1(envcems); 229 | IloExpr exp2(envcems); 230 | IloExpr exp3(envcems); 231 | 232 | 233 | for (int t = 0; t < T; t++) 234 | { 235 | for (int k = 0; k < NumMg; k++) 236 | { 237 | for (int l = 0; l < NumMg; l++) 238 | { 239 | 240 | if (k != l) { 241 | exp0 += powersend[k][l][t]; 242 | exp1 += powersrec[k][l][t]; 243 | exp2 += heatsend[k][l][t]; 244 | exp3 += heatrec[k][l][t]; 245 | 246 | 247 | } 248 | else 249 | { 250 | cmodel.add(powersend[k][l][t] == 0); 251 | cmodel.add(powersrec[k][l][t] == 0); 252 | cmodel.add(heatsend[k][l][t] == 0); 253 | cmodel.add(heatrec[k][l][t] == 0); 254 | 255 | } 256 | } 257 | } 258 | cmodel.add(exp0 == exp1); 259 | cmodel.add(exp2 == exp3); 260 | } 261 | 262 | 263 | 264 | 265 | 266 | for (int t = 0; t < T; t++) 267 | { 268 | 269 | for (int k = 0; k < NumMg; k++) 270 | { 271 | 272 | IloExpr mgEsend(envcems); 273 | IloExpr mgErec(envcems); 274 | IloExpr mgHsend(envcems); 275 | IloExpr mgHrec(envcems); 276 | 277 | for (int l = 0; l < NumMg; l++) 278 | { 279 | mgEsend += powersend[k][l][t]; 280 | mgErec += powersrec[k][l][t]; 281 | mgHsend += heatsend[k][l][t]; 282 | mgHrec += heatrec[k][l][t]; 283 | } 284 | cmodel.add(mgEsend + powergridsell[k][t] == psur[k][t]); 285 | cmodel.add(mgHsend + heatgridsell[k][t] == hsur[k][t]); 286 | 287 | cmodel.add(mgErec + powergridbuy[k][t] == pshort[k][t]); 288 | 289 | cmodel.add(mgHrec + heatgridbuy[k][t] == hshort[k][t]); 290 | 291 | 292 | 293 | } 294 | 295 | 296 | 297 | 298 | 299 | 300 | } 301 | 302 | 303 | 304 | 305 | #pragma endregion 306 | 307 | 308 | 309 | 310 | #pragma endregion 311 | IloCplex cplex(envcems); 312 | cplex.extract(cmodel); 313 | cplex.exportModel("ModelLP.lp"); 314 | cplex.setOut(envcems.getNullStream()); 315 | cplex.solve(); 316 | double obj = cplex.getObjValue(); 317 | cout << "Solution status: " << cplex.getStatus() << endl; 318 | cout << "Minimized Objective Funtion of " << obj << endl; 319 | 320 | 321 | 322 | 323 | 324 | // Create and open the CSV file for writing 325 | ofstream outputFile("global_output.csv"); 326 | 327 | 328 | 329 | outputFile << "Mg1send/rec,Mg1short/sur,mg1buy/sell,Mg2send/rec,Mg2short/sur,mg2buy/sell,Mg3send/rec,Mg3short/sur,mg3buy/sell" << endl; 330 | 331 | 332 | for (int t = 0; t < T; t++) 333 | { 334 | 335 | 336 | for (int mg = 0; mg < NumMg; mg++) 337 | { 338 | double ps = 0; double pr = 0; 339 | 340 | for (int l = 0; l < NumMg; l++) 341 | { 342 | ps += cplex.getValue(powersend[mg][l][t]); 343 | pr += cplex.getValue(powersrec[mg][l][t]); 344 | 345 | } 346 | 347 | outputFile << -ps + pr << ","<<+psur[mg][t] - pshort[mg][t]<<"," << cplex.getValue(powergridbuy[mg][t]) - cplex.getValue(powergridsell[mg][t]) << ","; 348 | 349 | } 350 | 351 | outputFile << endl; 352 | 353 | 354 | } 355 | 356 | 357 | 358 | 359 | return 1; 360 | 361 | } -------------------------------------------------------------------------------- /MultiMG/Decentralized/decentralizedMG.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34024.191 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "Project1.vcxproj", "{92FC16A1-661B-40D1-833F-FA53A83C04DF}" 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 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x64.ActiveCfg = Debug|x64 17 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x64.Build.0 = Debug|x64 18 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x86.ActiveCfg = Debug|Win32 19 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x86.Build.0 = Debug|Win32 20 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x64.ActiveCfg = Release|x64 21 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x64.Build.0 = Release|x64 22 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x86.ActiveCfg = Release|Win32 23 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {89DA0DA7-D26C-4CE9-B98A-A7D76BE1D820} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/decentralizedMG.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 | 17.0 23 | Win32Proj 24 | {92fc16a1-661b-40d1-833f-fa53a83c04df} 25 | Project1 26 | 10.0 27 | Decentralized 28 | 29 | 30 | 31 | Application 32 | true 33 | v143 34 | Unicode 35 | 36 | 37 | Application 38 | false 39 | v143 40 | true 41 | Unicode 42 | 43 | 44 | Application 45 | true 46 | v143 47 | Unicode 48 | 49 | 50 | Application 51 | false 52 | v143 53 | true 54 | Unicode 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Level3 77 | true 78 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 79 | true 80 | 81 | 82 | Console 83 | true 84 | 85 | 86 | 87 | 88 | Level3 89 | true 90 | true 91 | true 92 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | true 99 | true 100 | 101 | 102 | 103 | 104 | Level3 105 | true 106 | WIN64;_CONSOLE;IL_STD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 107 | true 108 | C:\Program Files\IBM\ILOG\CPLEX_Studio221\concert\include;C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\include;%(AdditionalIncludeDirectories) 109 | MultiThreadedDLL 110 | 111 | 112 | Console 113 | true 114 | C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\lib\x64_windows_msvc14\stat_mda\cplex2210.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\lib\x64_windows_msvc14\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio221\concert\lib\x64_windows_msvc14\stat_mda\concert.lib;%(AdditionalDependencies) 115 | 116 | 117 | 118 | 119 | Level3 120 | true 121 | true 122 | true 123 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 124 | true 125 | 126 | 127 | Console 128 | true 129 | true 130 | true 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/decentralizedMG.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;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 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/decentralizedMG.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/global_output.csv: -------------------------------------------------------------------------------- 1 | Mg1send/rec,Mg1short/sur,mg1buy/sell,Mg2send/rec,Mg2short/sur,mg2buy/sell,Mg3send/rec,Mg3short/sur,mg3buy/sell,short,mg_trade,grid_trade 2 | 0,-114,114,0,0,0,0,-283,283,397,, 3 | 0,-46,46,0,0,0,0,-221,221,267,, 4 | 0,0,0,0,0,0,0,-112,112,112,, 5 | 0,0,0,-70,70,0,70,-107,37,37,, 6 | 0,0,0,-28,28,0,28,-164,136,136,, 7 | -8,8,0,-103,103,0,111,-182,71,71,, 8 | 0,-6,6,-47,47,0,47,-201,154,160,, 9 | 0,0,0,-76,76,0,76,-179,103,103,, 10 | 0,0,0,-88,88,0,88,-322,234,234,, 11 | 53,-53,0,-80,80,0,27,-342,315,315,, 12 | 66,-84,18,-66,66,0,0,-384,384,402,, 13 | 50,-106,56,-50,50,0,0,-430,430,486,, 14 | 65,-65,0,-75,75,0,10,-345,335,335,, 15 | 22,-22,0,-28,28,0,6,-282,276,276,, 16 | 2,-2,0,-37,37,0,35,-257,222,222,, 17 | 0,0,0,-75,75,0,75,-145,70,70,, 18 | -87,93,-6,0,183,-183,87,-87,0,-189,, 19 | -76,76,0,-38,171,-133,114,-114,0,-133,, 20 | 0,0,0,-78,78,0,78,-140,62,62,, 21 | 0,0,0,-84,84,0,84,-121,37,37,, 22 | 0,0,0,-138,138,0,138,-270,132,132,, 23 | 0,0,0,-18,18,0,18,-361,343,343,, 24 | 0,-76,76,0,0,0,0,-376,376,452,, 25 | 4,-41,37,-4,4,0,0,-291,291,328,, 26 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/mg1_output.csv: -------------------------------------------------------------------------------- 1 | Time,Pload+Pec,Hload+Hac,Cload,CGbuy,CGsell,CHsell,CHbuy,Rdg1,PGshort/sur,statoc,Bchg/dischg,Pdg1,Pdg2,Pchp1,Pchp2,Hhob,Hchp1,Hchp2,HGshort/sur,Hchg/dischg,Pevchg/dischg1,Pevchg/dischg2,Pevchg/dischg3,Pevchg/dischg4,Pevchg/dischg5 2 | 1,274.263,130,100,138,128,135,138,0,114,0.831667,-99.7368,100,0,60,100,80,72,80,-102,0,0,0,0,0,0 3 | 2,280.263,125,100,139,129,135,138,0,46,0.994667,-25.7368,100,0,60,100,80,72,80,-107,0,0,0,0,0,0 4 | 3,263.211,120,80,143,133,135,138,0,0,0.995333,-0.105253,100,4,60,100,80,72,80,-112,0,-0.684224,0,0,0,0 5 | 4,276.263,120,100,149,139,135,138,0,0,1,-0.736846,100,17,60,100,80,72,80,-112,0,0,0,0,0,0 6 | 5,307.316,125,120,150,140,135,138,0,0,1,0,100,71,60,100,80,72,80,-100,-7,-7.82689,-15.8573,0,0,0 7 | 6,332.105,135,135,152,142,135,138,0,-8,0.999261,0.10526,100,80,60,100,80,72,80,-97,0,0,0,0,0,0 8 | 7,342,246,150,155,145,135,138,0,6,0.999261,0,100,80,60,100,80,72,80,14,0,0,0,-4,0,0 9 | 8,341.684,232,135,158,148,135,138,10,0,0.999261,0,100,80,60,100,80,72,80,0,0,0,0,-8.31579,0,0 10 | 9,404.579,175,125,160,150,144,149,15,0,0.651339,49.5789,100,80,60,100,80,72,80,-57,0,0,0,0,0,0 11 | 10,417.842,190,130,154,144,144,149,20,53,0.651339,0,100,80,60,100,80,72,80,-51,9,0,0,-0.528648,5.81685,-0.446099 12 | 11,447.368,195,140,153,143,144,149,23,84,0.651339,0,100,80,60,100,80,72,80,-37,0,0,0,0,0.368417,0 13 | 12,477.895,200,150,153,143,144,149,28,106,0.651339,0,100,80,60,100,80,72,80,-32,0,0,0,0,3.89473,0 14 | 13,437.895,195,150,152,142,144,149,33,65,0.652006,-0.105267,100,80,60,100,80,72,80,-37,0,0,0,0,0,0 15 | 14,396.842,195,130,150,140,144,149,35,22,0.653006,-0.157898,100,80,60,100,80,72,80,-56,19,0,0,0,0,0 16 | 15,376.316,180,120,149,139,144,149,34,2,0.65079,0.315786,100,80,60,100,80,72,80,-52,0,0,0,0,0,0 17 | 16,315.789,170,110,149,139,144,149,31,0,0.966689,-49.8789,100,80,60,100,80,72,80,-62,0,0,0,0,0,-5.33168 18 | 17,274.737,185,90,154,144,144,149,28,-93,0.968356,-0.263162,100,80,60,100,80,72,80,-47,0,0,0,0,0,0 19 | 18,274.211,190,80,156,146,144,149,10,-76,0.966878,0.210523,100,80,60,100,80,72,80,-42,0,0,0,0,0,0 20 | 19,340.053,242,135,163,153,140,140,0,0,0.966509,0.052628,100,80,60,100,80,72,80,10,0,0,0,0,0,0 21 | 20,340.368,309,150,164,154,140,140,0,0,0.963924,0.368417,100,80,60,100,80,72,80,77,0,0,0,0,0,0 22 | 21,377.632,295,135,164,154,140,140,0,0,0.699842,37.6316,100,80,60,100,80,72,80,63,0,0,0,0,0,0 23 | 22,439.211,255,140,160,150,140,140,0,0,0.00362818,99.2105,100,80,60,100,80,72,80,23,0,0,0,0,0,0 24 | 23,415.789,180,110,150,140,140,140,0,76,0.00496153,-0.21053,100,80,60,100,80,72,80,-52,0,0,0,0,0,0 25 | 24,381.579,175,125,148,138,140,140,0,41,0.000898769,0.578944,100,80,60,100,80,72,80,-59,2,0,0,0,0,0 26 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/mg2_output.csv: -------------------------------------------------------------------------------- 1 | Time,Pload+Pec,Hload+Hac,Cload,CGbuy,CGsell,CHsell,CHbuy,Rdg1,PGshort/sur,statoc,Bchg/dischg,Pdg1,Pdg2,Pchp1,Pchp2,Hhob,Hchp1,Hchp2,HGshort/sur,Hchg/dischg,Pevchg/dischg1,Pevchg/dischg2,Pevchg/dischg3,Pevchg/dischg4,Pevchg/dischg5 2 | 1,189.263,65,100,138,128,135,138,0,0,0.648,-70.7368,100,0,60,100,80,72,80,-167,0,0,0,0,0,0 3 | 2,192.263,62,100,139,129,135,138,0,0,0.994667,-54.7368,87,0,60,100,80,72,80,-170,0,0,0,0,0,0 4 | 3,173.211,60,80,143,133,135,138,0,0,0.996,-0.210517,22,0,60,100,80,72,80,-172,0,-8.57896,0,0,0,0 5 | 4,189.368,61,100,149,139,135,138,0,-70,1,-0.631583,100,0,60,100,80,72,80,-164,-7,0,0,0,0,0 6 | 5,216.316,62,120,150,140,135,138,0,-28,1,0,100,0,60,100,80,72,80,-170,0,0,-15.6842,0,0,0 7 | 6,237.105,67,135,152,142,135,138,0,-103,0.999261,0.10526,100,80,60,100,80,72,80,-165,0,0,0,0,0,0 8 | 7,292.895,75,150,155,145,135,138,0,-47,0.999261,0,100,80,60,100,80,72,80,-157,0,0.0438527,-0.149119,0,0,0 9 | 8,274.105,80,135,158,148,135,138,10,-76,0.998523,0.10526,100,80,60,100,80,72,80,-152,0,0,0,0,0,0 10 | 9,267.579,87,125,160,150,144,149,15,-88,0.99446,0.578944,100,80,60,100,80,72,80,-145,0,0,0,0,0,0 11 | 10,276.842,95,130,154,144,144,149,20,-80,0.99446,0,100,80,60,100,80,72,80,-167,30,0,0,-12.8444,9.68655,0 12 | 11,297.368,97,140,153,143,144,149,23,-66,0.99446,0,100,80,60,100,80,72,80,-135,0,0,0,0,0.368417,0 13 | 12,317.895,100,150,153,143,144,149,28,-50,0.99446,0,100,80,60,100,80,72,80,-132,0,0,0,0,0.0250355,-0.130302 14 | 13,297.895,97,150,152,142,144,149,33,-75,0.99446,0,100,80,60,100,80,72,80,-135,0,0,0,0,0,-0.105267 15 | 14,266.842,97,130,150,140,144,149,35,-28,0.99446,0,100,0,60,100,80,72,80,-135,0,0,0,0,0,-0.157898 16 | 15,251.316,90,120,149,139,144,149,34,-37,0.999359,-0.773595,100,0,60,100,80,72,80,-142,0,0,0,0,0,-4.91062 17 | 16,215.789,85,110,149,139,144,149,31,-75,0.999359,0,100,0,60,100,80,72,80,-147,0,0,0,0,0,-0.21053 18 | 17,184.737,92,90,154,144,144,149,28,-183,0.999359,0,100,80,60,100,80,72,80,-140,0,0,0,0,0,-0.263162 19 | 18,179.211,95,80,156,146,144,149,10,-171,0.997882,0.210523,100,80,60,100,80,72,80,-137,0,0,0,0,0,0 20 | 19,262.105,97,135,163,153,140,140,0,-78,0.997143,0.10526,100,80,60,100,80,72,80,-135,0,0,0,0,0,0 21 | 20,297.895,100,150,164,154,140,140,0,-84,0.703145,41.8947,100,80,60,100,80,72,80,-132,0,0,0,0,0,0 22 | 21,301.421,100,135,164,154,140,140,0,-138,0.00545362,99.421,100,80,60,100,80,72,80,-132,0,0,0,0,0,0 23 | 22,322.368,95,140,160,150,140,140,0,-18,0.00286823,0.368417,100,80,60,100,80,72,80,-137,0,0,0,0,0,0 24 | 23,265.789,90,110,150,140,140,140,0,0,0.00420159,-0.21053,100,6,60,100,80,72,80,-142,0,0,0,0,0,0 25 | 24,256.579,87,125,148,138,140,140,0,-4,0.000138828,0.578944,100,0,60,100,80,72,80,-145,0,0,0,0,0,0 26 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/mg3_output.csv: -------------------------------------------------------------------------------- 1 | Time,Pload+Pec,Hload+Hac,Cload,CGbuy,CGsell,CHsell,CHbuy,Rdg1,PGshort/sur,statoc,Bchg/dischg,Pdg1,Pdg2,Pchp1,Pchp2,Hhob,Hchp1,Hchp2,HGshort/sur,Hchg/dischg,Pevchg/dischg1,Pevchg/dischg2,Pevchg/dischg3,Pevchg/dischg4,Pevchg/dischg5 2 | 1,443.263,260,100,138,128,135,138,0,283,0.831667,-99.7368,100,0,60,100,80,72,80,36,-8,0,0,0,0,0 3 | 2,455.263,250,100,139,129,135,138,0,221,0.994667,-25.7368,100,0,60,100,80,72,80,18,0,0,0,0,0,0 4 | 3,442.211,240,80,143,133,135,138,0,112,1,-0.842099,100,80,60,100,80,72,80,8,0,-8.94738,0,0,0,0 5 | 4,447.263,240,100,149,139,135,138,0,107,0.998153,0.263154,100,80,60,100,80,72,80,8,0,0,0,0,0,0 6 | 5,488.316,250,120,150,140,135,138,0,164,0.998153,0,100,80,60,100,80,72,80,18,0,0,-15.6842,0,0,0 7 | 6,522.105,270,135,152,142,135,138,0,182,0.997415,0.10526,100,80,60,100,80,72,80,38,0,0,0,0,0,0 8 | 7,541.316,475,150,155,145,135,138,0,201,0.997415,0,100,80,60,100,80,72,80,243,0,0.315786,0,0,0,0 9 | 8,528.737,478,135,158,148,135,138,10,179,0.997415,0,100,80,60,100,80,72,80,246,0,0,-0.149119,-0.114042,0,0 10 | 9,677.579,350,125,160,150,144,149,15,322,0.992563,0.691306,100,80,60,100,80,72,80,118,0,0,0,-0.112362,0,0 11 | 10,698.842,380,130,154,144,144,149,20,342,0.992563,0,100,80,60,100,80,72,80,148,0,0,0,-12.618,9.46014,0 12 | 11,747.368,390,140,153,143,144,149,23,384,0.992563,0,100,80,60,100,80,72,80,158,0,0,0,0,0.368417,0 13 | 12,797.895,400,150,153,143,144,149,28,430,0.992563,0,100,80,60,100,80,72,80,168,0,0,0,0,0.25144,-0.356707 14 | 13,717.895,390,150,152,142,144,149,33,345,0.992563,0,100,80,60,100,80,72,80,158,0,0,0,0,0,-0.105267 15 | 14,656.842,390,130,150,140,144,149,35,282,0.992563,0,100,80,60,100,80,72,80,158,0,0,0,0,0,-0.157898 16 | 15,626.316,360,120,149,139,144,149,34,257,0.992563,0,100,80,60,100,80,72,80,128,0,0,0,0,0,-4.68421 17 | 16,515.789,340,110,149,139,144,149,31,145,0.992563,0,100,80,60,100,80,72,80,108,0,0,0,0,0,-0.21053 18 | 17,454.737,370,90,154,144,144,149,28,87,0.992563,0,100,80,60,100,80,72,80,108,30,0,0,0,0,-0.263162 19 | 18,464.211,380,80,156,146,144,149,10,114,0.991086,0.210523,100,80,60,100,80,72,80,148,0,0,0,0,0,0 20 | 19,480.737,548,135,163,153,140,140,0,140,0.985915,0.736838,100,80,60,100,80,72,80,316,0,0,0,0,0,0 21 | 20,560.421,576,150,164,154,140,140,0,121,0.288224,99.421,100,80,60,100,80,72,80,344,0,0,0,0,0,0 22 | 21,650.737,548,135,164,154,140,140,0,270,0.00235108,40.7368,100,80,60,100,80,72,80,316,0,0,0,0,0,0 23 | 22,700.632,544,140,160,150,140,140,0,361,0.00468444,-0.368425,100,80,60,100,80,72,80,312,0,0,0,0,0,0 24 | 23,715.789,360,110,150,140,140,140,0,376,0.0060178,-0.21053,100,80,60,100,80,72,80,128,0,0,0,0,0,0 25 | 24,631.579,350,125,148,138,140,140,0,291,0.00195503,0.578944,100,80,60,100,80,72,80,118,0,0,0,0,0,0 26 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.Build.CppClean.log: -------------------------------------------------------------------------------- 1 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\vc143.pdb 2 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\vc143.idb 3 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\source.obj 4 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\ems.obj 5 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\decentralized.exe 6 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\decentralized.ilk 7 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\decentralized.pdb 8 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\decentralized.tlog\cl.command.1.tlog 9 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\decentralized.tlog\cl.items.tlog 10 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\decentralized.tlog\cl.read.1.tlog 11 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\decentralized.tlog\cl.write.1.tlog 12 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\decentralized.tlog\link.command.1.tlog 13 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\decentralized.tlog\link.read.1.tlog 14 | d:\masterwork\codes\microgridoptimization\multimg\decentralized\x64\debug\decentralized.tlog\link.write.1.tlog 15 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/Decentralized.exe -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.exe.recipe: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\x64\Debug\Decentralized.exe 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/Decentralized.ilk -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/Decentralized.pdb -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.tlog/CL.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/Decentralized.tlog/CL.command.1.tlog -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.tlog/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/Decentralized.tlog/CL.read.1.tlog -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.tlog/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/Decentralized.tlog/CL.write.1.tlog -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.tlog/Cl.items.tlog: -------------------------------------------------------------------------------- 1 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\Source.cpp;D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\x64\Debug\Source.obj 2 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\EMS.cpp;D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\x64\Debug\EMS.obj 3 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.tlog/Decentralized.lastbuildstate: -------------------------------------------------------------------------------- 1 | PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.37.32822:TargetPlatformVersion=10.0.22621.0: 2 | Debug|x64|D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\| 3 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.tlog/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/Decentralized.tlog/link.command.1.tlog -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.tlog/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/Decentralized.tlog/link.read.1.tlog -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Decentralized.tlog/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/Decentralized.tlog/link.write.1.tlog -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/EMS.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/EMS.obj -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/Source.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/Source.obj -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/decentralizedMG.log: -------------------------------------------------------------------------------- 1 |  Source.cpp 2 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\Source.cpp(63,38): warning C4305: 'initializing': truncation from 'double' to 'float' 3 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\Source.cpp(63,43): warning C4305: 'initializing': truncation from 'double' to 'float' 4 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\Source.cpp(63,48): warning C4305: 'initializing': truncation from 'double' to 'float' 5 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\Source.cpp(63,53): warning C4305: 'initializing': truncation from 'double' to 'float' 6 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\Source.cpp(63,58): warning C4305: 'initializing': truncation from 'double' to 'float' 7 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\Source.cpp(64,35): warning C4305: 'initializing': truncation from 'double' to 'float' 8 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\Source.cpp(64,47): warning C4305: 'initializing': truncation from 'double' to 'float' 9 | C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\utility(242,54): warning C4244: 'initializing': conversion from '_Ty' to '_Ty2', possible loss of data 10 | with 11 | [ 12 | _Ty=double 13 | ] 14 | and 15 | [ 16 | _Ty2=float 17 | ] 18 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\Source.cpp(51,9): message : see reference to function template instantiation 'std::pair::pair(_Other1,_Other2 &&) noexcept(false)' being compiled 19 | with 20 | [ 21 | _Other1=const char (&)[7], 22 | _Other2=double 23 | ] 24 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\Source.cpp(50,42): message : see the first reference to 'std::pair::pair' in 'main' 25 | decentralizedMG.vcxproj -> D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\x64\Debug\Decentralized.exe 26 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/decentralizedMG.vcxproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\MasterWork\Codes\MicrogridOptimization\MultiMG\Decentralized\x64\Debug\Decentralized.exe 2 | -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/vc143.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/vc143.idb -------------------------------------------------------------------------------- /MultiMG/Decentralized/x64/Debug/vc143.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/Decentralized/x64/Debug/vc143.pdb -------------------------------------------------------------------------------- /MultiMG/a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/MultiMG/a.png -------------------------------------------------------------------------------- /SingleMG/README.md: -------------------------------------------------------------------------------- 1 | # MicrogridOptimization 2 | 3 | 4 | 5 | 6 | ### References: 7 | - LP-based Mathematical Model for Optimal Microgrid Operation Considering Heat Trade with District Heat System, https://gvpress.com/journals/IJEIC/vol4_no4/2.pdf 8 | - Optimal Operation of Networked Microgrids for Enhancing Resilience Using Mobile Electric Vehicles, https://www.mdpi.com/1996-1073/14/1/142 9 | - Optimal scheduling of combined cooling, heating, and power system-based microgrid coupled with carbon capture storage system https://www.sciencedirect.com/science/article/abs/pii/S2352152X23001433 10 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/SingleMG_ElecHeatCoolNetAndEV.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34024.191 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "Project1.vcxproj", "{92FC16A1-661B-40D1-833F-FA53A83C04DF}" 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 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x64.ActiveCfg = Debug|x64 17 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x64.Build.0 = Debug|x64 18 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x86.ActiveCfg = Debug|Win32 19 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x86.Build.0 = Debug|Win32 20 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x64.ActiveCfg = Release|x64 21 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x64.Build.0 = Release|x64 22 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x86.ActiveCfg = Release|Win32 23 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {89DA0DA7-D26C-4CE9-B98A-A7D76BE1D820} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/SingleMG_ElecHeatCoolNetAndEV.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 | 17.0 23 | Win32Proj 24 | {92fc16a1-661b-40d1-833f-fa53a83c04df} 25 | Project1 26 | 10.0 27 | SingleMG_ElectHeatCoolNetAndEv 28 | 29 | 30 | 31 | Application 32 | true 33 | v143 34 | Unicode 35 | 36 | 37 | Application 38 | false 39 | v143 40 | true 41 | Unicode 42 | 43 | 44 | Application 45 | true 46 | v143 47 | Unicode 48 | 49 | 50 | Application 51 | false 52 | v143 53 | true 54 | Unicode 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Level3 77 | true 78 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 79 | true 80 | 81 | 82 | Console 83 | true 84 | 85 | 86 | 87 | 88 | Level3 89 | true 90 | true 91 | true 92 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | true 99 | true 100 | 101 | 102 | 103 | 104 | Level3 105 | true 106 | WIN64;_CONSOLE;IL_STD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 107 | true 108 | C:\Program Files\IBM\ILOG\CPLEX_Studio221\concert\include;C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\include;%(AdditionalIncludeDirectories) 109 | MultiThreadedDLL 110 | 111 | 112 | Console 113 | true 114 | C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\lib\x64_windows_msvc14\stat_mda\cplex2210.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\lib\x64_windows_msvc14\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio221\concert\lib\x64_windows_msvc14\stat_mda\concert.lib;%(AdditionalDependencies) 115 | 116 | 117 | 118 | 119 | Level3 120 | true 121 | true 122 | true 123 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 124 | true 125 | 126 | 127 | Console 128 | true 129 | true 130 | true 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/SingleMG_ElecHeatCoolNetAndEV.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;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 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/SingleMG_ElecHeatCoolNetAndEV.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/Source.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | ILOSTLBEGIN 7 | 8 | 9 | typedef IloArray NumVar2D; 10 | 11 | int 12 | main(int, char**) 13 | { 14 | 15 | auto start = chrono::high_resolution_clock::now(); 16 | IloEnv env; 17 | IloModel model(env); 18 | 19 | 20 | #pragma region Microgrid Input Data 21 | 22 | // Some Constants 23 | 24 | 25 | int T = 24; //One day 26 | int numEvs = 5; // Total Nmber of Electric vehicles 27 | 28 | map int_constant = { 29 | {"Cdg1", 135}, 30 | {"Cdg2", 140}, 31 | {"Chob", 80}, 32 | {"Cchp1", 150}, 33 | {"Cchp2", 145}, 34 | {"Pbmax", 150}, 35 | {"Hssmax", 50}, 36 | }; 37 | 38 | 39 | map float_constant = { 40 | {"socini", 0.2}, 41 | {"effin", 0.95}, 42 | {"Eveffin", 0.90}, 43 | {"k1", 1.2}, 44 | {"k2", 0.8}, 45 | {"Heffin", 0.95} 46 | }; 47 | 48 | 49 | // Arrival and Departure time of Evs 50 | int* ta = new int[numEvs] {2,4,6,9,9}; 51 | int* td = new int[numEvs] {6, 7, 9, 12, 16}; 52 | float* evsocini = new float[numEvs] {0.30,0.20,0.10,0.70,0.40}; 53 | float* evcap = new float[numEvs] {38.3, 47.5, 28.9, 56, 52}; 54 | 55 | // Electric and Heat Demand 56 | //int* Pload = new int[T] {169, 175, 179, 171, 181, 172, 270, 264, 273, 281, 193, 158, 161, 162, 250, 260, 267, 271, 284, 167, 128, 134, 144, 150}; //Electicity demand w.r.t tim 57 | int* Pload = new int[T] {169, 175, 179, 171, 181, 190, 270, 264, 273, 281, 300, 320, 280, 260, 250, 200, 180, 190, 240, 280, 325, 350, 300, 250}; //Electicity demand w.r.t tim 58 | int* Hload = new int[T] {130, 125, 120, 120, 125, 135, 150, 160, 175, 190, 195, 200, 195, 195, 180, 170, 185, 190, 195, 200, 195, 190, 180, 175}; //Heat Demand 59 | int* Cload = new int[T] {100, 100, 80, 100, 120, 135, 150, 135, 125, 130, 140, 150, 150, 130, 120, 110, 90, 80, 135, 150, 135, 140, 110, 125}; //Heat Demand 60 | 61 | 62 | // Trading Prices Electric and Heat 63 | int* CGbuy = new int[T] { 138, 139, 143, 149, 150, 152, 155, 158, 160, 154, 153, 153, 152, 150, 149, 149, 154, 156, 163, 164, 164, 160, 150, 148}; //buying price of electricity 64 | int* CGsell = new int[T] { 128, 129, 133, 139, 140, 142, 145, 148, 150, 144, 143, 143, 142, 140, 139, 139, 144, 146, 153, 154, 154, 150, 140, 138}; //selling price of electricity 65 | int* CHbuy = new int[T] {77, 77, 77, 77, 77, 77, 77, 77, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 78, 78, 78, 78, 78, 78}; // buying price of heat 66 | int* CHsell = new int[T] {75, 75, 75, 75, 75, 75, 75, 75, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 78, 78, 78, 78, 78, 78 }; // selling price of heat 67 | 68 | // Renewable Infeeds 69 | float* Rdg1 = new float[T] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10, 15, 20, 23, 28, 33, 35, 34, 31, 28, 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; //Power generated by PV w.r.t time 70 | //float* Rdg2 = new float[T] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10, 15, 20, 23, 28, 33, 35, 34, 31, 28, 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; //Power generated by PV w.r.t time 71 | 72 | #pragma endregion 73 | 74 | 75 | #pragma region Decision Variables 76 | 77 | IloNumVarArray PGbuy(env, T, 0, IloInfinity);//Grid power bought 78 | IloNumVarArray PGsell(env, T, 0, IloInfinity);//Grid power sold 79 | 80 | IloNumVarArray HGbuy(env, T, 0, IloInfinity, ILOINT);//Grid Heat bought 81 | IloNumVarArray HGsell(env, T, 0, IloInfinity, ILOINT);//Grid Heat sold 82 | 83 | 84 | IloNumVarArray statoc(env, T, 0, 1); //battery storage capacity 85 | IloNumVarArray Bchg(env, T, 0, 100); //battery charging 86 | IloNumVarArray Bdischg(env, T, 0, 100); //battery discharging 87 | 88 | IloNumVarArray HSSsoc(env, T, 0, 1); //battery storage capacity 89 | IloNumVarArray Hchg(env, T, 0, 50, ILOINT); //battery charging 90 | IloNumVarArray Hdischg(env, T, 0, 50, ILOINT); //battery discharging 91 | 92 | IloNumVarArray Pdg1(env, T, 0, 100,ILOINT); //DGA power generation range 93 | IloNumVarArray Pdg2(env, T, 0, 80, ILOINT); //DGA power generation range 94 | IloNumVarArray Pchp1(env, T, 30, 60,ILOINT); //CHP1 power generation range 95 | IloNumVarArray Pchp2(env, T, 50, 100, ILOINT); //CHP2 power generation range 96 | 97 | 98 | IloNumVarArray Hhob(env, T, 0, 80, ILOINT); //HOB heat power generation range 99 | IloNumVarArray Hchp1(env, T, 0, IloInfinity); //CHP1 heat power generation range 100 | IloNumVarArray Hchp2(env, T, 0, IloInfinity); //CHP2 heat generation range 101 | IloNumVarArray Hac(env, T, 0, IloInfinity); // AC 102 | IloNumVarArray Pec(env, T, 0, IloInfinity); // Electric Chiller 103 | 104 | 105 | // Electric Vehicles Decision Variables 106 | NumVar2D Pevchg(env, numEvs); 107 | NumVar2D Pevdischg(env, numEvs); 108 | NumVar2D evsoc(env, numEvs); 109 | 110 | for (int n = 0; n < numEvs; n++) 111 | { 112 | Pevchg[n] = IloNumVarArray(env, T, 0, evcap[n],ILOFLOAT); 113 | Pevdischg[n] = IloNumVarArray(env, T, 0, evcap[n], ILOFLOAT); 114 | evsoc[n] = IloNumVarArray(env, T, 0, 1, ILOFLOAT); 115 | } 116 | 117 | #pragma endregion 118 | 119 | 120 | #pragma region Objective Function 121 | 122 | IloExpr objective(env, T); 123 | 124 | 125 | for (int t = 0; t < T; t++) 126 | { 127 | objective += int_constant["Cdg1"] * Pdg1[t] + int_constant["Cdg2"] * Pdg2[t] + CGbuy[t] * PGbuy[t] - CGsell[t] * PGsell[t] + CHbuy[t] * HGbuy[t] - CHsell[t] * HGsell[t] + int_constant["Chob"] * Hhob[t] + int_constant["Cchp1"] * Pchp1[t] + int_constant["Cchp2"] * Pchp2[t]; 128 | } 129 | 130 | 131 | // Objective: minimize cost 132 | model.add(IloMinimize(env, objective)); 133 | 134 | #pragma endregion 135 | 136 | 137 | 138 | #pragma region Constraints 139 | 140 | 141 | // Constraint: meet demand 142 | 143 | for (int t = 0; t < T; t++) 144 | { 145 | 146 | model.add(0 <= Pdg1[t]); 147 | model.add(Pdg1[t] <= 100); 148 | 149 | model.add(0 <= Pdg2[t]); 150 | model.add(Pdg2[t] <= 80); 151 | 152 | model.add(0 <= Hhob[t]); 153 | model.add(Hhob[t] <= 80); 154 | 155 | model.add(30 <= Pchp1[t]); 156 | model.add(Pchp1[t] <= 60); 157 | 158 | model.add(50 <= Pchp2[t]); 159 | model.add(Pchp2[t] <= 100); 160 | 161 | model.add(Hchp1[t] == (float_constant["k1"]) * Pchp1[t]); 162 | model.add(Hchp2[t] == (float_constant["k2"]) * Pchp2[t]); 163 | 164 | model.add(0 <= HSSsoc[t]); 165 | model.add(HSSsoc[t] <= 1); 166 | 167 | for (int n = 0; n < numEvs; n++) 168 | { 169 | 170 | // soc bounds 171 | model.add(0 <= evsoc[n][t]); 172 | model.add(evsoc[n][t] <= 1); 173 | 174 | // Ev battery Constraints 175 | if (t == ta[n]) 176 | { 177 | model.add(evsoc[n][t] == evsocini[n] + (float_constant["Eveffin"] * Pevchg[n][t] - Pevdischg[n][t]/ float_constant["Eveffin"])/evcap[n]); 178 | model.add(0 <= Pevchg[n][t]); 179 | model.add(0 <= Pevdischg[n][t]); 180 | model.add(Pevchg[n][t] <= (evcap[n] * (1 - evsocini[n]) / float_constant["Eveffin"])); 181 | model.add(Pevdischg[n][t] <= (evcap[n] * evsocini[n] * float_constant["Eveffin"])); 182 | } 183 | else if (t > ta[n] && t <= td[n]) 184 | 185 | { 186 | model.add(evsoc[n][t] == evsoc[n][t - 1] + ((float_constant["Eveffin"] * Pevchg[n][t] - (Pevdischg[n][t] / float_constant["Eveffin"])) / evcap[n])); 187 | model.add(0 <= Pevchg[n][t]); 188 | model.add(0 <= Pevdischg[n][t]); 189 | model.add(Pevchg[n][t] <= (evcap[n] * (1 - evsoc[n][t - 1])) / float_constant["Eveffin"]); 190 | model.add(Pevdischg[n][t] <= evcap[n] * evsoc[n][t - 1] * float_constant["Eveffin"]); 191 | 192 | 193 | if (t == td[n]) { model.add(evsoc[n][t] >= 0.5 ); } 194 | 195 | } 196 | else 197 | { 198 | 199 | model.add(Pevchg[n][t] == 0); 200 | model.add(Pevdischg[n][t] == 0); 201 | 202 | } 203 | 204 | } 205 | 206 | 207 | // Adding the HSS and BSS Constraints constraints 208 | model.add(0 <= statoc[t]); 209 | model.add(statoc[t] <= 1); 210 | 211 | 212 | if (t == 0) 213 | { 214 | model.add(statoc[t] == float_constant["socini"] + ((float_constant["effin"] * Bchg[t] - (Bdischg[t] / float_constant["effin"])) / int_constant["Pbmax"])); 215 | model.add(0 <= Bchg[t]); 216 | model.add(0 <= Bdischg[t]); 217 | model.add(Bchg[t] <= (int_constant["Pbmax"] * (1 - float_constant["socini"]) / float_constant["effin"])); 218 | model.add(Bdischg[t] <= (int_constant["Pbmax"] * float_constant["socini"] * float_constant["effin"])); 219 | 220 | 221 | model.add(HSSsoc[t] == 0.5 + ((float_constant["Heffin"] * Hchg[t] - (Hdischg[t] / float_constant["Heffin"])) / int_constant["Hssmax"])); 222 | model.add(0 <= Hchg[t]); 223 | model.add(0 <= Hdischg[t]); 224 | //model.add(0 == Hdischg[t] * Hchg[t]); 225 | model.add(Hchg[t] <= (int_constant["Hssmax"] * (1 - 0.5) / float_constant["Heffin"])); 226 | model.add(Hdischg[t] <= (int_constant["Hssmax"] * 0.5 * float_constant["Heffin"])); 227 | 228 | } 229 | else 230 | { 231 | model.add(statoc[t] == statoc[t - 1] + ((float_constant["effin"] * Bchg[t] - (Bdischg[t] / float_constant["effin"])) / int_constant["Pbmax"])); 232 | model.add(0 <= Bchg[t]); 233 | model.add(0 <= Bdischg[t]); 234 | model.add(Bchg[t] <= (int_constant["Pbmax"] * (1 - statoc[t - 1])) / float_constant["effin"]); 235 | model.add(Bdischg[t] <= int_constant["Pbmax"] * statoc[t - 1] * float_constant["effin"]); 236 | 237 | 238 | model.add(HSSsoc[t] == HSSsoc[t - 1] + ((float_constant["Heffin"] * Hchg[t] - (Hdischg[t] / float_constant["Heffin"])) / int_constant["Hssmax"])); 239 | model.add(0 <= Hchg[t]); 240 | model.add(0 <= Hdischg[t]); 241 | //model.add(0 == Hdischg[t] * Hchg[t]); 242 | model.add(Hchg[t] <= (int_constant["Hssmax"] * (1 - HSSsoc[t-1]) / float_constant["Heffin"])); 243 | model.add(Hdischg[t] <= (int_constant["Hssmax"] * HSSsoc[t - 1] * float_constant["Heffin"])); 244 | } 245 | 246 | 247 | // Preparing electric vehicles expression for the power balance equation 248 | IloExpr exp0(env); 249 | IloExpr exp1(env); 250 | for (int n = 0; n < numEvs; n++) 251 | { 252 | exp0 += Pevchg[n][t]; 253 | exp1 += Pevdischg[n][t]; 254 | } 255 | 256 | // Adding the Electric power balance constraint 257 | 258 | model.add(Pdg1[t] - Pec[t] + Pdg2[t] + Rdg1[t] + Pchp1[t] + Pchp2[t] + Bdischg[t] + exp1 - exp0 - Bchg[t] + PGbuy[t] - PGsell[t] == Pload[t]); 259 | 260 | model.add(Hhob[t] - Hac[t] + Hchp1[t] + Hchp2[t] + HGbuy[t] - HGsell[t] - Hchg[t] + Hdischg[t] == Hload[t]); 261 | 262 | model.add(0.85 * Hac[t] + 0.95 * Pec[t] == Cload[t]); 263 | 264 | } 265 | 266 | #pragma endregion 267 | 268 | 269 | #pragma region Results 270 | IloCplex cplex(env); 271 | cplex.extract(model); 272 | cplex.exportModel("ModelLP.lp"); 273 | cplex.setOut(env.getNullStream()); 274 | if (!cplex.solve()) { 275 | env.error() << "Failed" << endl; 276 | throw(-1); 277 | } 278 | double obj = cplex.getObjValue(); 279 | auto end = chrono::high_resolution_clock::now(); 280 | auto Elapsed = chrono::duration_cast(end - start); 281 | cout << "\n\n\t The elapsed time is: \t" << Elapsed.count() << endl; 282 | cout << "Solution status: " << cplex.getStatus() << endl; 283 | cout << "Minimized Objective Funtion : " << obj << endl; 284 | IloNum eps = cplex.getParam( 285 | IloCplex::Param::MIP::Tolerances::Integrality); 286 | #pragma endregion 287 | 288 | 289 | #pragma region StoringOutput 290 | 291 | // Create and open the CSV file for writing 292 | // Create and open the CSV file for writing 293 | std::ofstream outputFile("output.csv"); 294 | 295 | if (outputFile.is_open()) { 296 | // Write the header row 297 | outputFile << "Time,Pload+Pec,Hload+Hac,Cload,CGbuy,CGsell,CHsell,CHbuy,Rdg1,PGbuy/sell,statoc,Bchg/dischg,Pdg1,Pdg2,Pchp1,Pchp2,Hhob,Hchp1,Hchp2,HGbuy/sell,Hchg/dischg" ; 298 | for (int mg = 0; mg < numEvs; mg++) { 299 | outputFile << ",Pevchg/dischg" << mg + 1; 300 | } 301 | 302 | outputFile << std::endl; 303 | 304 | 305 | // Write the data rows 306 | for (int i = 0; i < T; i++) { 307 | outputFile << i + 1 << "," << Pload[i] + cplex.getValue(Pec[i]) <<","<::pair(_Other1,_Other2 &&) noexcept(false)' being compiled 19 | with 20 | [ 21 | _Other1=const char (&)[7], 22 | _Other2=double 23 | ] 24 | D:\MasterWork\Codes\MicrogridOptimization\SingleMG\SingleMG_ElecHeatCoolNetAndEV\Source.cpp(39,42): message : see the first reference to 'std::pair::pair' in 'main' 25 | SingleMG_ElecHeatCoolNetAndEV.vcxproj -> D:\MasterWork\Codes\MicrogridOptimization\SingleMG\SingleMG_ElecHeatCoolNetAndEV\x64\Debug\SingleMG_ElectHeatCoolNetAndEv.exe 26 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/SingleMG_ElecHeatCoolNetAndEV.vcxproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\MasterWork\Codes\MicrogridOptimization\SingleMG\SingleMG_ElecHeatCoolNetAndEV\x64\Debug\SingleMG_ElectHeatCoolNetAndEv.exe 2 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/SingleMG_ElectHeatCoolNetAndEv.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/SingleMG_ElectHeatCoolNetAndEv.exe -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/SingleMG_ElectHeatCoolNetAndEv.exe.recipe: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | D:\MasterWork\Codes\MicrogridOptimization\SingleMG\SingleMG_ElecHeatCoolNetAndEV\x64\Debug\SingleMG_ElectHeatCoolNetAndEv.exe 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/SingleMG_ElectHeatCoolNetAndEv.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/SingleMG_ElectHeatCoolNetAndEv.ilk -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/SingleMG_ElectHeatCoolNetAndEv.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/SingleMG_ElectHeatCoolNetAndEv.pdb -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/Source.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/Source.obj -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/vc143.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/vc143.idb -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/vc143.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/SingleMG/SingleMG_ElecHeatCoolNetAndEV/x64/Debug/vc143.pdb -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatNetAndEV/SingleMG_ElecHeatNetAndEV.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34024.191 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "Project1.vcxproj", "{92FC16A1-661B-40D1-833F-FA53A83C04DF}" 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 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x64.ActiveCfg = Debug|x64 17 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x64.Build.0 = Debug|x64 18 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x86.ActiveCfg = Debug|Win32 19 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x86.Build.0 = Debug|Win32 20 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x64.ActiveCfg = Release|x64 21 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x64.Build.0 = Release|x64 22 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x86.ActiveCfg = Release|Win32 23 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {89DA0DA7-D26C-4CE9-B98A-A7D76BE1D820} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatNetAndEV/SingleMG_ElecHeatNetAndEV.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 | 17.0 23 | Win32Proj 24 | {92fc16a1-661b-40d1-833f-fa53a83c04df} 25 | Project1 26 | 10.0 27 | SingleMG_ElectHeatNetAndEv 28 | 29 | 30 | 31 | Application 32 | true 33 | v143 34 | Unicode 35 | 36 | 37 | Application 38 | false 39 | v143 40 | true 41 | Unicode 42 | 43 | 44 | Application 45 | true 46 | v143 47 | Unicode 48 | 49 | 50 | Application 51 | false 52 | v143 53 | true 54 | Unicode 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Level3 77 | true 78 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 79 | true 80 | 81 | 82 | Console 83 | true 84 | 85 | 86 | 87 | 88 | Level3 89 | true 90 | true 91 | true 92 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | true 99 | true 100 | 101 | 102 | 103 | 104 | Level3 105 | true 106 | WIN64;_CONSOLE;IL_STD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 107 | true 108 | C:\Program Files\IBM\ILOG\CPLEX_Studio221\concert\include;C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\include;%(AdditionalIncludeDirectories) 109 | MultiThreadedDLL 110 | 111 | 112 | Console 113 | true 114 | C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\lib\x64_windows_msvc14\stat_mda\cplex2210.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\lib\x64_windows_msvc14\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio221\concert\lib\x64_windows_msvc14\stat_mda\concert.lib;%(AdditionalDependencies) 115 | 116 | 117 | 118 | 119 | Level3 120 | true 121 | true 122 | true 123 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 124 | true 125 | 126 | 127 | Console 128 | true 129 | true 130 | true 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatNetAndEV/SingleMG_ElecHeatNetAndEV.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;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 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatNetAndEV/SingleMG_ElecHeatNetAndEV.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElecHeatNetAndEV/Source.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | ILOSTLBEGIN 6 | 7 | 8 | typedef IloArray NumVar2D; 9 | 10 | int 11 | main(int, char**) 12 | { 13 | 14 | auto start = chrono::high_resolution_clock::now(); 15 | IloEnv env; 16 | IloModel model(env); 17 | 18 | 19 | #pragma region Microgrid Input Data 20 | 21 | // Some Constants 22 | int T = 24; //One day 23 | int Cdg1 = 135; //Cost for generating per kW power from dg 24 | int Cdg2 = 140; //Cost for generating per kW power from dg 25 | int Chob = 80; 26 | int Cchp1 = 150; 27 | int Cchp2 = 145; 28 | float socini = 0.2; //Initially charged battery 29 | int Pbmax = 100; //battery maximum capacity 30 | float effin = 0.95; //battery effciency 31 | float Eveffin = 0.90; //battery effciency 32 | float k1 = 1.2; //heat to electric ratio chp1 33 | float k2 = 0.8; //heat to electric ratio chp2 34 | float Heffin = 0.95; //battery effciency 35 | int Hssmax = 50; //battery maximum capacity 36 | int numEvs = 5; // Total Nmber of Electric vehicles 37 | 38 | 39 | // Arrival and Departure time of Evs 40 | int* ta = new int[numEvs] {2,4,6,9,9}; 41 | int* td = new int[numEvs] {6, 7, 9, 12, 16}; 42 | float* evsocini = new float[numEvs] {0.30,0.20,0.10,0.70,0.40}; 43 | float* evcap = new float[numEvs] {38.3, 47.5, 28.9, 56, 52}; 44 | 45 | // Electric and Heat Demand 46 | //int* Pload = new int[T] {169, 175, 179, 171, 181, 172, 270, 264, 273, 281, 193, 158, 161, 162, 250, 260, 267, 271, 284, 167, 128, 134, 144, 150}; //Electicity demand w.r.t tim 47 | int* Pload = new int[T] {169, 175, 179, 171, 181, 190, 270, 264, 273, 281, 300, 320, 280, 260, 250, 200, 180, 190, 240, 280, 325, 350, 300, 250}; //Electicity demand w.r.t tim 48 | int* Hload = new int[T] {130, 125, 120, 120, 125, 135, 150, 160, 175, 190, 195, 200, 195, 195, 180, 170, 185, 190, 195, 200, 195, 190, 180, 175}; //Heat Demand 49 | 50 | 51 | // Trading Prices Electric and Heat 52 | int* CGbuy = new int[T] { 138, 139, 143, 149, 150, 152, 155, 158, 160, 154, 153, 153, 152, 150, 149, 149, 154, 156, 163, 164, 164, 160, 150, 148}; //buying price of electricity 53 | int* CGsell = new int[T] { 128, 129, 133, 139, 140, 142, 145, 148, 150, 144, 143, 143, 142, 140, 139, 139, 144, 146, 153, 154, 154, 150, 140, 138}; //selling price of electricity 54 | int* CHbuy = new int[T] {77, 77, 77, 77, 77, 77, 77, 77, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 78, 78, 78, 78, 78, 78}; // buying price of heat 55 | int* CHsell = new int[T] {75, 75, 75, 75, 75, 75, 75, 75, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 78, 78, 78, 78, 78, 78 }; // selling price of heat 56 | 57 | // Renewable Infeeds 58 | float* Rdg1 = new float[T] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10, 15, 20, 23, 28, 33, 35, 34, 31, 28, 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; //Power generated by PV w.r.t time 59 | //float* Rdg2 = new float[T] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10, 15, 20, 23, 28, 33, 35, 34, 31, 28, 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; //Power generated by PV w.r.t time 60 | 61 | #pragma endregion 62 | 63 | 64 | #pragma region Decision Variables 65 | 66 | IloNumVarArray PGbuy(env, T, 0, IloInfinity);//Grid power bought 67 | IloNumVarArray PGsell(env, T, 0, IloInfinity);//Grid power sold 68 | 69 | IloNumVarArray HGbuy(env, T, 0, IloInfinity, ILOINT);//Grid Heat bought 70 | IloNumVarArray HGsell(env, T, 0, IloInfinity, ILOINT);//Grid Heat sold 71 | 72 | 73 | IloNumVarArray statoc(env, T, 0, 1); //battery storage capacity 74 | IloNumVarArray Bchg(env, T, 0, 100); //battery charging 75 | IloNumVarArray Bdischg(env, T, 0, 100); //battery discharging 76 | 77 | IloNumVarArray HSSsoc(env, T, 0, 1); //battery storage capacity 78 | IloNumVarArray Hchg(env, T, 0, 50,ILOINT); //battery charging 79 | IloNumVarArray Hdischg(env, T, 0, 50,ILOINT); //battery discharging 80 | 81 | IloNumVarArray Pdg1(env, T, 0, 100,ILOINT); //DGA power generation range 82 | IloNumVarArray Pdg2(env, T, 0, 80, ILOINT); //DGA power generation range 83 | IloNumVarArray Pchp1(env, T, 30, 60,ILOINT); //CHP1 power generation range 84 | IloNumVarArray Pchp2(env, T, 50, 100, ILOINT); //CHP2 power generation range 85 | 86 | 87 | IloNumVarArray Hhob(env, T, 0, 80, ILOINT); //HOB heat power generation range 88 | IloNumVarArray Hchp1(env, T, 0, IloInfinity); //CHP1 heat power generation range 89 | IloNumVarArray Hchp2(env, T, 0, IloInfinity); //CHP2 heat generation range 90 | 91 | // Electric Vehicles Decision Variables 92 | NumVar2D Pevchg(env, numEvs); 93 | NumVar2D Pevdischg(env, numEvs); 94 | NumVar2D evsoc(env, numEvs); 95 | 96 | for (int n = 0; n < numEvs; n++) 97 | { 98 | Pevchg[n] = IloNumVarArray(env, T, 0, evcap[n],ILOFLOAT); 99 | Pevdischg[n] = IloNumVarArray(env, T, 0, evcap[n], ILOFLOAT); 100 | evsoc[n] = IloNumVarArray(env, T, 0, 1, ILOFLOAT); 101 | } 102 | 103 | #pragma endregion 104 | 105 | 106 | #pragma region Objective Function 107 | 108 | IloExpr objective(env, T); 109 | 110 | 111 | for (int t = 0; t < T; t++) 112 | { 113 | objective += Cdg1 * Pdg1[t] + Cdg2 * Pdg2[t] + CGbuy[t] * PGbuy[t] - CGsell[t] * PGsell[t] + CHbuy[t] * HGbuy[t] - CHsell[t] * HGsell[t] + Chob * Hhob[t] 114 | + Cchp1 * Pchp1[t] + Cchp2 * Pchp2[t]; 115 | } 116 | 117 | 118 | // Objective: minimize cost 119 | model.add(IloMinimize(env, objective)); 120 | 121 | #pragma endregion 122 | 123 | 124 | 125 | #pragma region Constraints 126 | 127 | 128 | // Constraint: meet demand 129 | 130 | for (int t = 0; t < T; t++) 131 | { 132 | 133 | model.add(0 <= Pdg1[t]); 134 | model.add(Pdg1[t] <= 100); 135 | 136 | model.add(0 <= Pdg2[t]); 137 | model.add(Pdg2[t] <= 80); 138 | 139 | model.add(0 <= Hhob[t]); 140 | model.add(Hhob[t] <= 80); 141 | 142 | model.add(30 <= Pchp1[t]); 143 | model.add(Pchp1[t] <= 60); 144 | 145 | model.add(50 <= Pchp2[t]); 146 | model.add(Pchp2[t] <= 100); 147 | 148 | model.add(Hchp1[t] == (k1) * Pchp1[t]); 149 | model.add(Hchp2[t] == (k2) * Pchp2[t]); 150 | 151 | model.add(0 <= HSSsoc[t]); 152 | model.add(HSSsoc[t] <= 1); 153 | 154 | 155 | 156 | for (int n = 0; n < numEvs; n++) 157 | { 158 | 159 | // soc bounds 160 | model.add(0 <= evsoc[n][t]); 161 | model.add(evsoc[n][t] <= 1); 162 | 163 | // Ev battery Constraints 164 | if (t == ta[n]) 165 | { 166 | model.add(evsoc[n][t] == evsocini[n] + (Eveffin* Pevchg[n][t] - Pevdischg[n][t]/Eveffin)/evcap[n]); 167 | model.add(0 <= Pevchg[n][t]); 168 | model.add(0 <= Pevdischg[n][t]); 169 | model.add(Pevchg[n][t] <= (evcap[n] * (1 - evsocini[n]) / Eveffin)); 170 | model.add(Pevdischg[n][t] <= (evcap[n] * evsocini[n] * Eveffin)); 171 | } 172 | else if (t > ta[n] && t <= td[n]) 173 | 174 | { 175 | model.add(evsoc[n][t] == evsoc[n][t - 1] + ((Eveffin * Pevchg[n][t] - (Pevdischg[n][t] / effin)) / evcap[n])); 176 | model.add(0 <= Pevchg[n][t]); 177 | model.add(0 <= Pevdischg[n][t]); 178 | model.add(Pevchg[n][t] <= (evcap[n] * (1 - evsoc[n][t - 1])) / Eveffin); 179 | model.add(Pevdischg[n][t] <= evcap[n] * evsoc[n][t - 1] * Eveffin); 180 | 181 | 182 | if (t == td[n]) { model.add(evsoc[n][t] >= 0.5 ); } 183 | 184 | } 185 | else 186 | { 187 | 188 | model.add(Pevchg[n][t] == 0); 189 | model.add(Pevdischg[n][t] == 0); 190 | 191 | } 192 | 193 | } 194 | 195 | 196 | // Adding the Battery Constraints constraints 197 | model.add(0 <= statoc[t]); 198 | model.add(statoc[t] <= 1); 199 | if (t == 0) 200 | { 201 | model.add(statoc[t] == socini + ((effin * Bchg[t] - (Bdischg[t] / effin)) / Pbmax)); 202 | model.add(0 <= Bchg[t]); 203 | model.add(0 <= Bdischg[t]); 204 | model.add(Bchg[t] <= (Pbmax * (1 - socini) / effin)); 205 | model.add(Bdischg[t] <= (Pbmax * socini * effin)); 206 | 207 | model.add(HSSsoc[t] == 0.5 + ((Heffin * Hchg[t] - (Hdischg[t] / Heffin)) / Hssmax)); 208 | model.add(0 <= Hchg[t]); 209 | model.add(0 <= Hdischg[t]); 210 | //model.add(0 == Hdischg[t] * Hchg[t]); 211 | model.add(Hchg[t] <= (Hssmax * (1 - 0.5) / Heffin)); 212 | model.add(Hdischg[t] <= (Hssmax * 0.5 * Heffin)); 213 | 214 | 215 | } 216 | else 217 | { 218 | model.add(statoc[t] == statoc[t - 1] + ((effin * Bchg[t] - (Bdischg[t] / effin)) / Pbmax)); 219 | model.add(0 <= Bchg[t]); 220 | model.add(0 <= Bdischg[t]); 221 | model.add(Bchg[t] <= (Pbmax * (1 - statoc[t - 1])) / effin); 222 | model.add(Bdischg[t] <= Pbmax * statoc[t - 1] * effin); 223 | 224 | 225 | model.add(HSSsoc[t] == HSSsoc[t - 1] + ((Heffin * Hchg[t] - (Hdischg[t] / Heffin)) / Hssmax)); 226 | model.add(0 <= Hchg[t]); 227 | model.add(0 <= Hdischg[t]); 228 | //model.add(0 == Hdischg[t] * Hchg[t]); 229 | model.add(Hchg[t] <= (Hssmax * (1 - HSSsoc[t - 1]) / Heffin)); 230 | model.add(Hdischg[t] <= (Hssmax * HSSsoc[t - 1] * Heffin)); 231 | 232 | 233 | 234 | } 235 | 236 | 237 | // Preparing electric vehicles expression for the power balance equation 238 | IloExpr exp0(env); 239 | IloExpr exp1(env); 240 | for (int n = 0; n < numEvs; n++) 241 | { 242 | exp0 += Pevchg[n][t]; 243 | exp1 += Pevdischg[n][t]; 244 | } 245 | 246 | // Adding the Electric power balance constraint 247 | 248 | model.add(Pdg1[t] + Pdg2[t] + Rdg1[t] + Pchp1[t] + Pchp2[t] + Bdischg[t] + exp1 - exp0 - Bchg[t] + PGbuy[t] - PGsell[t] == Pload[t]); 249 | model.add(Hhob[t] + Hchp1[t] + Hchp2[t] + HGbuy[t] - HGsell[t] - Hchg[t] + Hdischg[t] == Hload[t]); 250 | 251 | 252 | } 253 | 254 | #pragma endregion 255 | 256 | 257 | #pragma region Results 258 | IloCplex cplex(env); 259 | cplex.extract(model); 260 | cplex.exportModel("ModelLP.lp"); 261 | cplex.setOut(env.getNullStream()); 262 | if (!cplex.solve()) { 263 | env.error() << "Failed" << endl; 264 | throw(-1); 265 | } 266 | double obj = cplex.getObjValue(); 267 | auto end = chrono::high_resolution_clock::now(); 268 | auto Elapsed = chrono::duration_cast(end - start); 269 | cout << "\n\n\t The elapsed time is: \t" << Elapsed.count() << endl; 270 | cout << "Solution status: " << cplex.getStatus() << endl; 271 | cout << "Minimized Objective Funtion : " << obj << endl; 272 | IloNum eps = cplex.getParam( 273 | IloCplex::Param::MIP::Tolerances::Integrality); 274 | #pragma endregion 275 | 276 | 277 | #pragma region StoringOutput 278 | 279 | // Create and open the CSV file for writing 280 | // Create and open the CSV file for writing 281 | std::ofstream outputFile("output.csv"); 282 | 283 | if (outputFile.is_open()) { 284 | // Write the header row 285 | outputFile << "Time,Pload,Hload,CGbuy,CGsell,CHsell,CHbuy,Rdg1,PGbuy,PGsell,statoc,Bchg,Bdischg,Pdg1,Pdg2,Pchp1,Pchp2,Hhob,Hchp1,Hchp2,HGbuy,HGsell,Hchg,Hdisch" ; 286 | for (int mg = 0; mg < numEvs; mg++) { 287 | outputFile << ",Pevchg" << mg + 1 << ",Pevdischg" << mg + 1; 288 | } 289 | 290 | outputFile << std::endl; 291 | 292 | 293 | // Write the data rows 294 | for (int i = 0; i < T; i++) { 295 | outputFile << i + 1 << "," << Pload[i] <<","< 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 | 17.0 23 | Win32Proj 24 | {92fc16a1-661b-40d1-833f-fa53a83c04df} 25 | Project1 26 | 10.0 27 | SingleMG_ElectAndHeatNet 28 | 29 | 30 | 31 | Application 32 | true 33 | v143 34 | Unicode 35 | 36 | 37 | Application 38 | false 39 | v143 40 | true 41 | Unicode 42 | 43 | 44 | Application 45 | true 46 | v143 47 | Unicode 48 | 49 | 50 | Application 51 | false 52 | v143 53 | true 54 | Unicode 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Level3 77 | true 78 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 79 | true 80 | 81 | 82 | Console 83 | true 84 | 85 | 86 | 87 | 88 | Level3 89 | true 90 | true 91 | true 92 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | true 99 | true 100 | 101 | 102 | 103 | 104 | Level3 105 | true 106 | WIN64;_CONSOLE;IL_STD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 107 | true 108 | C:\Program Files\IBM\ILOG\CPLEX_Studio221\concert\include;C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\include;%(AdditionalIncludeDirectories) 109 | MultiThreadedDLL 110 | 111 | 112 | Console 113 | true 114 | C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\lib\x64_windows_msvc14\stat_mda\cplex2210.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\lib\x64_windows_msvc14\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio221\concert\lib\x64_windows_msvc14\stat_mda\concert.lib;%(AdditionalDependencies) 115 | 116 | 117 | 118 | 119 | Level3 120 | true 121 | true 122 | true 123 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 124 | true 125 | 126 | 127 | Console 128 | true 129 | true 130 | true 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElectAndHeatNet/SingleMG_ElectAndHeatNet.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;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 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElectAndHeatNet/SingleMG_ElectAndHeatNet.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElectAndHeatNet/Source.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | ILOSTLBEGIN 6 | 7 | 8 | int main(int, char**) 9 | { 10 | 11 | auto start = chrono::high_resolution_clock::now(); 12 | IloEnv env; 13 | IloModel model(env); 14 | 15 | 16 | #pragma region Microgrid Input Data 17 | 18 | // Some Constants 19 | int T = 24; //One day 20 | int Cdg1 = 135; //Cost for generating per kW power from dg 21 | int Cdg2 = 140; //Cost for generating per kW power from dg 22 | int Chob = 80; 23 | int Cchp1 = 150; 24 | int Cchp2 = 145; 25 | float socini = 0.2; //Initially charged battery 26 | int Pbmax = 100; //battery maximum capacity 27 | float effin = 0.95; //battery effciency 28 | float k1 = 1.2; //heat to electric ratio chp1 29 | float k2 = 0.8; //heat to electric ratio chp2 30 | float Heffin = 0.95; //battery effciency 31 | int Hssmax = 50; //battery maximum capacity 32 | 33 | // Electric and Heat Demand 34 | int* Pload = new int[T] {169, 175, 179, 171, 181, 190, 270, 264, 273, 281, 300, 320, 280, 260, 250, 200, 180, 190, 240, 280, 325, 350, 300, 250}; //Electicity demand w.r.t tim 35 | int* Hload = new int[T] {130, 125, 120, 120, 125, 135, 150, 160, 175, 190, 195, 200, 195, 195, 180, 170, 185, 190, 195, 200, 195, 190, 180, 175}; //Heat Demand 36 | 37 | 38 | // Trading Prices Electric and Heat 39 | int* CGbuy = new int[T] { 138, 139, 143, 149, 150, 152, 155, 158, 160, 154, 153, 153, 152, 150, 149, 149, 154, 156, 163, 164, 164, 160, 150, 148}; //buying price of electricity 40 | int* CGsell = new int[T] { 128, 129, 133, 139, 140, 142, 145, 148, 150, 144, 143, 143, 142, 140, 139, 139, 144, 146, 153, 154, 154, 150, 140, 138}; //selling price of electricity 41 | int* CHbuy = new int[T] {77, 77, 77, 77, 77, 77, 77, 77, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 78, 78, 78, 78, 78, 78}; // buying price of heat 42 | int* CHsell = new int[T] {75, 75, 75, 75, 75, 75, 75, 75, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 78, 78, 78, 78, 78, 78 }; // selling price of heat 43 | 44 | // Renewable Infeeds 45 | float* Rdg1 = new float[T] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10, 15, 20, 23, 28, 33, 35, 34, 31, 28, 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; //Power generated by PV w.r.t time 46 | //float* Rdg2 = new float[T] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10, 15, 20, 23, 28, 33, 35, 34, 31, 28, 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; //Power generated by PV w.r.t time 47 | 48 | #pragma endregion 49 | 50 | 51 | #pragma region Decision Variables 52 | 53 | IloNumVarArray PGbuy(env, T, 0, IloInfinity);//Grid power bought 54 | IloNumVarArray PGsell(env, T, 0, IloInfinity);//Grid power sold 55 | 56 | IloNumVarArray HGbuy(env, T, 0, IloInfinity, ILOINT);//Grid Heat bought 57 | IloNumVarArray HGsell(env, T, 0, IloInfinity, ILOINT);//Grid Heat sold 58 | 59 | 60 | IloNumVarArray statoc(env, T, 0, 1); //battery storage capacity 61 | IloNumVarArray Bchg(env, T, 0, 50); //battery charging 62 | IloNumVarArray Bdischg(env, T, 0, 50); //battery discharging 63 | 64 | IloNumVarArray HSSsoc(env, T, 0, 1); //battery storage capacity 65 | IloNumVarArray Hchg(env, T, 0, 50,ILOINT); //battery charging 66 | IloNumVarArray Hdischg(env, T, 0, 50,ILOINT); //battery discharging 67 | 68 | IloNumVarArray Pdg1(env, T, 0, 100,ILOINT); //DGA power generation range 69 | IloNumVarArray Pdg2(env, T, 0, 80, ILOINT); //DGA power generation range 70 | IloNumVarArray Pchp1(env, T, 30, 60,ILOINT); //CHP1 power generation range 71 | IloNumVarArray Pchp2(env, T, 50, 100, ILOINT); //CHP2 power generation range 72 | 73 | 74 | IloNumVarArray Hhob(env, T, 0, 80, ILOINT); //HOB heat power generation range 75 | IloNumVarArray Hchp1(env, T, 0, IloInfinity); //CHP1 heat power generation range 76 | IloNumVarArray Hchp2(env, T, 0, IloInfinity); //CHP2 heat generation range 77 | 78 | #pragma endregion 79 | 80 | 81 | #pragma region Objective Function 82 | 83 | IloExpr objective(env, T); 84 | 85 | 86 | for (int t = 0; t < T; t++) 87 | { 88 | objective += Cdg1 * Pdg1[t] + Cdg2 * Pdg2[t] + CGbuy[t] * PGbuy[t] - CGsell[t] * PGsell[t] + CHbuy[t] * HGbuy[t] - CHsell[t] * HGsell[t] + Chob * Hhob[t] 89 | + Cchp1 * Pchp1[t] + Cchp2 * Pchp2[t]; 90 | } 91 | 92 | 93 | // Objective: minimize cost 94 | model.add(IloMinimize(env, objective)); 95 | 96 | #pragma endregion 97 | 98 | 99 | 100 | #pragma region Constraints 101 | 102 | 103 | // Constraint: meet demand 104 | 105 | for (int t = 0; t < T; t++) 106 | { 107 | 108 | model.add(0 <= Pdg1[t]); 109 | model.add(Pdg1[t] <= 100); 110 | 111 | model.add(0 <= Pdg2[t]); 112 | model.add(Pdg2[t] <= 80); 113 | 114 | model.add(0 <= Hhob[t]); 115 | model.add(Hhob[t] <= 80); 116 | 117 | model.add(30 <= Pchp1[t]); 118 | model.add(Pchp1[t] <= 60); 119 | 120 | model.add(50 <= Pchp2[t]); 121 | model.add(Pchp2[t] <= 100); 122 | 123 | model.add(Hchp1[t] == (k1) * Pchp1[t]); 124 | model.add(Hchp2[t] == (k2) * Pchp2[t]); 125 | 126 | 127 | 128 | // Adding the Battery Constraints constraints 129 | model.add(0 <= statoc[t]); 130 | model.add(statoc[t] <= 1); 131 | model.add(0 <= HSSsoc[t]); 132 | model.add(HSSsoc[t] <= 1); 133 | 134 | 135 | if (t == 0) 136 | { 137 | model.add(statoc[t] == socini + ((effin * Bchg[t] - (Bdischg[t] / effin)) / Pbmax)); 138 | model.add(0 <= Bchg[t]); 139 | model.add(0 <= Bdischg[t]); 140 | model.add(Bchg[t] <= (Pbmax * (1 - socini) / effin)); 141 | model.add(Bdischg[t] <= (Pbmax * socini * effin)); 142 | 143 | 144 | model.add(HSSsoc[t] == 0.5 + ((Heffin * Hchg[t] - (Hdischg[t] / Heffin)) / Hssmax)); 145 | model.add(0 <= Hchg[t]); 146 | model.add(0 <= Hdischg[t]); 147 | //model.add(0 == Hdischg[t] * Hchg[t]); 148 | model.add(Hchg[t] <= (Hssmax * (1 - 0.5) / Heffin)); 149 | model.add(Hdischg[t] <= (Hssmax * 0.5 * Heffin)); 150 | 151 | } 152 | else 153 | { 154 | model.add(statoc[t] == statoc[t - 1] + ((effin * Bchg[t] - (Bdischg[t] / effin)) / Pbmax)); 155 | model.add(0 <= Bchg[t]); 156 | model.add(0 <= Bdischg[t]); 157 | model.add(Bchg[t] <= (Pbmax * (1 - statoc[t - 1])) / effin); 158 | model.add(Bdischg[t] <= Pbmax * statoc[t - 1] * effin); 159 | 160 | model.add(HSSsoc[t] == HSSsoc[t - 1] + ((Heffin * Hchg[t] - (Hdischg[t] / Heffin)) / Hssmax)); 161 | model.add(0 <= Hchg[t]); 162 | model.add(0 <= Hdischg[t]); 163 | //model.add(0 == Hdischg[t] * Hchg[t]); 164 | model.add(Hchg[t] <= (Hssmax * (1 - HSSsoc[t - 1]) / Heffin)); 165 | model.add(Hdischg[t] <= (Hssmax * HSSsoc[t - 1] * Heffin)); 166 | 167 | } 168 | 169 | // Adding the Electric power balance constraint 170 | model.add(Pdg1[t] + Pdg2[t] + Rdg1[t]+ Pchp1[t] + Pchp2[t] + Bdischg[t] - Bchg[t] + PGbuy[t] - PGsell[t] == Pload[t]); 171 | 172 | model.add(Hhob[t] + Hchp1[t] + Hchp2[t] + HGbuy[t] - HGsell[t] - Hchg[t] + Hdischg[t] == Hload[t]); 173 | 174 | 175 | } 176 | 177 | #pragma endregion 178 | 179 | 180 | #pragma region Results 181 | IloCplex cplex(env); 182 | cplex.extract(model); 183 | cplex.exportModel("ModelLP.lp"); 184 | cplex.setOut(env.getNullStream()); 185 | if (!cplex.solve()) { 186 | env.error() << "Failed" << endl; 187 | throw(-1); 188 | } 189 | double obj = cplex.getObjValue(); 190 | auto end = chrono::high_resolution_clock::now(); 191 | auto Elapsed = chrono::duration_cast(end - start); 192 | cout << "\n\n\t The elapsed time is: \t" << Elapsed.count() << endl; 193 | cout << "Solution status: " << cplex.getStatus() << endl; 194 | cout << "Minimized Objective Funtion : " << obj << endl; 195 | IloNum eps = cplex.getParam( 196 | IloCplex::Param::MIP::Tolerances::Integrality); 197 | #pragma endregion 198 | 199 | 200 | #pragma region StoringOutput 201 | 202 | // Create and open the CSV file for writing 203 | std::ofstream outputFile("output.csv"); 204 | 205 | if (outputFile.is_open()) { 206 | // Write the header row 207 | outputFile << "Time,Pload,Hload,CGbuy,CGsell,CHsell,CHbuy,Rdg1,PGbuy,PGsell,statoc,Bchg,Bdischg,Pdg1,Pdg2,Pchp1,Pchp2,Hhob,Hchp1,Hchp2,HGbuy,HGsell,Hchg,Hdisch" << std::endl; 208 | 209 | // Write the data rows 210 | for (int i = 0; i < T; i++) { 211 | outputFile << i + 1 << "," << Pload[i] <<","<= 0 21 | c2: x1 <= 80 22 | c3: x2 >= 0 23 | c4: x2 <= 90 24 | c5: x97 >= 0 25 | c6: x97 <= 1 26 | c7: x97 - 0.00474999994039536 x98 + 0.00526315796078077 x99 27 | = 0.200000002980232 28 | c8: x98 >= 0 29 | c9: x99 >= 0 30 | c10: x98 <= 168.421051025391 31 | c11: x99 <= 38 32 | c12: x1 + x2 + x3 - x4 - x98 + x99 = 169 33 | c13: x5 >= 0 34 | c14: x5 <= 80 35 | c15: x6 >= 0 36 | c16: x6 <= 90 37 | c17: x100 >= 0 38 | c18: x100 <= 1 39 | c19: - x97 + x100 - 0.00474999994039536 x101 + 0.00526315796078077 x102 = 0 40 | c20: x101 >= 0 41 | c21: x102 >= 0 42 | c22: 210.526318431231 x97 + x101 <= 210.526318431231 43 | c23: - 189.999997615814 x97 + x102 <= 0 44 | c24: x5 + x6 + x7 - x8 - x101 + x102 = 175 45 | c25: x9 >= 0 46 | c26: x9 <= 80 47 | c27: x10 >= 0 48 | c28: x10 <= 90 49 | c29: x103 >= 0 50 | c30: x103 <= 1 51 | c31: - x100 + x103 - 0.00474999994039536 x104 + 0.00526315796078077 x105 = 0 52 | c32: x104 >= 0 53 | c33: x105 >= 0 54 | c34: 210.526318431231 x100 + x104 <= 210.526318431231 55 | c35: - 189.999997615814 x100 + x105 <= 0 56 | c36: x9 + x10 + x11 - x12 - x104 + x105 = 179 57 | c37: x13 >= 0 58 | c38: x13 <= 80 59 | c39: x14 >= 0 60 | c40: x14 <= 90 61 | c41: x106 >= 0 62 | c42: x106 <= 1 63 | c43: - x103 + x106 - 0.00474999994039536 x107 + 0.00526315796078077 x108 = 0 64 | c44: x107 >= 0 65 | c45: x108 >= 0 66 | c46: 210.526318431231 x103 + x107 <= 210.526318431231 67 | c47: - 189.999997615814 x103 + x108 <= 0 68 | c48: x13 + x14 + x15 - x16 - x107 + x108 = 171 69 | c49: x17 >= 0 70 | c50: x17 <= 80 71 | c51: x18 >= 0 72 | c52: x18 <= 90 73 | c53: x109 >= 0 74 | c54: x109 <= 1 75 | c55: - x106 + x109 - 0.00474999994039536 x110 + 0.00526315796078077 x111 = 0 76 | c56: x110 >= 0 77 | c57: x111 >= 0 78 | c58: 210.526318431231 x106 + x110 <= 210.526318431231 79 | c59: - 189.999997615814 x106 + x111 <= 0 80 | c60: x17 + x18 + x19 - x20 - x110 + x111 = 181 81 | c61: x21 >= 0 82 | c62: x21 <= 80 83 | c63: x22 >= 0 84 | c64: x22 <= 90 85 | c65: x112 >= 0 86 | c66: x112 <= 1 87 | c67: - x109 + x112 - 0.00474999994039536 x113 + 0.00526315796078077 x114 = 0 88 | c68: x113 >= 0 89 | c69: x114 >= 0 90 | c70: 210.526318431231 x109 + x113 <= 210.526318431231 91 | c71: - 189.999997615814 x109 + x114 <= 0 92 | c72: x21 + x22 + x23 - x24 - x113 + x114 = 172 93 | c73: x25 >= 0 94 | c74: x25 <= 80 95 | c75: x26 >= 0 96 | c76: x26 <= 90 97 | c77: x115 >= 0 98 | c78: x115 <= 1 99 | c79: - x112 + x115 - 0.00474999994039536 x116 + 0.00526315796078077 x117 = 0 100 | c80: x116 >= 0 101 | c81: x117 >= 0 102 | c82: 210.526318431231 x112 + x116 <= 210.526318431231 103 | c83: - 189.999997615814 x112 + x117 <= 0 104 | c84: x25 + x26 + x27 - x28 - x116 + x117 = 270 105 | c85: x29 >= 0 106 | c86: x29 <= 80 107 | c87: x30 >= 0 108 | c88: x30 <= 90 109 | c89: x118 >= 0 110 | c90: x118 <= 1 111 | c91: - x115 + x118 - 0.00474999994039536 x119 + 0.00526315796078077 x120 = 0 112 | c92: x119 >= 0 113 | c93: x120 >= 0 114 | c94: 210.526318431231 x115 + x119 <= 210.526318431231 115 | c95: - 189.999997615814 x115 + x120 <= 0 116 | c96: x29 + x30 + x31 - x32 - x119 + x120 = 244 117 | c97: x33 >= 0 118 | c98: x33 <= 80 119 | c99: x34 >= 0 120 | c100: x34 <= 90 121 | c101: x121 >= 0 122 | c102: x121 <= 1 123 | c103: - x118 + x121 - 0.00474999994039536 x122 + 0.00526315796078077 x123 = 0 124 | c104: x122 >= 0 125 | c105: x123 >= 0 126 | c106: 210.526318431231 x118 + x122 <= 210.526318431231 127 | c107: - 189.999997615814 x118 + x123 <= 0 128 | c108: x33 + x34 + x35 - x36 - x122 + x123 = 243 129 | c109: x37 >= 0 130 | c110: x37 <= 80 131 | c111: x38 >= 0 132 | c112: x38 <= 90 133 | c113: x124 >= 0 134 | c114: x124 <= 1 135 | c115: - x121 + x124 - 0.00474999994039536 x125 + 0.00526315796078077 x126 = 0 136 | c116: x125 >= 0 137 | c117: x126 >= 0 138 | c118: 210.526318431231 x121 + x125 <= 210.526318431231 139 | c119: - 189.999997615814 x121 + x126 <= 0 140 | c120: x37 + x38 + x39 - x40 - x125 + x126 = 241 141 | c121: x41 >= 0 142 | c122: x41 <= 80 143 | c123: x42 >= 0 144 | c124: x42 <= 90 145 | c125: x127 >= 0 146 | c126: x127 <= 1 147 | c127: - x124 + x127 - 0.00474999994039536 x128 + 0.00526315796078077 x129 = 0 148 | c128: x128 >= 0 149 | c129: x129 >= 0 150 | c130: 210.526318431231 x124 + x128 <= 210.526318431231 151 | c131: - 189.999997615814 x124 + x129 <= 0 152 | c132: x41 + x42 + x43 - x44 - x128 + x129 = 147 153 | c133: x45 >= 0 154 | c134: x45 <= 80 155 | c135: x46 >= 0 156 | c136: x46 <= 90 157 | c137: x130 >= 0 158 | c138: x130 <= 1 159 | c139: - x127 + x130 - 0.00474999994039536 x131 + 0.00526315796078077 x132 = 0 160 | c140: x131 >= 0 161 | c141: x132 >= 0 162 | c142: 210.526318431231 x127 + x131 <= 210.526318431231 163 | c143: - 189.999997615814 x127 + x132 <= 0 164 | c144: x45 + x46 + x47 - x48 - x131 + x132 = 102 165 | c145: x49 >= 0 166 | c146: x49 <= 80 167 | c147: x50 >= 0 168 | c148: x50 <= 90 169 | c149: x133 >= 0 170 | c150: x133 <= 1 171 | c151: - x130 + x133 - 0.00474999994039536 x134 + 0.00526315796078077 x135 = 0 172 | c152: x134 >= 0 173 | c153: x135 >= 0 174 | c154: 210.526318431231 x130 + x134 <= 210.526318431231 175 | c155: - 189.999997615814 x130 + x135 <= 0 176 | c156: x49 + x50 + x51 - x52 - x134 + x135 = 95 177 | c157: x53 >= 0 178 | c158: x53 <= 80 179 | c159: x54 >= 0 180 | c160: x54 <= 90 181 | c161: x136 >= 0 182 | c162: x136 <= 1 183 | c163: - x133 + x136 - 0.00474999994039536 x137 + 0.00526315796078077 x138 = 0 184 | c164: x137 >= 0 185 | c165: x138 >= 0 186 | c166: 210.526318431231 x133 + x137 <= 210.526318431231 187 | c167: - 189.999997615814 x133 + x138 <= 0 188 | c168: x53 + x54 + x55 - x56 - x137 + x138 = 92 189 | c169: x57 >= 0 190 | c170: x57 <= 80 191 | c171: x58 >= 0 192 | c172: x58 <= 90 193 | c173: x139 >= 0 194 | c174: x139 <= 1 195 | c175: - x136 + x139 - 0.00474999994039536 x140 + 0.00526315796078077 x141 = 0 196 | c176: x140 >= 0 197 | c177: x141 >= 0 198 | c178: 210.526318431231 x136 + x140 <= 210.526318431231 199 | c179: - 189.999997615814 x136 + x141 <= 0 200 | c180: x57 + x58 + x59 - x60 - x140 + x141 = 182 201 | c181: x61 >= 0 202 | c182: x61 <= 80 203 | c183: x62 >= 0 204 | c184: x62 <= 90 205 | c185: x142 >= 0 206 | c186: x142 <= 1 207 | c187: - x139 + x142 - 0.00474999994039536 x143 + 0.00526315796078077 x144 = 0 208 | c188: x143 >= 0 209 | c189: x144 >= 0 210 | c190: 210.526318431231 x139 + x143 <= 210.526318431231 211 | c191: - 189.999997615814 x139 + x144 <= 0 212 | c192: x61 + x62 + x63 - x64 - x143 + x144 = 198 213 | c193: x65 >= 0 214 | c194: x65 <= 80 215 | c195: x66 >= 0 216 | c196: x66 <= 90 217 | c197: x145 >= 0 218 | c198: x145 <= 1 219 | c199: - x142 + x145 - 0.00474999994039536 x146 + 0.00526315796078077 x147 = 0 220 | c200: x146 >= 0 221 | c201: x147 >= 0 222 | c202: 210.526318431231 x142 + x146 <= 210.526318431231 223 | c203: - 189.999997615814 x142 + x147 <= 0 224 | c204: x65 + x66 + x67 - x68 - x146 + x147 = 211 225 | c205: x69 >= 0 226 | c206: x69 <= 80 227 | c207: x70 >= 0 228 | c208: x70 <= 90 229 | c209: x148 >= 0 230 | c210: x148 <= 1 231 | c211: - x145 + x148 - 0.00474999994039536 x149 + 0.00526315796078077 x150 = 0 232 | c212: x149 >= 0 233 | c213: x150 >= 0 234 | c214: 210.526318431231 x145 + x149 <= 210.526318431231 235 | c215: - 189.999997615814 x145 + x150 <= 0 236 | c216: x69 + x70 + x71 - x72 - x149 + x150 = 251 237 | c217: x73 >= 0 238 | c218: x73 <= 80 239 | c219: x74 >= 0 240 | c220: x74 <= 90 241 | c221: x151 >= 0 242 | c222: x151 <= 1 243 | c223: - x148 + x151 - 0.00474999994039536 x152 + 0.00526315796078077 x153 = 0 244 | c224: x152 >= 0 245 | c225: x153 >= 0 246 | c226: 210.526318431231 x148 + x152 <= 210.526318431231 247 | c227: - 189.999997615814 x148 + x153 <= 0 248 | c228: x73 + x74 + x75 - x76 - x152 + x153 = 284 249 | c229: x77 >= 0 250 | c230: x77 <= 80 251 | c231: x78 >= 0 252 | c232: x78 <= 90 253 | c233: x154 >= 0 254 | c234: x154 <= 1 255 | c235: - x151 + x154 - 0.00474999994039536 x155 + 0.00526315796078077 x156 = 0 256 | c236: x155 >= 0 257 | c237: x156 >= 0 258 | c238: 210.526318431231 x151 + x155 <= 210.526318431231 259 | c239: - 189.999997615814 x151 + x156 <= 0 260 | c240: x77 + x78 + x79 - x80 - x155 + x156 = 167 261 | c241: x81 >= 0 262 | c242: x81 <= 80 263 | c243: x82 >= 0 264 | c244: x82 <= 90 265 | c245: x157 >= 0 266 | c246: x157 <= 1 267 | c247: - x154 + x157 - 0.00474999994039536 x158 + 0.00526315796078077 x159 = 0 268 | c248: x158 >= 0 269 | c249: x159 >= 0 270 | c250: 210.526318431231 x154 + x158 <= 210.526318431231 271 | c251: - 189.999997615814 x154 + x159 <= 0 272 | c252: x81 + x82 + x83 - x84 - x158 + x159 = 128 273 | c253: x85 >= 0 274 | c254: x85 <= 80 275 | c255: x86 >= 0 276 | c256: x86 <= 90 277 | c257: x160 >= 0 278 | c258: x160 <= 1 279 | c259: - x157 + x160 - 0.00474999994039536 x161 + 0.00526315796078077 x162 = 0 280 | c260: x161 >= 0 281 | c261: x162 >= 0 282 | c262: 210.526318431231 x157 + x161 <= 210.526318431231 283 | c263: - 189.999997615814 x157 + x162 <= 0 284 | c264: x85 + x86 + x87 - x88 - x161 + x162 = 134 285 | c265: x89 >= 0 286 | c266: x89 <= 80 287 | c267: x90 >= 0 288 | c268: x90 <= 90 289 | c269: x163 >= 0 290 | c270: x163 <= 1 291 | c271: - x160 + x163 - 0.00474999994039536 x164 + 0.00526315796078077 x165 = 0 292 | c272: x164 >= 0 293 | c273: x165 >= 0 294 | c274: 210.526318431231 x160 + x164 <= 210.526318431231 295 | c275: - 189.999997615814 x160 + x165 <= 0 296 | c276: x89 + x90 + x91 - x92 - x164 + x165 = 144 297 | c277: x93 >= 0 298 | c278: x93 <= 80 299 | c279: x94 >= 0 300 | c280: x94 <= 90 301 | c281: x166 >= 0 302 | c282: x166 <= 1 303 | c283: - x163 + x166 - 0.00474999994039536 x167 + 0.00526315796078077 x168 = 0 304 | c284: x167 >= 0 305 | c285: x168 >= 0 306 | c286: 210.526318431231 x163 + x167 <= 210.526318431231 307 | c287: - 189.999997615814 x163 + x168 <= 0 308 | c288: x93 + x94 + x95 - x96 - x167 + x168 = 150 309 | Bounds 310 | 0 <= x1 <= 80 311 | 0 <= x2 <= 100 312 | 0 <= x5 <= 80 313 | 0 <= x6 <= 100 314 | 0 <= x9 <= 80 315 | 0 <= x10 <= 100 316 | 0 <= x13 <= 80 317 | 0 <= x14 <= 100 318 | 0 <= x17 <= 80 319 | 0 <= x18 <= 100 320 | 0 <= x21 <= 80 321 | 0 <= x22 <= 100 322 | 0 <= x25 <= 80 323 | 0 <= x26 <= 100 324 | 0 <= x29 <= 80 325 | 0 <= x30 <= 100 326 | 0 <= x33 <= 80 327 | 0 <= x34 <= 100 328 | 0 <= x37 <= 80 329 | 0 <= x38 <= 100 330 | 0 <= x41 <= 80 331 | 0 <= x42 <= 100 332 | 0 <= x45 <= 80 333 | 0 <= x46 <= 100 334 | 0 <= x49 <= 80 335 | 0 <= x50 <= 100 336 | 0 <= x53 <= 80 337 | 0 <= x54 <= 100 338 | 0 <= x57 <= 80 339 | 0 <= x58 <= 100 340 | 0 <= x61 <= 80 341 | 0 <= x62 <= 100 342 | 0 <= x65 <= 80 343 | 0 <= x66 <= 100 344 | 0 <= x69 <= 80 345 | 0 <= x70 <= 100 346 | 0 <= x73 <= 80 347 | 0 <= x74 <= 100 348 | 0 <= x77 <= 80 349 | 0 <= x78 <= 100 350 | 0 <= x81 <= 80 351 | 0 <= x82 <= 100 352 | 0 <= x85 <= 80 353 | 0 <= x86 <= 100 354 | 0 <= x89 <= 80 355 | 0 <= x90 <= 100 356 | 0 <= x93 <= 80 357 | 0 <= x94 <= 100 358 | 0 <= x97 <= 1 359 | 0 <= x98 <= 100 360 | 0 <= x99 <= 100 361 | 0 <= x100 <= 1 362 | 0 <= x101 <= 100 363 | 0 <= x102 <= 100 364 | 0 <= x103 <= 1 365 | 0 <= x104 <= 100 366 | 0 <= x105 <= 100 367 | 0 <= x106 <= 1 368 | 0 <= x107 <= 100 369 | 0 <= x108 <= 100 370 | 0 <= x109 <= 1 371 | 0 <= x110 <= 100 372 | 0 <= x111 <= 100 373 | 0 <= x112 <= 1 374 | 0 <= x113 <= 100 375 | 0 <= x114 <= 100 376 | 0 <= x115 <= 1 377 | 0 <= x116 <= 100 378 | 0 <= x117 <= 100 379 | 0 <= x118 <= 1 380 | 0 <= x119 <= 100 381 | 0 <= x120 <= 100 382 | 0 <= x121 <= 1 383 | 0 <= x122 <= 100 384 | 0 <= x123 <= 100 385 | 0 <= x124 <= 1 386 | 0 <= x125 <= 100 387 | 0 <= x126 <= 100 388 | 0 <= x127 <= 1 389 | 0 <= x128 <= 100 390 | 0 <= x129 <= 100 391 | 0 <= x130 <= 1 392 | 0 <= x131 <= 100 393 | 0 <= x132 <= 100 394 | 0 <= x133 <= 1 395 | 0 <= x134 <= 100 396 | 0 <= x135 <= 100 397 | 0 <= x136 <= 1 398 | 0 <= x137 <= 100 399 | 0 <= x138 <= 100 400 | 0 <= x139 <= 1 401 | 0 <= x140 <= 100 402 | 0 <= x141 <= 100 403 | 0 <= x142 <= 1 404 | 0 <= x143 <= 100 405 | 0 <= x144 <= 100 406 | 0 <= x145 <= 1 407 | 0 <= x146 <= 100 408 | 0 <= x147 <= 100 409 | 0 <= x148 <= 1 410 | 0 <= x149 <= 100 411 | 0 <= x150 <= 100 412 | 0 <= x151 <= 1 413 | 0 <= x152 <= 100 414 | 0 <= x153 <= 100 415 | 0 <= x154 <= 1 416 | 0 <= x155 <= 100 417 | 0 <= x156 <= 100 418 | 0 <= x157 <= 1 419 | 0 <= x158 <= 100 420 | 0 <= x159 <= 100 421 | 0 <= x160 <= 1 422 | 0 <= x161 <= 100 423 | 0 <= x162 <= 100 424 | 0 <= x163 <= 1 425 | 0 <= x164 <= 100 426 | 0 <= x165 <= 100 427 | 0 <= x166 <= 1 428 | 0 <= x167 <= 100 429 | 0 <= x168 <= 100 430 | End 431 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElectNet/SingleMG_ElectNet.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34024.191 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "Project1.vcxproj", "{92FC16A1-661B-40D1-833F-FA53A83C04DF}" 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 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x64.ActiveCfg = Debug|x64 17 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x64.Build.0 = Debug|x64 18 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x86.ActiveCfg = Debug|Win32 19 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Debug|x86.Build.0 = Debug|Win32 20 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x64.ActiveCfg = Release|x64 21 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x64.Build.0 = Release|x64 22 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x86.ActiveCfg = Release|Win32 23 | {92FC16A1-661B-40D1-833F-FA53A83C04DF}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {89DA0DA7-D26C-4CE9-B98A-A7D76BE1D820} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElectNet/SingleMG_ElectNet.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 | 17.0 23 | Win32Proj 24 | {92fc16a1-661b-40d1-833f-fa53a83c04df} 25 | Project1 26 | 10.0 27 | SingleMG 28 | 29 | 30 | 31 | Application 32 | true 33 | v143 34 | Unicode 35 | 36 | 37 | Application 38 | false 39 | v143 40 | true 41 | Unicode 42 | 43 | 44 | Application 45 | true 46 | v143 47 | Unicode 48 | 49 | 50 | Application 51 | false 52 | v143 53 | true 54 | Unicode 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Level3 77 | true 78 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 79 | true 80 | 81 | 82 | Console 83 | true 84 | 85 | 86 | 87 | 88 | Level3 89 | true 90 | true 91 | true 92 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | true 99 | true 100 | 101 | 102 | 103 | 104 | Level3 105 | true 106 | WIN64;_CONSOLE;IL_STD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 107 | true 108 | C:\Program Files\IBM\ILOG\CPLEX_Studio221\concert\include;C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\include;%(AdditionalIncludeDirectories) 109 | MultiThreadedDLL 110 | 111 | 112 | Console 113 | true 114 | C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\lib\x64_windows_msvc14\stat_mda\cplex2210.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio221\cplex\lib\x64_windows_msvc14\stat_mda\ilocplex.lib;C:\Program Files\IBM\ILOG\CPLEX_Studio221\concert\lib\x64_windows_msvc14\stat_mda\concert.lib;%(AdditionalDependencies) 115 | 116 | 117 | 118 | 119 | Level3 120 | true 121 | true 122 | true 123 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 124 | true 125 | 126 | 127 | Console 128 | true 129 | true 130 | true 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElectNet/SingleMG_ElectNet.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;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 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElectNet/SingleMG_ElectNet.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElectNet/Source.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | ILOSTLBEGIN 6 | 7 | 8 | int 9 | main(int, char**) 10 | { 11 | 12 | auto start = chrono::high_resolution_clock::now(); 13 | IloEnv env; 14 | IloModel model(env); 15 | 16 | 17 | #pragma region Microgrid Input Data 18 | 19 | 20 | int T = 24; //One day 21 | int Cdg1 = 80; //Cost for generating per kW power from dg 22 | int Cdg2 = 90; //Cost for generating per kW power from dg 23 | 24 | int* Pload = new int[T] {169, 175, 179, 171, 181, 172, 270, 264, 273, 281, 193, 158, 161, 162, 250, 260, 267, 271, 284, 167, 128, 134, 144, 150}; //Electicity demand w.r.t tim 25 | 26 | int* CGbuy = new int[T] { 90, 90, 90, 90, 90, 90, 110, 110, 110, 110, 110, 125, 125, 125, 125, 125, 125, 125, 110, 110, 110, 110, 110, 110 }; //buying price from grid w.r.t time 27 | int* CGsell = new int[T] { 70, 70, 70, 70, 70, 70, 90, 90, 90, 90, 90, 105, 105, 105, 105, 105, 105, 105, 90, 90, 90, 90, 90, 90}; //selling price to grid w.r.t time 28 | 29 | float* Rdg1 = new float[T] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10, 15, 20, 23, 28, 33, 35, 34, 31, 28, 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; //Power generated by PV w.r.t time 30 | float* Rdg2 = new float[T] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10, 15, 20, 23, 28, 33, 35, 34, 31, 28, 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; //Power generated by PV w.r.t time 31 | 32 | 33 | float socini = 0.2; //Initially charged battery 34 | int Pbmax = 200; //battery maximum capacity 35 | float effin = 0.95; //battery effciency 36 | 37 | #pragma endregion 38 | 39 | 40 | #pragma region Decision Variables 41 | IloNumVarArray PGbuy(env, T, 0, IloInfinity);//Grid power bought 42 | IloNumVarArray PGsell(env, T, 0, IloInfinity);//Grid power sold 43 | 44 | IloNumVarArray statoc(env, T, 0, 1); //battery storage capacity 45 | 46 | IloNumVarArray Bchg(env, T, 0, 100); //battery charging 47 | IloNumVarArray Bdischg(env, T, 0, 100); //battery discharging 48 | 49 | IloNumVarArray Pdg1(env, T, 0, 80); //DGA power generation range 50 | IloNumVarArray Pdg2(env, T, 0, 100); //DGA power generation range 51 | #pragma endregion 52 | 53 | 54 | #pragma region Objective Function 55 | 56 | IloExpr objective(env, T); 57 | 58 | 59 | for (int t = 0; t < T; t++) 60 | { 61 | objective += Cdg1 * Pdg1[t] + Cdg2 * Pdg2[t] + CGbuy[t] * PGbuy[t] - CGsell[t] * PGsell[t]; 62 | 63 | } 64 | 65 | 66 | // Objective: minimize cost 67 | model.add(IloMinimize(env, objective)); 68 | 69 | #pragma endregion 70 | 71 | 72 | 73 | #pragma region Constraints 74 | 75 | 76 | // Constraint: meet demand 77 | 78 | for (int t = 0; t < T; t++) 79 | { 80 | 81 | model.add(0 <= Pdg1[t]); 82 | model.add(Pdg1[t] <= 80); 83 | 84 | model.add(0 <= Pdg2[t]); 85 | model.add(Pdg2[t] <= 90); 86 | 87 | 88 | 89 | // Adding the Battery Constraints constraints 90 | model.add(0 <= statoc[t]); 91 | model.add(statoc[t] <= 1); 92 | if (t == 0) 93 | { 94 | model.add(statoc[t] == socini + ((effin * Bchg[t] - (Bdischg[t] / effin)) / Pbmax)); 95 | model.add(0 <= Bchg[t]); 96 | model.add(0 <= Bdischg[t]); 97 | model.add(Bchg[t] <= (Pbmax * (1 - socini) / effin)); 98 | model.add(Bdischg[t] <= (Pbmax * socini * effin)); 99 | 100 | 101 | } 102 | else 103 | { 104 | model.add(statoc[t] == statoc[t - 1] + ((effin * Bchg[t] - (Bdischg[t] / effin)) / Pbmax)); 105 | model.add(0 <= Bchg[t]); 106 | model.add(0 <= Bdischg[t]); 107 | model.add(Bchg[t] <= (Pbmax * (1 - statoc[t - 1])) / effin); 108 | model.add(Bdischg[t] <= Pbmax * statoc[t - 1] * effin); 109 | 110 | } 111 | 112 | // Adding the power balance constraint 113 | model.add(Pdg1[t] + Pdg2[t] + Rdg1[t] + Rdg2[t] + Bdischg[t] - Bchg[t] + PGbuy[t] - PGsell[t] == Pload[t]); 114 | } 115 | 116 | #pragma endregion 117 | 118 | 119 | #pragma region Results 120 | IloCplex cplex(env); 121 | cplex.extract(model); 122 | cplex.exportModel("ModelLP.lp"); 123 | cplex.setOut(env.getNullStream()); 124 | if (!cplex.solve()) { 125 | env.error() << "Failed" << endl; 126 | throw(-1); 127 | } 128 | double obj = cplex.getObjValue(); 129 | auto end = chrono::high_resolution_clock::now(); 130 | auto Elapsed = chrono::duration_cast(end - start); 131 | cout << "\n\n\t The elapsed time is: \t" << Elapsed.count() << endl; 132 | cout << "Solution status: " << cplex.getStatus() << endl; 133 | cout << "Minimized Objective Funtion : " << obj << endl; 134 | IloNum eps = cplex.getParam( 135 | IloCplex::Param::MIP::Tolerances::Integrality); 136 | #pragma endregion 137 | 138 | 139 | #pragma region StoringOutput 140 | 141 | // Create and open the CSV file for writing 142 | std::ofstream outputFile("output.csv"); 143 | 144 | if (outputFile.is_open()) { 145 | // Write the header row 146 | outputFile << "Time,Pload,CGbuy,CGsell,Rdg1,Rdg2,PGbuy,PGsell,statoc,Bchg,Bdischg,Pdg1,Pdg2" << std::endl; 147 | 148 | // Write the data rows 149 | for (int i = 0; i < T; i++) { 150 | outputFile << i + 1 << "," << Pload[i] << "," << CGbuy[i] << "," 151 | << CGsell[i] << "," << Rdg1[i] << "," << Rdg2[i] << "," 152 | << cplex.getValue(PGbuy[i]) << "," << -cplex.getValue(PGsell[i]) << "," 153 | << cplex.getValue(statoc[i]) << "," << -cplex.getValue(Bchg[i]) << "," 154 | << cplex.getValue(Bdischg[i]) << "," << cplex.getValue(Pdg1[i]) << "," 155 | << cplex.getValue(Pdg2[i]) << std::endl; 156 | } 157 | 158 | // Close the CSV file 159 | outputFile.close(); 160 | std::cout << "Data saved to output.csv" << std::endl; 161 | } 162 | else { 163 | std::cerr << "Failed to open the output.csv file for writing." << std::endl; 164 | } 165 | 166 | 167 | #pragma endregion 168 | 169 | env.end(); 170 | system("pause"); 171 | return 0; 172 | } -------------------------------------------------------------------------------- /SingleMG/SingleMG_ElectNet/output.csv: -------------------------------------------------------------------------------- 1 | Time,Pload,CGbuy,CGsell,Rdg1,Rdg2,PGbuy,PGsell,statoc,Bchg,Bdischg,Pdg1,Pdg2 2 | 1,169,90,70,0,0,157.421,0,0.525,-68.4211,0,80,0 3 | 2,175,90,70,0,0,95,0,0.525,0,0,80,0 4 | 3,179,90,70,0,0,99,0,0.525,0,0,80,0 5 | 4,171,90,70,0,0,91,0,0.525,0,0,80,0 6 | 5,181,90,70,0,0,101,0,0.525,0,0,80,0 7 | 6,172,90,70,0,0,192,0,1,-100,0,80,0 8 | 7,270,110,90,0,0,100,0,1,0,0,80,90 9 | 8,264,110,90,10,10,74,0,1,0,0,80,90 10 | 9,273,110,90,15,15,73,0,1,0,0,80,90 11 | 10,281,110,90,20,20,22.2425,0,0.743382,0,48.7575,80,90 12 | 11,193,110,90,23,23,0,0,0.852632,-23,0,80,90 13 | 12,158,125,105,28,28,0,-68,0.852632,0,0,80,90 14 | 13,161,125,105,33,33,0,-75,0.852632,0,0,80,90 15 | 14,162,125,105,35,35,0,-78,0.852632,0,0,80,90 16 | 15,250,125,105,34,34,0,0,0.789474,0,12,80,90 17 | 16,260,125,105,31,31,0,0,0.642105,0,28,80,90 18 | 17,267,125,105,28,28,0,0,0.426316,0,41,80,90 19 | 18,271,125,105,10,10,0,0,0,0,81,80,90 20 | 19,284,110,90,0,0,114,0,0,0,0,80,90 21 | 20,167,110,90,0,0,0,-3,0,0,0,80,90 22 | 21,128,110,90,0,0,0,-42,0,0,0,80,90 23 | 22,134,110,90,0,0,0,-36,0,0,0,80,90 24 | 23,144,110,90,0,0,0,-26,0,0,0,80,90 25 | 24,150,110,90,0,0,0,-20,0,0,0,80,90 26 | -------------------------------------------------------------------------------- /graphics/SingleMG.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TalhaRehmanMTRKT/MicrogridOptimization/ac29e9c4d64adba024e78a7aa74347072e3b878f/graphics/SingleMG.PNG --------------------------------------------------------------------------------