401401 }
402402}
403403
404- f_setInitialValues ();
405-
406404v_isRapidRun = false ;
407405
408406double duration = System .currentTimeMillis () - startTime1 ;
409407
410408traceln ("*** headless run duration: " + duration /1000 + " s ***" );
411409
412410traceln ("Live-sim t_h after rapidRun: %s" , t_h );
411+ if (b_isDeserialised ) {
412+ traceln ("Anylogic Model time(HOUR): %s" , time (HOUR ));
413+ }
413414c_profiles .forEach (p -> p .updateValue (t_h ));
414415c_forecasts .forEach (p -> p .initializeForecast (t_h ));
415416
495496double topLevelElectricGridCapacity_kW = 0 ;
496497boolean topLevelGridCapacitiesKnown = true ;
497498
498- // First make all links between GridNodes
499+ // First make all links between GridNodes
499500for ( GridNode GN : pop_gridNodes ) {
500501 GN .f_connectToParentNode ();
501502}
502503
504+ // First clear lists (needed after deserialisation)
505+ c_gridNodeExecutionList .clear ();
506+ c_gridNodeExecutionListReverse .clear ();
507+ c_gridNodesTopLevel .clear ();
508+ c_gridNodesNotTopLevel .clear ();
509+
503510// Then build execution order list
504511for ( GridNode GN : pop_gridNodes ) {
505512 GridNode parentNode = findFirst (pop_gridNodes , p ->p .p_gridNodeID .equals (GN .p_parentNodeID )); // Works as long as p_gridNodeID is not null. p_parentNodeID can be null no problemo.
524531c_gridNodeExecutionListReverse = c_gridNodeExecutionList ;
525532Collections .reverse (c_gridNodeExecutionList );
526533
534+
527535//Set cumulative toplevel grid values as energyModel values
528536v_liveConnectionMetaData .physicalCapacity_kW = topLevelElectricGridCapacity_kW ;
529537v_liveConnectionMetaData .contractedDeliveryCapacity_kW = topLevelElectricGridCapacity_kW ;
@@ -563,15 +571,15 @@ ArrayList<GridConnection> f_getActiveGridConnections()
563571//v_hourOfYearStart=hourOfYearPerMonth[getMonth()] + (getDayOfMonth()-1)*24;
564572t_h = p_runStartTime_h ;
565573
574+ Date startDate = date ();
575+ p_year = startDate .getYear () + 1900 ;
576+
566577LocalDate localDate = LocalDate .of (p_year , 1 , 1 );
567578v_dayOfWeek1jan = DayOfWeek .from (localDate ).getValue ();
568579p_startOfWinterWeek_h = roundToInt (24 * (p_winterWeekNumber * 7 + (8 -v_dayOfWeek1jan )%7 )); // Week 49 is winterweek.
569580p_startOfSummerWeek_h = roundToInt (24 * (p_summerWeekNumber * 7 + (8 -v_dayOfWeek1jan )%7 )); // Week 18 is summerweek.
570581
571582
572- Date startDate = date ();
573-
574- p_year = startDate .getYear () + 1900 ;
575583
576584int monthIdx = 0 ;
577585while ( t_h > hourOfYearPerMonth [monthIdx ] ) {
@@ -586,6 +594,8 @@ ArrayList<GridConnection> f_getActiveGridConnections()
586594traceln ("Month of year start: %s" , monthIdx );
587595startDate .setMonth (monthIdx );
588596startDate .setDate (dayOfMonth );
597+ startDate .setHours (0 );
598+ startDate .setMinutes (0 );
589599traceln ("Startdate: %s" , startDate );
590600//startDate.set
591601getExperiment ().getEngine ().setStartDate (startDate );
@@ -639,10 +649,6 @@ ArrayList<GridConnection> f_getActiveGridConnections()
639649 b_parallelizeConnectionOwners = true ;
640650}
641651
642- // set initial values
643- f_setInitialValues ();
644-
645-
646652b_isInitialized = true ;
647653/*ALCODEEND*/ }
648654
@@ -671,14 +677,6 @@ ArrayList<GridNode> f_getGridNodesNotTopLevel()
671677return this .c_gridNodesNotTopLevel ;
672678/*ALCODEEND*/ }
673679
674- double f_setInitialValues ()
675- {/*ALCODESTART::1722853692644*/
676- // Starting prices
677- //c_gridConnections.forEach(GC -> GC.v_electricityPriceLowPassed_eurpkWh = c_gridNodesTopLevel.get(0).v_currentParentNodalPrice_eurpkWh); // Initialize filtered prices for gridConnections, hoping to prevent or reduce initial settling excursions
678-
679-
680- /*ALCODEEND*/ }
681-
682680double f_initializePause ()
683681{/*ALCODESTART::1722590514591*/
684682for (GridConnection GC : UtilityConnections ) {
@@ -1040,15 +1038,15 @@ EnergyCoop f_addProductionEnergyCarrier(OL_EnergyCarriers EC)
10401038double f_startAfterDeserialisation ()
10411039{/*ALCODESTART::1753963201170*/
10421040// Reconstruct the LiveData class
1043- v_liveData = new J_LiveData (this );
1041+ /* v_liveData = new J_LiveData(this);
10441042v_liveData.activeEnergyCarriers = EnumSet.of(OL_EnergyCarriers.ELECTRICITY);
10451043v_liveData.activeProductionEnergyCarriers = EnumSet.of(OL_EnergyCarriers.ELECTRICITY);
10461044v_liveData.activeConsumptionEnergyCarriers = EnumSet.of(OL_EnergyCarriers.ELECTRICITY);
10471045
10481046//v_liveConnectionMetaData = new J_ConnectionMetaData(this);
10491047//v_liveAssetsMetaData = new J_AssetsMetaData(this);
10501048v_liveData.connectionMetaData = v_liveConnectionMetaData;
1051- v_liveData .assetsMetaData = v_liveAssetsMetaData ;
1049+ v_liveData.assetsMetaData = v_liveAssetsMetaData;*/
10521050
10531051v_liveData .resetLiveDatasets (p_runStartTime_h , p_runStartTime_h , p_timeStep_h );
10541052
@@ -1059,14 +1057,14 @@ EnergyCoop f_addProductionEnergyCarrier(OL_EnergyCarriers EC)
10591057
10601058// Reconstruct the LiveData class in the EnergyCoops
10611059for (EnergyCoop ec : pop_energyCoops ) {
1062- ec .v_liveData = new J_LiveData (ec );
1060+ /* ec.v_liveData = new J_LiveData(ec);
10631061 ec.v_liveData.activeEnergyCarriers = EnumSet.of(OL_EnergyCarriers.ELECTRICITY);
10641062 ec.v_liveData.activeProductionEnergyCarriers = EnumSet.of(OL_EnergyCarriers.ELECTRICITY);
10651063 ec.v_liveData.activeConsumptionEnergyCarriers = EnumSet.of(OL_EnergyCarriers.ELECTRICITY);
10661064
10671065 ec.v_liveData.connectionMetaData = ec.v_liveConnectionMetaData;
10681066 ec.v_liveData.assetsMetaData = ec.v_liveAssetsMetaData;
1069-
1067+ */
10701068 ec .v_liveData .resetLiveDatasets (p_runStartTime_h , p_runStartTime_h , p_timeStep_h );
10711069
10721070 ec .fm_currentProductionFlows_kW = new J_FlowsMap ();
@@ -1079,35 +1077,62 @@ EnergyCoop f_addProductionEnergyCarrier(OL_EnergyCarriers EC)
10791077List <GridConnection > allGridConnections = new ArrayList <>(c_gridConnections );
10801078allGridConnections .addAll (c_pausedGridConnections );
10811079for (GridConnection gc : allGridConnections ) {
1082- gc .v_liveData = new J_LiveData (gc );
1080+ /* gc.v_liveData = new J_LiveData(gc);
10831081 gc.v_liveData.activeEnergyCarriers = EnumSet.of(OL_EnergyCarriers.ELECTRICITY);
10841082 gc.v_liveData.activeProductionEnergyCarriers = EnumSet.of(OL_EnergyCarriers.ELECTRICITY);
10851083 gc.v_liveData.activeConsumptionEnergyCarriers = EnumSet.of(OL_EnergyCarriers.ELECTRICITY);
10861084
10871085 gc.v_liveData.connectionMetaData = gc.v_liveConnectionMetaData;
10881086 gc.v_liveData.assetsMetaData = gc.v_liveAssetsMetaData;
1089-
1087+ */
10901088 gc .v_liveData .resetLiveDatasets (p_runStartTime_h , p_runStartTime_h , p_timeStep_h );
10911089
10921090 gc .fm_currentProductionFlows_kW = new J_FlowsMap ();
10931091 gc .fm_currentConsumptionFlows_kW = new J_FlowsMap ();
10941092 gc .fm_currentBalanceFlows_kW = new J_FlowsMap ();
10951093 gc .fm_currentAssetFlows_kW = new J_ValueMap (OL_AssetFlowCategories .class );
10961094
1097- for (J_EA j_ea : gc .c_energyAssets ) {
1095+ /* for (J_EA j_ea : gc.c_energyAssets) {
10981096 gc.f_addEnergyCarriersAndAssetCategoriesFromEA(j_ea);
1099- }
1097+ }*/
11001098}
11011099
1102- //v_liveData.activeEnergyCarriers = EnumSet.of(OL_EnergyCarriers.ELECTRICITY, OL_EnergyCarriers.HEAT, OL_EnergyCarriers.METHANE, OL_EnergyCarriers.DIESEL);
1103- //v_liveData.activeProductionEnergyCarriers = EnumSet.of(OL_EnergyCarriers.ELECTRICITY, OL_EnergyCarriers.HEAT);
1104- //v_liveData.activeConsumptionEnergyCarriers = EnumSet.of(OL_EnergyCarriers.ELECTRICITY, OL_EnergyCarriers.HEAT, OL_EnergyCarriers.METHANE, OL_EnergyCarriers.DIESEL);
1105- //for (J_EA j_ea : c_energyAssets) {
1106- //v_liveData.activeProductionEnergyCarriers.addAll(j_ea.activeProductionEnergyCarriers);
1107- //v_liveData.activeConsumptionEnergyCarriers.addAll(j_ea.activeConsumptionEnergyCarriers);
1108- //}
1100+ // Initialize time and date
1101+ //v_hourOfYearStart=hourOfYearPerMonth[getMonth()] + (getDayOfMonth()-1)*24;
1102+ t_h = p_runStartTime_h ;
1103+
1104+ Date startDate = date ();
1105+ p_year = startDate .getYear () + 1900 ;
1106+
1107+ LocalDate localDate = LocalDate .of (p_year , 1 , 1 );
1108+ v_dayOfWeek1jan = DayOfWeek .from (localDate ).getValue ();
1109+ p_startOfWinterWeek_h = roundToInt (24 * (p_winterWeekNumber * 7 + (8 -v_dayOfWeek1jan )%7 )); // Week 49 is winterweek.
1110+ p_startOfSummerWeek_h = roundToInt (24 * (p_summerWeekNumber * 7 + (8 -v_dayOfWeek1jan )%7 )); // Week 18 is summerweek.
1111+
1112+ int monthIdx = 0 ;
1113+ while ( t_h > hourOfYearPerMonth [monthIdx ] ) {
1114+ monthIdx ++;
1115+ if (monthIdx ==hourOfYearPerMonth .length ){
1116+ break ;
1117+ }
1118+ }
1119+
1120+ int dayOfMonth = 1 +(int )((t_h - hourOfYearPerMonth [monthIdx ])/24.0 );
1121+ traceln ("Day of month start: %s" , dayOfMonth );
1122+ traceln ("Month of year start: %s" , monthIdx );
1123+ startDate .setMonth (monthIdx );
1124+ startDate .setDate (dayOfMonth );
1125+ startDate .setHours (0 );
1126+ startDate .setMinutes (0 );
1127+ traceln ("Startdate: %s" , startDate );
1128+ //startDate.set
1129+ getExperiment ().getEngine ().setStartDate (startDate );
11091130
1131+ f_initializeForecasts ();
1132+
1133+ f_initializeLiveDataSets ();
11101134
1135+ b_isDeserialised = true ;
11111136/*ALCODEEND*/ }
11121137
11131138Pair <J_DataSetMap , J_DataSetMap > f_getPeakWeekDataSets ()
@@ -1235,3 +1260,76 @@ Date f_getDate()
12351260c_pausedGridConnections .forEach (GC -> GC .v_liveData .clearLiveDatasets ());
12361261/*ALCODEEND*/ }
12371262
1263+ double f_initializeEngineAfterLoad ()
1264+ {/*ALCODESTART::1758792939882*/
1265+ // Initialize time and date
1266+ //v_hourOfYearStart=hourOfYearPerMonth[getMonth()] + (getDayOfMonth()-1)*24;
1267+ t_h = p_runStartTime_h ;
1268+
1269+ Date startDate = date ();
1270+ p_year = startDate .getYear () + 1900 ;
1271+
1272+ LocalDate localDate = LocalDate .of (p_year , 1 , 1 );
1273+ v_dayOfWeek1jan = DayOfWeek .from (localDate ).getValue ();
1274+ p_startOfWinterWeek_h = roundToInt (24 * (p_winterWeekNumber * 7 + (8 -v_dayOfWeek1jan )%7 )); // Week 49 is winterweek.
1275+ p_startOfSummerWeek_h = roundToInt (24 * (p_summerWeekNumber * 7 + (8 -v_dayOfWeek1jan )%7 )); // Week 18 is summerweek.
1276+
1277+ int monthIdx = 0 ;
1278+ while ( t_h > hourOfYearPerMonth [monthIdx ] ) {
1279+ monthIdx ++;
1280+ if (monthIdx ==hourOfYearPerMonth .length ){
1281+ break ;
1282+ }
1283+ }
1284+
1285+ int dayOfMonth = 1 +(int )((t_h - hourOfYearPerMonth [monthIdx ])/24.0 );
1286+ traceln ("Day of month start: %s" , dayOfMonth );
1287+ traceln ("Month of year start: %s" , monthIdx );
1288+ startDate .setMonth (monthIdx );
1289+ startDate .setDate (dayOfMonth );
1290+ startDate .setHours (0 );
1291+ startDate .setMinutes (0 );
1292+ traceln ("Startdate: %s" , startDate );
1293+ //startDate.set
1294+ getExperiment ().getEngine ().setStartDate (startDate );
1295+
1296+
1297+
1298+ // Initialize all agents in the correct order, creating all connections. What about setting initial values? And how about repeated simulations?
1299+
1300+ /*f_buildGridNodeTree();
1301+ c_gridConnections.forEach(GC -> GC.f_initialize());
1302+
1303+ // Only relevant for deserialisation:
1304+ c_pausedGridConnections.forEach(GC -> GC.f_initialize());
1305+
1306+ pop_connectionOwners.forEach(CO -> CO.f_initialize());
1307+ pop_energyCoops.forEach(EC -> EC.f_initialize()); // Not yet robust when there is no supplier initialized!
1308+
1309+
1310+
1311+ // Initializing Live Data Class
1312+ v_liveAssetsMetaData.updateActiveAssetData(c_gridConnections);
1313+ for (GridConnection GC : c_gridConnections) {
1314+ v_liveData.activeEnergyCarriers.addAll(GC.v_liveData.activeEnergyCarriers);
1315+ v_liveData.activeConsumptionEnergyCarriers.addAll(GC.v_liveData.activeConsumptionEnergyCarriers);
1316+ v_liveData.activeProductionEnergyCarriers.addAll(GC.v_liveData.activeProductionEnergyCarriers);
1317+ }
1318+
1319+ // Loop over populations to check v_ispaused
1320+ f_initializePause();
1321+
1322+ for (GridNode GN : c_gridNodeExecutionList) {
1323+ GN.f_initializeGridnode();
1324+ }
1325+
1326+ v_liveData.connectionMetaData.contractedDeliveryCapacityKnown = false;
1327+ v_liveData.connectionMetaData.contractedFeedinCapacityKnown = false;
1328+ v_liveData.connectionMetaData.physicalCapacityKnown = false;
1329+ */
1330+ f_initializeForecasts ();
1331+
1332+ f_initializeLiveDataSets ();
1333+
1334+ /*ALCODEEND*/ }
1335+
0 commit comments