コード例 #1
0
 static void mMain(string[] args)
 {
     string path        = @"C:\Users\Christoph\Documents\Visual Studio 2012\Projects\GHUrbanMorphologyEHub\UrbanFormEHub\bin\";
     bool   carbmin     = false;
     bool   minpartload = false;
     double gfa         = 2000;  // gross floor area of urban design
     double carbcon     = 10.06; //this needs to be kgco2/m2a, using the GFA of the urban form design
     //Ehub ehub = new Ehub(path, gfa, carbmin, minpartload, carbcon);
     Ehub ehub = new Ehub(path, gfa, carbmin, minpartload);
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: christophwaibel/EnergyHubs
        /// <summary>
        /// Run Energy Hubs for multiple inputs and writes outputs for each
        /// </summary>
        static void RunMultipleEhubs()
        {
            int    numberOfTypicalDays = 12;
            string buildingInputName   = @"building_input";
            string technologyInputName = @"technology_input";

            // ask for folder with input files (pairs of demand_input and tech_params)
            Console.WriteLine();
            Console.WriteLine(@"*************************************************************************************");
            Console.WriteLine(@"****************************** E N E R G Y H U B S **********************************");
            Console.WriteLine(@"*************************************************************************************");
            Console.WriteLine(@"************************************* F O R *****************************************");
            Console.WriteLine(@"*************************************************************************************");
            Console.WriteLine(@"********************** M U L T I P L E    B U I L D I N G S *************************");
            Console.WriteLine(@"*************************************************************************************");
            Console.WriteLine(@"Please enter the path of your inputs folder in the following format: 'c:\inputs\'");
            Console.WriteLine("The folder should contain one or more pairs of csv-files in the naming convention: 'building_input_0.csv', 'technology_input_0.csv'. '0' is the integer that makes the program recognize that these two csv belong together.");
            Console.WriteLine();
            Console.Write("Enter your path now and confirm by hitting the Enter-key: ");
            string path = Console.ReadLine();

            if (!path.EndsWith(@"\"))
            {
                path = path + @"\";
            }


            // identify all valid input files in folder
            int filePairs = 0;

            string[] fileEntries = Directory.GetFiles(path);
            string[] fileNames   = new string[fileEntries.Length];
            for (int i = 0; i < fileEntries.Length; i++)
            {
                fileNames[i] = Path.GetFileName(fileEntries[i]);
            }

            List <string> inputBuildingFiles   = new List <string>();
            List <string> inputTechnologyFiles = new List <string>();
            List <int>    inputIndices         = new List <int>();

            foreach (string fileEntry in fileEntries)
            {
                string   fileName             = Path.GetFileName(fileEntry);
                string[] splitFileName        = fileName.Split('_');
                string   fileNameWithoutIndex = splitFileName[0] + '_' + splitFileName[1];
                if (string.Equals(fileNameWithoutIndex, buildingInputName))
                {
                    //find its partner. just make string search
                    string partnerFile = technologyInputName + "_" + splitFileName[splitFileName.Length - 1];
                    if (fileNames.Contains(partnerFile))
                    {
                        filePairs++;
                    }

                    inputBuildingFiles.Add(fileName);
                    inputTechnologyFiles.Add(partnerFile);
                    inputIndices.Add(Convert.ToInt32(splitFileName[splitFileName.Length - 1].Split('.')[0]));
                }
            }

            // ask, how many runs to do
            Console.WriteLine("Enter the number of Building-cases to generate Energyhubs for. There exist {0} file-pairs, hence you can select any integer number smaller equal of that:", filePairs);
            Int32.TryParse(Console.ReadLine(), out int nRuns);
            int nRunsActually = filePairs < nRuns ? filePairs : nRuns;    // if there are less file pairs in the folder than the number of runs, we actually want, only run the existing pairs in the folder

            for (int i = 0; i < nRunsActually; i++)
            {
                try
                {
                    Console.WriteLine(@"*************************************************************************************");
                    Console.WriteLine("Loading data...");
                    LoadBuildingInput(path + inputBuildingFiles[i],
                                      out List <double> heating, out List <double> cooling, out List <double> electricity, out List <double> ghi, out List <double> dhw, out List <double> Tamb, out List <double[]> solar, out List <double> solarArea);
                    LoadTechParameters(path + inputTechnologyFiles[i], out Dictionary <string, double> technologyParameters);


                    /// data preparation, clustering and typical days
                    Console.WriteLine("Clustering and generating typical days...");
                    int        numberOfSolarAreas = solar[0].Length;
                    int        numBaseLoads       = 5;                                 // heating, cooling, electricity, ghi, tamb
                    int        numLoads           = numBaseLoads + numberOfSolarAreas; // heating, cooling, electricity, ghi, tamb, solar. however, solar will include several profiles.
                    double[][] fullProfiles       = new double[numLoads][];
                    string[]   loadTypes          = new string[numLoads];
                    bool[]     peakDays           = new bool[numLoads];
                    bool[]     correctionLoad     = new bool[numLoads];
                    for (int u = 0; u < numLoads; u++)
                    {
                        fullProfiles[u] = new double[hoursPerYear];
                    }
                    loadTypes[0]      = "heating";
                    loadTypes[1]      = "cooling";
                    loadTypes[2]      = "electricity";
                    loadTypes[3]      = "ghi";
                    loadTypes[4]      = "Tamb";
                    peakDays[0]       = true;
                    peakDays[1]       = true;
                    peakDays[2]       = true;
                    peakDays[3]       = false;
                    peakDays[4]       = false;
                    correctionLoad[0] = true;
                    correctionLoad[1] = true;
                    correctionLoad[2] = true;
                    correctionLoad[3] = false;
                    correctionLoad[4] = false;

                    bool[] useForClustering = new bool[fullProfiles.Length]; // specificy here, which load is used for clustering. the others are just reshaped
                    for (int t = 0; t < hoursPerYear; t++)
                    {
                        fullProfiles[0][t]  = heating[t] + dhw[t];
                        fullProfiles[1][t]  = cooling[t];
                        fullProfiles[2][t]  = electricity[t];
                        fullProfiles[3][t]  = ghi[t];
                        fullProfiles[4][t]  = Tamb[t];
                        useForClustering[0] = true;
                        useForClustering[1] = true;
                        useForClustering[2] = true;
                        useForClustering[3] = true;
                        useForClustering[4] = false;
                    }

                    for (int u = 0; u < numberOfSolarAreas; u++)
                    {
                        useForClustering[u + numBaseLoads] = false;
                        peakDays[u + numBaseLoads]         = false;
                        correctionLoad[u + numBaseLoads]   = true;
                        loadTypes[u + numBaseLoads]        = "solar";
                        for (int t = 0; t < hoursPerYear; t++)
                        {
                            fullProfiles[u + numBaseLoads][t] = solar[t][u];
                        }
                    }

                    // TO DO: load in GHI time series, add it to full profiles (right after heating, cooling, elec), and use it for clustering. exclude other solar profiles from clustering, but they need to be reshaped too
                    EhubMisc.HorizonReduction.TypicalDays typicalDays = EhubMisc.HorizonReduction.GenerateTypicalDays(fullProfiles, loadTypes, numberOfTypicalDays, peakDays, useForClustering, correctionLoad, false);


                    /// Running Energy Hub
                    Console.WriteLine("Solving MILP optimization model...");
                    double[][] typicalSolarLoads = new double[numberOfSolarAreas][];
                    for (int u = 0; u < numberOfSolarAreas; u++)
                    {
                        typicalSolarLoads[u] = typicalDays.DayProfiles[numBaseLoads + u];
                    }
                    int[] clustersizePerTimestep = typicalDays.NumberOfDaysPerTimestep;
                    Ehub  ehub = new Ehub(typicalDays.DayProfiles[0], typicalDays.DayProfiles[1], typicalDays.DayProfiles[2],
                                          typicalSolarLoads, solarArea.ToArray(),
                                          typicalDays.DayProfiles[4], technologyParameters,
                                          clustersizePerTimestep);
                    ehub.Solve(5);

                    /// Storing Results
                    Console.WriteLine("Saving results into {0}...", path + @"results\");
                    WriteOutput(inputIndices[i], path, numberOfSolarAreas, ehub, typicalDays);

                    Console.WriteLine("Energyhubs {0} of {1} completed...", i + 1, nRunsActually);
                    Console.WriteLine(@"......");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    WriteErrorFile(inputIndices[i], path, ex);
                }
            }



            /// Waiting for user to close window
            Console.WriteLine(@"*************************************************************************************");
            Console.WriteLine(@"*************************************************************************************");
            Console.WriteLine(@"*************************************************************************************");
            Console.WriteLine("Program finished. Hit any key to close program...: ");
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: christophwaibel/EnergyHubs
        static void WriteOutput(int fileIndex, string path, int numberOfSolarAreas, Ehub ehub, EhubMisc.HorizonReduction.TypicalDays typicalDays)
        {
            // check, if results folder exists in inputs folder
            string outputPath = path + @"results\";

            Directory.CreateDirectory(outputPath);

            // write a csv for each epsilon cut, name it "_e1", "_e2", .. etc
            List <string> header = new List <string>();
            // write units to 2nd row
            List <string> header_units = new List <string>();

            header.Add("Lev.Emissions");
            header_units.Add("kgCO2eq/a");
            header.Add("Lev.Cost");
            header_units.Add("CHF/a");
            header.Add("OPEX");
            header_units.Add("CHF/a");
            header.Add("CAPEX");
            header_units.Add("CHF/a");
            header.Add("DistrictHeatingCost");
            header_units.Add("CHF/a");
            header.Add("x_Battery");
            header_units.Add("kWh");
            header.Add("x_TES");
            header_units.Add("kWh");
            header.Add("x_CHP");
            header_units.Add("kW");
            header.Add("x_Boiler");
            header_units.Add("kW");
            header.Add("x_BiomassBoiler");
            header_units.Add("kW");
            header.Add("x_ASHP");
            header_units.Add("kW");
            header.Add("x_AirCon");
            header_units.Add("kW");
            header.Add("x_Battery_charge");
            header_units.Add("kWh");
            header.Add("x_Battery_discharge");
            header_units.Add("kWh");
            header.Add("x_Battery_soc");
            header_units.Add("kWh");
            header.Add("x_TES_charge");
            header_units.Add("kWh");
            header.Add("x_TES_discharge");
            header_units.Add("kWh");
            header.Add("x_TES_soc");
            header_units.Add("kWh");
            header.Add("x_CHP_op_e");
            header_units.Add("kWh");
            header.Add("x_CHP_op_h");
            header_units.Add("kWh");
            header.Add("x_CHP_dump");
            header_units.Add("kWh");
            header.Add("x_Boiler_op");
            header_units.Add("kWh");
            header.Add("x_BiomassBoiler_op");
            header_units.Add("kWh");
            header.Add("x_ASHP_op");
            header_units.Add("kWh");
            header.Add("x_AirCon_op");
            header_units.Add("kWh");
            header.Add("x_GridPurchase");
            header_units.Add("kWh");
            header.Add("x_FeedIn");
            header_units.Add("kWh");
            for (int i = 0; i < numberOfSolarAreas; i++)
            {
                header.Add("x_PV_" + i);
                header_units.Add("sqm");
            }
            for (int i = 0; i < ehub.NumberOfBuildingsInDistrict; i++)
            {
                header.Add("x_HeatExchanger_DH_" + i);
                header_units.Add("kW");
            }
            header.Add("b_PV_totalProduction");
            header_units.Add("kWh");
            header.Add("TypicalHeating");
            header_units.Add("kWh");
            header.Add("TypicalCooling");
            header_units.Add("kWh");
            header.Add("TypicalElectricity");
            header_units.Add("kWh");
            header.Add("TypicalGHI");
            header_units.Add(@"W/sqm");
            header.Add("TypicalAmbientTemp");
            header_units.Add("deg C");
            header.Add("ClusterSize");
            header_units.Add("Days");
            header.Add("BiomassConsumed");
            header_units.Add("kWh");

            for (int e = 0; e < ehub.Outputs.Length; e++)
            {
                List <List <string> > outputString = new List <List <string> >();
                if (ehub.Outputs[e].infeasible)
                {
                    outputString.Add(new List <string> {
                        "Infeasible"
                    });
                    Console.WriteLine("--- Infeasible Solution ---");
                }
                else
                {
                    outputString.Add(header);
                    outputString.Add(header_units);

                    List <string> firstLine = new List <string>();
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].carbon));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].cost));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].OPEX));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].CAPEX));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].cost_dh));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_bat));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_tes));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_chp));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_boi));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_bmboi));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_hp));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_ac));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_bat_charge[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_bat_discharge[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_bat_soc[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_tes_charge[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_tes_discharge[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_tes_soc[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_chp_op_e[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_chp_op_h[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_chp_dump[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_boi_op[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_bmboi_op[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_hp_op[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_ac_op[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_elecpur[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].x_feedin[0]));
                    for (int i = 0; i < numberOfSolarAreas; i++)
                    {
                        firstLine.Add(Convert.ToString(ehub.Outputs[e].x_pv[i]));
                    }
                    for (int i = 0; i < ehub.NumberOfBuildingsInDistrict; i++)
                    {
                        firstLine.Add(Convert.ToString(ehub.Outputs[e].x_hx_dh[i]));
                    }
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].b_pvprod[0]));

                    firstLine.Add(Convert.ToString(typicalDays.DayProfiles[0][0]));
                    firstLine.Add(Convert.ToString(typicalDays.DayProfiles[1][0]));
                    firstLine.Add(Convert.ToString(typicalDays.DayProfiles[2][0]));
                    firstLine.Add(Convert.ToString(typicalDays.DayProfiles[3][0]));
                    firstLine.Add(Convert.ToString(typicalDays.DayProfiles[4][0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].clustersize[0]));
                    firstLine.Add(Convert.ToString(ehub.Outputs[e].biomassConsumed));

                    outputString.Add(firstLine);

                    for (int t = 1; t < ehub.Outputs[e].x_elecpur.Length; t++)
                    {
                        List <string> newLine = new List <string>();
                        for (int skip = 0; skip < 12; skip++)
                        {
                            newLine.Add("");
                        }
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_bat_charge[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_bat_discharge[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_bat_soc[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_tes_charge[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_tes_discharge[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_tes_soc[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_chp_op_e[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_chp_op_h[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_chp_dump[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_boi_op[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_bmboi_op[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_hp_op[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_ac_op[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_elecpur[t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].x_feedin[t]));
                        for (int skip = 0; skip < numberOfSolarAreas; skip++)
                        {
                            newLine.Add("");
                        }
                        for (int skip = 0; skip < ehub.NumberOfBuildingsInDistrict; skip++)
                        {
                            newLine.Add("");
                        }
                        newLine.Add(Convert.ToString(ehub.Outputs[e].b_pvprod[t]));

                        newLine.Add(Convert.ToString(typicalDays.DayProfiles[0][t]));
                        newLine.Add(Convert.ToString(typicalDays.DayProfiles[1][t]));
                        newLine.Add(Convert.ToString(typicalDays.DayProfiles[2][t]));
                        newLine.Add(Convert.ToString(typicalDays.DayProfiles[3][t]));
                        newLine.Add(Convert.ToString(typicalDays.DayProfiles[4][t]));
                        newLine.Add(Convert.ToString(ehub.Outputs[e].clustersize[t]));
                        newLine.Add("");

                        outputString.Add(newLine);
                    }
                }
                using var sw = new StreamWriter(outputPath + "result_" + Convert.ToString(fileIndex) + "_epsilon" + e + ".csv");
                foreach (List <string> line in outputString)
                {
                    foreach (string cell in line)
                    {
                        sw.Write(cell + ";");
                    }
                    sw.Write(Environment.NewLine);
                }
                sw.Close();
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine(@"///////////////////////////////////////");
            Console.WriteLine("CAREFUL!!!!!!!!!!! BUG IN CHP OPERATION!!! SEE LINE 977 in Ehub.cs");
            Console.WriteLine("Hit any key if you still wanna proceed");
            Console.ReadKey();
            Console.WriteLine("Morris sampling for ECOS 2018 energy hubs A, B and C...");
            Console.WriteLine(@"80 morris samples...");
            Console.WriteLine(@"///////////////////////////////////////");
            Console.WriteLine();
            Console.WriteLine(@"Please enter an existing path for writing results, and where the inputs are. E.g.: C:\Chris\Ecos2018\");
            string basepath = Console.ReadLine();

            Console.WriteLine(@"Please enter the number of epsilon cuts for the pareto front. 7 is a good number.");
            int epsilonsteps = Convert.ToInt16(Console.ReadLine());

            Console.WriteLine();

            //int epsilonsteps = 7;   // including min co2 and min cost
            int morrissamples = 400;
            //string path = @"C:\Users\Christoph\Desktop\Ecosinputs\";
            //string pathout_A = @"C:\Users\Christoph\Desktop\EcosResults\A\";
            //string pathout_B = @"C:\Users\Christoph\Desktop\EcosResults\B\";
            //string pathout_C = @"C:\Users\Christoph\Desktop\EcosResults\C\";
            string path      = basepath + @"inputs\";
            string pathout_A = basepath + @"Results_A\";
            string pathout_B = basepath + @"Results_B\";
            string pathout_C = basepath + @"Results_C\";

            String[][][] Morris_outputsA = new String[morrissamples][][];
            String[][][] Morris_outputsB = new String[morrissamples][][];
            String[][][] Morris_outputsC = new String[morrissamples][][];

            for (int m = 0; m < morrissamples; m++)
            {
                Ehub ehub_A = new Ehub(path, m, morrissamples);
                ehub_A.Solve_MultiObejctive(epsilonsteps, 0);
                ehub_A.writeOutputCSV(pathout_A);

                Ehub ehub_B = new Ehub(path, m, morrissamples);
                ehub_B.Solve_MultiObejctive(epsilonsteps, 1);
                ehub_B.writeOutputCSV(pathout_B);

                Ehub ehub_C = new Ehub(path, m, morrissamples);
                ehub_C.Solve_MultiObejctive(epsilonsteps, 2);
                ehub_C.writeOutputCSV(pathout_C);

                // only write outputs for the morris
                Morris_outputsA[m] = new String[epsilonsteps][];
                Morris_outputsB[m] = new String[epsilonsteps][];
                Morris_outputsC[m] = new String[epsilonsteps][];
                for (int e = 0; e < epsilonsteps; e++)
                {
                    Morris_outputsA[m][e]    = new String[10 + 60 + 2];  // Total, OPEX, CAPEX, CO2, hp, boi, chp, tes, bat, ac, 60 times pv, totalgridpurchase, totalfeedin);
                    Morris_outputsA[m][e][0] = Convert.ToString(ehub_A.outputs[e].cost);
                    Morris_outputsA[m][e][1] = Convert.ToString(ehub_A.outputs[e].OPEX);
                    Morris_outputsA[m][e][2] = Convert.ToString(ehub_A.outputs[e].CAPEX);
                    Morris_outputsA[m][e][3] = Convert.ToString(ehub_A.outputs[e].carbon);
                    Morris_outputsA[m][e][4] = Convert.ToString(ehub_A.outputs[e].x_hp);
                    Morris_outputsA[m][e][5] = Convert.ToString(ehub_A.outputs[e].x_boi);
                    Morris_outputsA[m][e][6] = Convert.ToString(ehub_A.outputs[e].x_chp);
                    Morris_outputsA[m][e][7] = Convert.ToString(ehub_A.outputs[e].x_tes);
                    Morris_outputsA[m][e][8] = Convert.ToString(ehub_A.outputs[e].x_bat);
                    Morris_outputsA[m][e][9] = Convert.ToString(ehub_A.outputs[e].x_ac);
                    Morris_outputsB[m][e]    = new String[10 + 60 + 2];  // Total, OPEX, CAPEX, CO2, hp, boi, chp, tes, bat, ac, 60 times pv, totalgridpurchase, totalfeedin);
                    Morris_outputsB[m][e][0] = Convert.ToString(ehub_B.outputs[e].cost);
                    Morris_outputsB[m][e][1] = Convert.ToString(ehub_B.outputs[e].OPEX);
                    Morris_outputsB[m][e][2] = Convert.ToString(ehub_B.outputs[e].CAPEX);
                    Morris_outputsB[m][e][3] = Convert.ToString(ehub_B.outputs[e].carbon);
                    Morris_outputsB[m][e][4] = Convert.ToString(ehub_B.outputs[e].x_hp);
                    Morris_outputsB[m][e][5] = Convert.ToString(ehub_B.outputs[e].x_boi);
                    Morris_outputsB[m][e][6] = Convert.ToString(ehub_B.outputs[e].x_chp);
                    Morris_outputsB[m][e][7] = Convert.ToString(ehub_B.outputs[e].x_tes);
                    Morris_outputsB[m][e][8] = Convert.ToString(ehub_B.outputs[e].x_bat);
                    Morris_outputsB[m][e][9] = Convert.ToString(ehub_B.outputs[e].x_ac);
                    Morris_outputsC[m][e]    = new String[10 + 60 + 2];  // Total, OPEX, CAPEX, CO2, hp, boi, chp, tes, bat, ac, 60 times pv, totalgridpurchase, totalfeedin);
                    Morris_outputsC[m][e][0] = Convert.ToString(ehub_C.outputs[e].cost);
                    Morris_outputsC[m][e][1] = Convert.ToString(ehub_C.outputs[e].OPEX);
                    Morris_outputsC[m][e][2] = Convert.ToString(ehub_C.outputs[e].CAPEX);
                    Morris_outputsC[m][e][3] = Convert.ToString(ehub_C.outputs[e].carbon);
                    Morris_outputsC[m][e][4] = Convert.ToString(ehub_C.outputs[e].x_hp);
                    Morris_outputsC[m][e][5] = Convert.ToString(ehub_C.outputs[e].x_boi);
                    Morris_outputsC[m][e][6] = Convert.ToString(ehub_C.outputs[e].x_chp);
                    Morris_outputsC[m][e][7] = Convert.ToString(ehub_C.outputs[e].x_tes);
                    Morris_outputsC[m][e][8] = Convert.ToString(ehub_C.outputs[e].x_bat);
                    Morris_outputsC[m][e][9] = Convert.ToString(ehub_C.outputs[e].x_ac);
                    for (int p = 0; p < ehub_A.outputs[e].x_pv.Length; p++)
                    {
                        Morris_outputsA[m][e][p + 10] = Convert.ToString(ehub_A.outputs[e].x_pv[p]);
                        Morris_outputsB[m][e][p + 10] = Convert.ToString(ehub_B.outputs[e].x_pv[p]);
                        Morris_outputsC[m][e][p + 10] = Convert.ToString(ehub_C.outputs[e].x_pv[p]);
                    }
                    Morris_outputsA[m][e][70] = Convert.ToString(ehub_A.outputs[e].x_elecpur.Sum());
                    Morris_outputsB[m][e][70] = Convert.ToString(ehub_B.outputs[e].x_elecpur.Sum());
                    Morris_outputsC[m][e][70] = Convert.ToString(ehub_C.outputs[e].x_elecpur.Sum());
                    Morris_outputsA[m][e][71] = Convert.ToString(ehub_A.outputs[e].x_feedin.Sum());
                    Morris_outputsB[m][e][71] = Convert.ToString(ehub_B.outputs[e].x_feedin.Sum());
                    Morris_outputsC[m][e][71] = Convert.ToString(ehub_C.outputs[e].x_feedin.Sum());
                }
                Console.WriteLine("morris run: {0}", m);
            }


            // Write first line for outputs: Total, OPEX, CAPEX, CO2, hp, boi, chp, tes, bat, ac, 60 times pv

            // write seperate text files for each epsilon constraint
            // per text file, each column is one output.
            for (int e = 0; e < epsilonsteps; e++)
            {
                string fileName = pathout_A + "EhubA_" + e + ".txt";
                using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write))
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.Write("Total;OPEX;CAPEX;Carbon;HP;Boiler;CHP;TES;Battery;AC;");
                        for (int p = 0; p < 60; p++)
                        {
                            sw.Write("PV_" + Convert.ToString(p) + ";");
                        }
                        sw.Write("TotPur;TotFeedin;\r\n");

                        for (int m = 0; m < morrissamples; m++)
                        {
                            for (int t = 0; t < 72; t++)
                            {
                                sw.Write(Morris_outputsA[m][e][t] + ";");
                            }
                            sw.Write("\r\n");
                        }
                    }

                fileName = pathout_B + "EhubB_" + e + ".txt";
                using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write))
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.Write("Total;OPEX;CAPEX;Carbon;HP;Boiler;CHP;TES;Battery;AC;");
                        for (int p = 0; p < 60; p++)
                        {
                            sw.Write("PV_" + Convert.ToString(p) + ";");
                        }
                        sw.Write("TotPur;TotFeedin;\r\n");

                        for (int m = 0; m < morrissamples; m++)
                        {
                            for (int t = 0; t < 72; t++)
                            {
                                sw.Write(Morris_outputsB[m][e][t] + ";");
                            }
                            sw.Write("\r\n");
                        }
                    }

                fileName = pathout_C + "EhubC_" + e + ".txt";
                using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write))
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.Write("Total;OPEX;CAPEX;Carbon;HP;Boiler;CHP;TES;Battery;AC;");
                        for (int p = 0; p < 60; p++)
                        {
                            sw.Write("PV_" + Convert.ToString(p) + ";");
                        }
                        sw.Write("TotPur;TotFeedin;\r\n");

                        for (int m = 0; m < morrissamples; m++)
                        {
                            for (int t = 0; t < 72; t++)
                            {
                                sw.Write(Morris_outputsC[m][e][t] + ";");
                            }
                            sw.Write("\r\n");
                        }
                    }
            }
        }
コード例 #5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CAREFUL HARDCODED STUFF LINES 160 following


            bool start = false;

            if (!DA.GetData(0, ref start))
            {
            }
            ;

            double carbcon = double.MaxValue;

            if (!DA.GetData(1, ref carbcon))
            {
            }
            ;

            double gfa = double.MaxValue;

            if (!DA.GetData(2, ref gfa))
            {
            }
            ;

            List <double> elecdem = new List <double>();

            if (!DA.GetDataList(3, elecdem))
            {
                return;
            }

            List <double> cooldem = new List <double>();

            if (!DA.GetDataList(4, cooldem))
            {
                return;
            }

            List <double> shdem = new List <double>();

            if (!DA.GetDataList(5, shdem))
            {
                return;
            }

            List <double> dhwdem = new List <double>();

            if (!DA.GetDataList(6, dhwdem))
            {
                return;
            }

            List <double> feedin = new List <double>();

            if (!DA.GetDataList(7, feedin))
            {
                return;
            }

            List <double> grid = new List <double>();

            if (!DA.GetDataList(8, grid))
            {
                return;
            }

            List <double> carbon = new List <double>();

            if (!DA.GetDataList(9, carbon))
            {
                return;
            }

            List <double> temp = new List <double>();

            if (!DA.GetDataList(10, temp))
            {
                return;
            }

            List <double> pvarea = new List <double>();

            if (!DA.GetDataList(11, pvarea))
            {
                return;
            }

            //assuming 30% of the facade can be covered with PV
            for (int i = 0; i < pvarea.Count; i++)
            {
                if (i > 8 && i < 45)
                {
                    pvarea[i] *= 0.3;
                }
                if (i > 53 && i < 90)
                {
                    pvarea[i] *= 0.3;
                }
                if (i > 98 && i < 135)
                {
                    pvarea[i] *= 0.3;
                }
                if (i > 143)
                {
                    pvarea[i] *= 0.3;
                }
            }

            Grasshopper.Kernel.Data.GH_Structure <Grasshopper.Kernel.Types.GH_Number> sol;
            if (!DA.GetDataTree(12, out sol))
            {
                return;
            }
            List <List <double> > solarPotList = new List <List <double> >();

            for (int i = 0; i < sol.Branches.Count; i++)
            {
                solarPotList.Add(new List <double>());
                foreach (Grasshopper.Kernel.Types.GH_Number gooNumber in sol.get_Branch(i))
                {
                    double numb;
                    GH_Convert.ToDouble(gooNumber, out numb, GH_Conversion.Both);
                    solarPotList[i].Add(numb);
                }
            }

            double maxbat = double.MaxValue;

            if (!DA.GetData(13, ref maxbat))
            {
            }
            ;
            double maxtes = double.MaxValue;

            if (!DA.GetData(14, ref maxtes))
            {
            }
            ;

            bool reducedhorizon = false;

            if (!DA.GetData(15, ref reducedhorizon))
            {
            }
            ;

            bool mincarbon = false;

            if (!DA.GetData(16, ref mincarbon))
            {
            }
            ;

            bool multithreading = true;

            if (!DA.GetData(17, ref multithreading))
            {
            }
            ;

            double rent = 65;

            if (!DA.GetData(18, ref rent))
            {
            }
            ;

            if (start)
            {
                Ehub ehub = new Ehub(multithreading, mincarbon, false, gfa, carbcon, elecdem, cooldem, shdem, dhwdem, feedin, grid, carbon, temp, pvarea, solarPotList, maxbat, maxtes, reducedhorizon);

                if (!ehub.outputs.infeasible)
                {
                    DA.SetData(0, ehub.outputs.cost);
                    DA.SetData(1, ehub.outputs.carbon);

                    List <double> x_cap = new List <double>();
                    x_cap.Add(ehub.outputs.x_ac);
                    x_cap.Add(ehub.outputs.x_hp_s);
                    x_cap.Add(ehub.outputs.x_hp_m);
                    x_cap.Add(ehub.outputs.x_hp_l);
                    x_cap.Add(ehub.outputs.x_chp_s);
                    x_cap.Add(ehub.outputs.x_chp_m);
                    x_cap.Add(ehub.outputs.x_chp_l);
                    x_cap.Add(ehub.outputs.x_boi_s);
                    x_cap.Add(ehub.outputs.x_boi_m);
                    x_cap.Add(ehub.outputs.x_boi_l);
                    x_cap.Add(ehub.outputs.x_bat);
                    x_cap.Add(ehub.outputs.x_tes);
                    DA.SetDataList(2, x_cap);

                    List <double> x_pv = new List <double>();
                    List <double> x_st = new List <double>();
                    for (int p = 0; p < ehub.outputs.x_pv.Length; p++)
                    {
                        x_pv.Add(ehub.outputs.x_pv[p]);
                        x_st.Add(ehub.outputs.x_st[p]);
                    }
                    DA.SetDataList(3, x_pv);
                    DA.SetDataList(4, x_st);

                    List <double> x_hp_op      = new List <double>();
                    List <double> x_chp_op_h   = new List <double>();
                    List <double> x_chp_op_e   = new List <double>();
                    List <double> x_boi_op     = new List <double>();
                    List <double> x_bat_ch_op  = new List <double>();
                    List <double> x_bat_dis_op = new List <double>();
                    List <double> x_bat_soc_op = new List <double>();
                    List <double> x_tes_ch_op  = new List <double>();
                    List <double> x_tes_dis_op = new List <double>();
                    List <double> x_tes_soc_op = new List <double>();
                    List <double> x_dump_op    = new List <double>();
                    List <double> x_pv_prod    = new List <double>();
                    List <double> x_elec_pur   = new List <double>();
                    List <double> x_elec_sell  = new List <double>();
                    List <double> d_elec_red   = new List <double>();
                    List <double> d_sh_red     = new List <double>();
                    List <double> d_dhw_red    = new List <double>();
                    List <double> d_cool_red   = new List <double>();

                    for (int t = 0; t < ehub.horizon; t++)
                    {
                        x_hp_op.Add(ehub.outputs.x_hp_s_op_sh[t] + ehub.outputs.x_hp_s_op_dhw[t] + ehub.outputs.x_hp_m_op_sh[t] + ehub.outputs.x_hp_m_op_dhw[t] + ehub.outputs.x_hp_l_op_sh[t] + ehub.outputs.x_hp_l_op_dhw[t]);
                        x_chp_op_h.Add(ehub.outputs.x_chp_s_op_sh[t] + ehub.outputs.x_chp_s_op_dhw[t] + ehub.outputs.x_chp_m_op_sh[t] + ehub.outputs.x_chp_m_op_dhw[t] + ehub.outputs.x_chp_l_op_sh[t] + ehub.outputs.x_chp_l_op_dhw[t]);
                        x_chp_op_e.Add(ehub.outputs.x_chp_s_op_e[t] + ehub.outputs.x_chp_m_op_e[t] + ehub.outputs.x_chp_l_op_e[t]);
                        x_boi_op.Add(ehub.outputs.x_boi_s_op_sh[t] + ehub.outputs.x_boi_s_op_dhw[t] + ehub.outputs.x_boi_m_op_sh[t] + ehub.outputs.x_boi_m_op_dhw[t] + ehub.outputs.x_boi_l_op_sh[t] + ehub.outputs.x_boi_l_op_dhw[t]);
                        x_bat_ch_op.Add(ehub.outputs.x_batcharge[t]);
                        x_bat_dis_op.Add(ehub.outputs.x_batdischarge[t]);
                        x_bat_soc_op.Add(ehub.outputs.x_batsoc[t]);
                        x_tes_ch_op.Add(ehub.outputs.x_tescharge_sh[t] + ehub.outputs.x_tescharge_dhw[t]);
                        x_tes_dis_op.Add(ehub.outputs.x_tesdischarge_sh[t] + ehub.outputs.x_tesdischarge_dhw[t]);
                        x_tes_soc_op.Add(ehub.outputs.x_tessoc[t]);
                        x_dump_op.Add(ehub.outputs.x_chp_s_dump_sh[t] + ehub.outputs.x_chp_m_dump_sh[t] + ehub.outputs.x_chp_l_dump_sh[t] + ehub.outputs.x_chp_s_dump_sh[t] + ehub.outputs.x_chp_m_dump_sh[t] + ehub.outputs.x_chp_l_dump_sh[t] +
                                      ehub.outputs.x_st_dump_dhw[t] + ehub.outputs.x_st_dump_sh[t]);
                        x_pv_prod.Add(ehub.outputs.b_pvprod[t]);
                        x_elec_pur.Add(ehub.outputs.x_elecpur[t]);
                        x_elec_sell.Add(ehub.outputs.x_feedin[t]);
                        d_elec_red.Add(ehub.d_elec[t]);
                        d_sh_red.Add(ehub.d_sh[t]);
                        d_dhw_red.Add(ehub.d_dhw[t]);
                        d_cool_red.Add(ehub.d_cool[t]);
                    }

                    DA.SetDataList(5, x_hp_op);
                    DA.SetDataList(6, x_chp_op_h);
                    DA.SetDataList(7, x_chp_op_e);
                    DA.SetDataList(8, x_boi_op);
                    DA.SetDataList(9, x_bat_ch_op);
                    DA.SetDataList(10, x_bat_dis_op);
                    DA.SetDataList(11, x_bat_soc_op);
                    DA.SetDataList(12, x_tes_ch_op);
                    DA.SetDataList(13, x_tes_dis_op);
                    DA.SetDataList(14, x_tes_soc_op);
                    DA.SetDataList(15, x_dump_op);
                    DA.SetDataList(16, x_pv_prod);
                    DA.SetDataList(17, x_elec_pur);
                    DA.SetDataList(18, x_elec_sell);
                    DA.SetDataList(19, d_elec_red);
                    DA.SetDataList(20, d_sh_red);
                    DA.SetDataList(21, d_dhw_red);
                    DA.SetDataList(22, d_cool_red);

                    DA.SetData(23, ehub.outputs.cost + (rent * -1 * gfa));
                }
                else
                {
                    DA.SetData(0, 10000000);    // penalty value. should never get so high otherwise
                    DA.SetData(1, 200);         // same
                    DA.SetData(23, 10000000);
                }
            }
        }
コード例 #6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string filePath = null;

            if (!DA.GetData(0, ref filePath))
            {
                return;
            }
            if (!filePath.EndsWith(@"\"))
            {
                filePath = filePath + @"\";
            }

            var heating     = new List <double>();
            var cooling     = new List <double>();
            var dhw         = new List <double>();
            var electricity = new List <double>();

            if (!DA.GetDataList(1, heating))
            {
                return;
            }
            if (!DA.GetDataList(2, cooling))
            {
                return;
            }
            if (!DA.GetDataList(3, dhw))
            {
                return;
            }
            if (!DA.GetDataList(4, electricity))
            {
                return;
            }

            var solarAreas = new List <double>();

            if (!DA.GetDataList(5, solarAreas))
            {
                return;
            }

            GH_Structure <GH_Number> solarPotentials;

            if (!DA.GetDataTree(6, out solarPotentials))
            {
                return;
            }
            List <List <double> > solarPotList = new List <List <double> >();

            for (int i = 0; i < solarPotentials.Branches.Count; i++)
            {
                solarPotList.Add(new List <double>());
                foreach (GH_Number gooNumber in solarPotentials.get_Branch(i))
                {
                    double numb;
                    GH_Convert.ToDouble(gooNumber, out numb, GH_Conversion.Both);
                    solarPotList[i].Add(numb);
                }
            }

            var irradiance = new double[solarPotList.Count][];

            for (int i = 0; i < solarPotList.Count; i++)
            {
                irradiance[i] = solarPotList[i].ToArray();
            }


            var ghi     = new List <double>();
            var dryBulb = new List <double>();

            if (!DA.GetDataList(7, ghi))
            {
                return;
            }
            if (!DA.GetDataList(8, dryBulb))
            {
                return;
            }


            bool run = false;

            DA.GetData(9, ref run);

            int epsilonCuts = 3;

            DA.GetData(10, ref epsilonCuts);


            if (run)
            {
                try
                {
                    LoadTechParameters(filePath + "technologies.csv", out var technologyParameters);
                    technologyParameters.Add("NumberOfBuildingsInEHub", Convert.ToDouble(1));
                    technologyParameters.Add("Peak_Htg_" + Convert.ToString(0), heating.Max());
                    technologyParameters.Add("Peak_Clg_" + Convert.ToString(0), cooling.Max());
                    Rhino.RhinoApp.WriteLine("_____LOADING INPUTS COMPLETE_____");
                    Rhino.RhinoApp.WriteLine("_________________________________");
                    Rhino.RhinoApp.WriteLine("_____CLUSTERING TYPICAL DAYS_____");

                    int numberOfSolarAreas = solarAreas.Count;
                    int numBaseLoads       = 5; // heating, cooling, electricity, ghi, tamb
                    int numLoads           =
                        numBaseLoads +
                        numberOfSolarAreas; // heating, cooling, electricity, ghi, tamb, solar. however, solar will include several profiles.
                    const int  hoursPerYear   = 8760;
                    double[][] fullProfiles   = new double[numLoads][];
                    string[]   loadTypes      = new string[numLoads];
                    bool[]     peakDays       = new bool[numLoads];
                    bool[]     correctionLoad = new bool[numLoads];
                    for (int u = 0; u < numLoads; u++)
                    {
                        fullProfiles[u] = new double[hoursPerYear];
                    }
                    loadTypes[0]      = "heating";
                    loadTypes[1]      = "cooling";
                    loadTypes[2]      = "electricity";
                    loadTypes[3]      = "ghi";
                    loadTypes[4]      = "Tamb";
                    peakDays[0]       = true;
                    peakDays[1]       = true;
                    peakDays[2]       = true;
                    peakDays[3]       = false;
                    peakDays[4]       = false;
                    correctionLoad[0] = true;
                    correctionLoad[1] = true;
                    correctionLoad[2] = true;
                    correctionLoad[3] = false;
                    correctionLoad[4] = false;

                    bool[]
                    useForClustering =
                        new bool[fullProfiles
                                 .Length]; // specificy here, which load is used for clustering. the others are just reshaped
                    for (int t = 0; t < hoursPerYear; t++)
                    {
                        fullProfiles[0][t]  = heating[t] + dhw[t];
                        fullProfiles[1][t]  = cooling[t];
                        fullProfiles[2][t]  = electricity[t];
                        fullProfiles[3][t]  = ghi[t];
                        fullProfiles[4][t]  = dryBulb[t];
                        useForClustering[0] = true;
                        useForClustering[1] = true;
                        useForClustering[2] = true;
                        useForClustering[3] = true;
                        useForClustering[4] = false;
                    }

                    for (int u = 0; u < numberOfSolarAreas; u++)
                    {
                        useForClustering[u + numBaseLoads] = false;
                        peakDays[u + numBaseLoads]         = false;
                        correctionLoad[u + numBaseLoads]   = true;
                        loadTypes[u + numBaseLoads]        = "solar";
                        for (int t = 0; t < hoursPerYear; t++)
                        {
                            fullProfiles[u + numBaseLoads][t] = irradiance[u][t];
                        }
                    }

                    // TO DO: load in GHI time series, add it to full profiles (right after heating, cooling, elec), and use it for clustering. exclude other solar profiles from clustering, but they need to be reshaped too
                    EhubMisc.HorizonReduction.TypicalDays typicalDays = EhubMisc.HorizonReduction.GenerateTypicalDays(
                        fullProfiles, loadTypes,
                        12, peakDays, useForClustering, correctionLoad, true);

                    /// Running Energy Hub
                    Rhino.RhinoApp.WriteLine("Solving MILP optimization model...");
                    double[][] typicalSolarLoads = new double[numberOfSolarAreas][];

                    // solar profiles negative or very small numbers. rounding floating numbers thing?
                    for (int u = 0; u < numberOfSolarAreas; u++)
                    {
                        typicalSolarLoads[u] = typicalDays.DayProfiles[numBaseLoads + u];
                        for (int t = 0; t < typicalSolarLoads[u].Length; t++)
                        {
                            if (typicalSolarLoads[u][t] < 0.1)
                            {
                                typicalSolarLoads[u][t] = 0.0;
                            }
                        }
                    }

                    // same for heating, cooling, elec demand... round very small numbers
                    for (int t = 0; t < typicalDays.DayProfiles[0].Length; t++)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            if (typicalDays.DayProfiles[i][t] < 0.001)
                            {
                                typicalDays.DayProfiles[i][t] = 0.0;
                            }
                        }
                    }


                    int[] clustersizePerTimestep = typicalDays.NumberOfDaysPerTimestep;
                    Ehub  ehub = new Ehub(typicalDays.DayProfiles[0], typicalDays.DayProfiles[1],
                                          typicalDays.DayProfiles[2],
                                          typicalSolarLoads, solarAreas.ToArray(),
                                          typicalDays.DayProfiles[4], technologyParameters,
                                          clustersizePerTimestep);
                    ehub.Solve(epsilonCuts, true);

                    Rhino.RhinoApp.WriteLine("___________________________");
                    Rhino.RhinoApp.WriteLine("ENERGY HUB SOLVER COMPLETED");

                    var capex     = new List <double>();
                    var opex      = new List <double>();
                    var emissions = new List <double>();
                    for (int i = 0; i < ehub.Outputs.Length; i++)
                    {
                        capex.Add(ehub.Outputs[i].CAPEX);
                        opex.Add(ehub.Outputs[i].OPEX);
                        emissions.Add(ehub.Outputs[i].carbon);
                    }
                    DA.SetDataList(0, capex);
                    DA.SetDataList(1, opex);
                    DA.SetDataList(2, emissions);


                    WriteOutput("EaCS3_HS21_Results_Ehub", filePath, numberOfSolarAreas, ehub, typicalDays, numBaseLoads);
                    Rhino.RhinoApp.WriteLine("___________________________");
                    Rhino.RhinoApp.WriteLine("RESULTS WRITTEN TO" + filePath.ToString());
                }
                catch (Exception e)
                {
                    Rhino.RhinoApp.WriteLine(e.Message);
                    throw;
                }
            }



            // return results to outputs IN GH component
        }