forked from irena-flextool/flextool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flexModel3.mod
3727 lines (3431 loc) · 203 KB
/
flexModel3.mod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# © International Renewable Energy Agency 2018-2022
#The FlexTool is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
#as published by the Free Software Foundation, either §ersion 3 of the License, or (at your option) any later version.
#The FlexTool is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
#without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#You should have received a copy of the GNU Lesser General Public License along with the FlexTool.
#If not, see <https://www.gnu.org/licenses/>.
#Author: Juha Kiviluoma (2017-2022), VTT Technical Research Centre of Finland
param datetime0 := gmtime();
display datetime0;
#########################
# Fundamental sets of the model
set entity 'e - contains both nodes and processes';
set process 'p - Particular activity that transfers, converts or stores commodities' within entity;
set processUnit 'Unit processes' within process;
set node 'n - Any location where a balance needs to be maintained' within entity;
set group 'g - Any group of entities that have a set of common constraints';
set commodity 'c - Stuff that is being processed';
set period_time '(d, t) - Time steps in the time periods of the whole timeline' dimen 2;
set period__time_first within period_time;
set period__time_last within period_time;
set solve_period_timeblockset '(solve, d, tb) - All solve, period, timeblockset combinations in the model instance' dimen 3;
set solve_period '(solve, d) - Time periods in the solves to extract periods that can be found in the full data' := setof {(s, d, tb) in solve_period_timeblockset} (s, d);
set period_solve 'picking up periods from solve_period' := setof {(s,d) in solve_period} (d);
set solve_current 'current solve name' dimen 1;
set period 'd - Time periods in the current solve' := setof {(d, t) in period_time} (d);
set period_first := {d in period : sum{d2 in period : d2 <= d} 1 = 1};
set period_last := {d in period : sum{d2 in period : d2 <= d} 1 = card(period)};
set timeline__timestep__duration dimen 3;
set time 't - Time steps in the current timelines' := setof {(tl, t, duration) in timeline__timestep__duration} (t);
set timeblockset__timeline dimen 2;
set timeline := setof{(tb, tl) in timeblockset__timeline} (tl);
set period__timeline := {d in period, tl in timeline : sum{(s, d, tb) in solve_period_timeblockset : s in solve_current && (tb, tl) in timeblockset__timeline} 1};
set method 'm - Type of process that transfers, converts or stores commodities';
set upDown 'upward and downward directions for some variables';
set ct_method;
set ct_method_constant within ct_method;
set ct_method_regular within ct_method;
set startup_method;
set startup_method_no within startup_method;
set fork_method;
set fork_method_yes within fork_method;
set fork_method_no within fork_method;
set reserve_method;
set ramp_method;
set ramp_limit_method within ramp_method;
set ramp_cost_method within ramp_method;
set profile;
set profile_method;
set debug 'flags to output debugging and test results';
set test_dt 'a shorter set of time steps for printing out test results' dimen 2;
set test_t dimen 1;
set model 'dummy set because has to load a table';
set constraint 'user defined greater than, less than or equality constraints between inputs and outputs';
set sense 'sense of user defined constraints';
set sense_greater_than within sense;
set sense_less_than within sense;
set sense_equal within sense;
set commodityParam;
set commodityPeriodParam within commodityParam;
set nodeParam;
set nodePeriodParam;
set nodeTimeParam within nodeParam;
set processParam;
set processPeriodParam;
set processTimeParam within processParam;
set sourceSinkParam;
set sourceSinkTimeParam within sourceSinkParam;
set reserveParam;
set reserveTimeParam within reserveParam;
set groupParam;
set groupPeriodParam;
set groupTimeParam within groupParam;
set reserve__upDown__group__method dimen 4;
set reserve__upDown__group := setof {(r, ud, g, m) in reserve__upDown__group__method : m <> 'no_reserve'} (r, ud, g);
set reserve 'r - Categories for the reservation of capacity_existing' := setof {(r, ud, ng, r_m) in reserve__upDown__group__method} (r);
set reserve__upDown__group__reserveParam__time dimen 5 within {reserve, upDown, group, reserveTimeParam, time};
set group__param dimen 2 within {group, groupParam};
set group__param__period dimen 3; # within {group, groupPeriodParam, periodAll};
set node__param__period dimen 3; # within {node, nodePeriodParam, periodAll};
set commodity__param__period dimen 3; # within {commodity, commodityPeriodParam, periodAll};
set process__param__period dimen 3; # within {process, processPeriodParam, periodAll};
set period_group 'picking up periods from group data' := setof {(n, param, d) in group__param__period} (d);
set period_node 'picking up periods from node data' := setof {(n, param, d) in node__param__period} (d);
set period_commodity 'picking up periods from commodity data' := setof {(n, param, d) in commodity__param__period} (d);
set period_process 'picking up periods from process data' := setof {(n, param, d) in process__param__period} (d);
set periodAll 'd - Time periods in data (including those currently in use)' := period_group union period_node union period_commodity union period_process union period_solve;
param p_group {g in group, groupParam} default 0;
param pd_group {g in group, groupPeriodParam, d in periodAll} default 0;
param p_group__process {g in group, p in process, groupParam};
#Method collections use in the model (abstracted methods)
set method_1var_off within method;
set method_1way_off within method;
set method_1way_LP within method;
set method_1way_MIP within method;
set method_2way_off within method;
set method_1way_1var_on within method;
set method_1way_nvar_on within method;
set method_1way within method;
set method_1way_1var within method;
set method_2way_1var within method;
set method_2way within method;
set method_2way_2var within method;
set method_2way_nvar within method;
set method_1way_on within method;
set method_2way_on within method;
set method_1var within method;
set method_nvar within method;
set method_off within method;
set method_on within method;
set method_LP within method;
set method_MIP within method;
set method_direct within method;
set method_indirect within method;
set method_1var_per_way within method;
set invest_method 'methods available for investments';
set invest_method_not_allowed 'method for denying investments' within invest_method;
set divest_method_not_allowed 'method for denying divestments' within invest_method;
set co2_method 'methods available for co2 price and limits';
set co2_price_method within co2_method;
set co2_max_period_method within co2_method;
set co2_max_total_method within co2_method;
set entity__invest_method 'the investment method applied to an entity' dimen 2 within {entity, invest_method};
set entityDivest := setof {(e, m) in entity__invest_method : m not in divest_method_not_allowed} (e);
set entityInvest := setof {(e, m) in entity__invest_method : m not in invest_method_not_allowed} (e);
param investableEntities := sum{e in entityInvest} 1;
set group__invest_method 'the investment method applied to a group' dimen 2 within {group, invest_method};
set group_invest := setof {(g, m) in group__invest_method : m not in invest_method_not_allowed} (g);
set group_divest := setof {(g, m) in group__invest_method : m not in divest_method_not_allowed} (g);
set group__co2_method 'the investment method applied to a group' dimen 2 within {group, co2_method};
set group_co2_price := setof {(g, m) in group__co2_method : m in co2_price_method} (g);
set group_co2_max_period := setof {(g, m) in group__co2_method : m in co2_max_period_method} (g);
set group_co2_max_total := setof {(g, m) in group__co2_method : m in co2_max_total_method} (g);
set nodeBalance 'nodes that maintain a node balance' within node;
set nodeState 'nodes that have a state' within node;
set inflow_method 'method for scaling the inflow';
set inflow_method_default within inflow_method;
set node__inflow_method_read 'method for scaling the inflow applied to a node' within {node, inflow_method};
set node__inflow_method dimen 2 within {node, inflow_method} :=
{n in node, m in inflow_method : (n, m) in node__inflow_method_read || (sum{(n, m2) in node__inflow_method_read} 1 = 0 && m in inflow_method_default)};
set storage_binding_method 'methods for binding storage state between periods';
set storage_binding_method_default within storage_binding_method;
set node__storage_binding_method_read within {node, storage_binding_method};
set node__storage_binding_method dimen 2 within {node, storage_binding_method} :=
{n in node, m in storage_binding_method : (n, m) in node__storage_binding_method_read || (sum{(n, m2) in node__storage_binding_method_read} 1 = 0 && m in storage_binding_method_default)};
set storage_start_end_method 'method to fix start and/or end value of storage in a model run';
set node__storage_start_end_method within {node, storage_start_end_method};
set storage_solve_horizon_method 'methods to set reference value or price for the end of horizon storage state';
set node__storage_solve_horizon_method within {node, storage_solve_horizon_method};
set node__profile__profile_method dimen 3 within {node,profile,profile_method};
set group_node 'member nodes of a particular group' dimen 2 within {group, node};
set group_process 'member processes of a particular group' dimen 2 within {group, process};
set group_process_node 'process__nodes of a particular group' dimen 3 within {group, process, node};
set group_entity := group_process union group_node;
set groupInertia 'node groups with an inertia constraint' within group;
set groupNonSync 'node groups with a non-synchronous constraint' within group;
set groupCapacityMargin 'node groups with a capacity margin' within group;
set groupOutput 'groups that will output aggregated results' within group;
set groupOutput_process 'output groups with process members' :=
{g in groupOutput : sum{(g, p, n) in group_process_node} 1};
set groupOutput_node 'output groups with node members' :=
{g in groupOutput : sum{(g, n) in group_node} 1 };
set process_unit 'processes that are unit' within process;
set process_connection 'processes that are connections' within process;
set process__ct_method_read dimen 2 within {process, ct_method};
set process__ct_method dimen 2 within {process, ct_method} :=
{p in process, m in ct_method
: (p, m) in process__ct_method_read
|| (sum{(p, m2) in process__ct_method_read} 1 = 0 && p in process_connection && m in ct_method_regular)
|| (sum{(p, m2) in process__ct_method_read} 1 = 0 && p in process_unit && m in ct_method_constant)};
set process__startup_method_read dimen 2 within {process, startup_method} default {p in process, 'no_startup'} ;
set process__startup_method dimen 2 within {process, startup_method}:=
{p in process, m in startup_method : (p, m) in process__startup_method_read || (sum{(p, m2) in process__startup_method_read} 1 = 0 && m in startup_method_no)};
set process_node_ramp_method dimen 3 within {process, node, ramp_method};
set methods dimen 4;
set process__profile__profile_method dimen 3 within {process, profile, profile_method};
set process__node__profile__profile_method dimen 4 within {process, node, profile, profile_method};
set process_source dimen 2 within {process, entity};
set process_sink dimen 2 within {process, entity};
set process__sink_nonSync_unit dimen 2 within {process, node};
set process_nonSync_connection dimen 1 within {process};
set process_reserve_upDown_node dimen 4;
set process_node_flow_constraint dimen 3 within {process, node, constraint};
set process_capacity_constraint dimen 2 within {process, constraint};
set node_capacity_constraint dimen 2 within {node, constraint};
set node_state_constraint dimen 2 within {node, constraint};
set constraint__sense dimen 2 within {constraint, sense};
set commodity_node dimen 2 within {commodity, node};
set dt dimen 2 within period_time;
param dt_jump {(d, t) in dt};
set dtttdt dimen 6;
set period_invest dimen 1 within period;
set period_realized dimen 1 within period;
set time_in_use := setof {(d, t) in dt} (t);
set startTime dimen 1 within time;
set startNext dimen 1 within time;
param startNext_index := sum{t in time, t_startNext in startNext : t <= t_startNext} 1;
set modelParam;
set process__param dimen 2 within {process, processParam};
set process__param__time dimen 3 within {process, processTimeParam, time};
set process__param_t := setof {(p, param, t) in process__param__time} (p, param);
set connection__param := {(p, param) in process__param : p in process_connection};
set connection__param__time := { (p, param, t) in process__param__time : (p in process_connection)};
set connection__param_t := setof {(connection, param, t) in connection__param__time} (connection, param);
set process__source__param dimen 3 within {process_source, sourceSinkParam};
set process__source__param__time dimen 4 within {process_source, sourceSinkTimeParam, time};
set process__source__param_t := setof {(p, source, param, t) in process__source__param__time} (p, source, param);
set process__sink__param dimen 3 within {process_sink, sourceSinkParam};
set process__sink__param__time dimen 4 within {process_sink, sourceSinkTimeParam, time};
set process__sink__param_t := setof {(p, sink, param, t) in process__sink__param__time} (p, sink, param);
set node__param__time dimen 3 within {node, nodeTimeParam, time};
set node__param_t := setof {(n, param, t) in node__param__time} (n, param);
param p_model {modelParam};
param p_commodity {c in commodity, commodityParam} default 0;
param pd_commodity {c in commodity, commodityPeriodParam, d in periodAll} default 0;
param p_node {node, nodeParam} default 0;
param pd_node {node, nodePeriodParam, periodAll} default 0;
param pt_node {node, nodeTimeParam, time} default 0;
param p_process_source {(p, source) in process_source, sourceSinkParam} default 0;
param pt_process_source {(p, source) in process_source, sourceSinkTimeParam, time} default 0;
param p_process_sink {(p, sink) in process_sink, sourceSinkParam} default 0;
param pt_process_sink {(p, sink) in process_sink, sourceSinkTimeParam, time} default 0;
param p_process_source_coefficient {(p, source) in process_source} default 1;
param p_process_sink_coefficient {(p, sink) in process_sink} default 1;
param pt_profile {profile, time};
param p_reserve_upDown_group {reserve, upDown, group, reserveParam} default 0;
param pt_reserve_upDown_group {reserve, upDown, group, reserveTimeParam, time};
param p_process_reserve_upDown_node {process, reserve, upDown, node, reserveParam} default 0;
param p_process {process, processParam} default 0;
param pd_process {process, processPeriodParam, periodAll} default 0;
param pt_process {process, processTimeParam, time} default 0;
param p_constraint_constant {constraint};
param p_process_node_constraint_flow_coefficient {process, node, constraint};
param p_process_constraint_capacity_coefficient {process, constraint};
param p_node_constraint_capacity_coefficient {node, constraint};
param p_node_constraint_state_coefficient {node, constraint};
param penalty_up {n in nodeBalance};
param penalty_down {n in nodeBalance};
param step_duration{(d, t) in dt};
param p_timeline_duration_in_years{timeline};
param p_discount_years{d in period} default 0;
param p_discount_rate{model} default 0.05;
param p_discount_offset_investment{model} default 1; # Calculate investment cost discounting while assuming they are made at the begining of the year (unless other value is given)
param p_discount_offset_operations{model} default 0.5; # Calculate operational costs assuming they are on average taking place at the middle of the year (unless other value is given)
param p_entity_invested {e in entity : e in entityInvest};
param p_entity_divested {e in entity : e in entityInvest};
param scale_the_objective;
param scale_the_state;
set param_costs dimen 1;
param costs_discounted {param_costs} default 0;
#########################
# Read data
#table data IN 'CSV' '.csv' : <- [];
# Domain sets
table data IN 'CSV' 'input/commodity.csv' : commodity <- [commodity];
table data IN 'CSV' 'input/constraint__sense.csv' : constraint <- [constraint];
table data IN 'CSV' 'input/debug.csv': debug <- [debug];
table data IN 'CSV' 'input/entity.csv': entity <- [entity];
table data IN 'CSV' 'input/group.csv' : group <- [group];
table data IN 'CSV' 'input/node.csv' : node <- [node];
table data IN 'CSV' 'input/nodeBalance.csv' : nodeBalance <- [nodeBalance];
table data IN 'CSV' 'input/nodeState.csv' : nodeState <- [nodeState];
table data IN 'CSV' 'input/groupInertia.csv' : groupInertia <- [groupInertia];
table data IN 'CSV' 'input/groupNonSync.csv' : groupNonSync <- [groupNonSync];
table data IN 'CSV' 'input/groupCapacityMargin.csv' : groupCapacityMargin <- [groupCapacityMargin];
table data IN 'CSV' 'input/groupOutput.csv' : groupOutput <- [groupOutput];
table data IN 'CSV' 'input/process.csv': process <- [process];
table data IN 'CSV' 'input/profile.csv': profile <- [profile];
# Single dimension membership sets
table data IN 'CSV' 'input/process_connection.csv': process_connection <- [process_connection];
table data IN 'CSV' 'input/process_nonSync_connection.csv': process_nonSync_connection <- [process];
table data IN 'CSV' 'input/process_unit.csv': process_unit <- [process_unit];
# Multi dimension membership sets
table data IN 'CSV' 'input/commodity__node.csv' : commodity_node <- [commodity,node];
table data IN 'CSV' 'input/entity__invest_method.csv' : entity__invest_method <- [entity,invest_method];
table data IN 'CSV' 'input/group__invest_method.csv' : group__invest_method <- [group,invest_method];
table data IN 'CSV' 'input/group__co2_method.csv' : group__co2_method <- [group,co2_method];
table data IN 'CSV' 'input/node__inflow_method.csv' : node__inflow_method_read <- [node,inflow_method];
table data IN 'CSV' 'input/node__storage_binding_method.csv' : node__storage_binding_method_read <- [node,storage_binding_method];
table data IN 'CSV' 'input/node__storage_start_end_method.csv' : node__storage_start_end_method <- [node,storage_start_end_method];
table data IN 'CSV' 'input/node__storage_solve_horizon_method.csv' : node__storage_solve_horizon_method <- [node,storage_solve_horizon_method];
table data IN 'CSV' 'input/node__profile__profile_method.csv' : node__profile__profile_method <- [node,profile,profile_method];
table data IN 'CSV' 'input/group__node.csv' : group_node <- [group,node];
table data IN 'CSV' 'input/group__process.csv' : group_process <- [group,process];
table data IN 'CSV' 'input/group__process__node.csv' : group_process_node <- [group,process,node];
table data IN 'CSV' 'input/p_process_node_constraint_flow_coefficient.csv' : process_node_flow_constraint <- [process, node, constraint];
table data IN 'CSV' 'input/p_process_constraint_capacity_coefficient.csv' : process_capacity_constraint <- [process, constraint];
table data IN 'CSV' 'input/p_node_constraint_capacity_coefficient.csv' : node_capacity_constraint <- [node, constraint];
table data IN 'CSV' 'input/p_node_constraint_state_coefficient.csv' : node_state_constraint <- [node, constraint];
table data IN 'CSV' 'input/constraint__sense.csv' : constraint__sense <- [constraint, sense];
table data IN 'CSV' 'input/p_process.csv' : process__param <- [process, processParam];
table data IN 'CSV' 'input/pd_node.csv' : node__param__period <- [node, nodeParam, period];
table data IN 'CSV' 'input/pt_node.csv' : node__param__time <- [node, nodeParam, time];
table data IN 'CSV' 'input/pd_process.csv' : process__param__period <- [process, processParam, period];
table data IN 'CSV' 'input/pt_process.csv' : process__param__time <- [process, processParam, time];
table data IN 'CSV' 'input/p_group.csv' : group__param <- [group, groupParam];
table data IN 'CSV' 'input/pd_group.csv' : group__param__period <- [group, groupParam, period];
table data IN 'CSV' 'input/process__ct_method.csv' : process__ct_method_read <- [process,ct_method];
table data IN 'CSV' 'input/process__node__ramp_method.csv' : process_node_ramp_method <- [process,node,ramp_method];
table data IN 'CSV' 'input/process__reserve__upDown__node.csv' : process_reserve_upDown_node <- [process,reserve,upDown,node];
table data IN 'CSV' 'input/process__sink.csv' : process_sink <- [process,sink];
table data IN 'CSV' 'input/process__source.csv' : process_source <- [process,source];
table data IN 'CSV' 'input/process__sink_nonSync_unit.csv' : process__sink_nonSync_unit <- [process,sink];
table data IN 'CSV' 'input/process__startup_method.csv' : process__startup_method_read <- [process,startup_method];
table data IN 'CSV' 'input/process__profile__profile_method.csv' : process__profile__profile_method <- [process,profile,profile_method];
table data IN 'CSV' 'input/process__node__profile__profile_method.csv' : process__node__profile__profile_method <- [process,node,profile,profile_method];
table data IN 'CSV' 'input/reserve__upDown__group__method.csv' : reserve__upDown__group__method <- [reserve,upDown,group,method];
table data IN 'CSV' 'input/pt_reserve__upDown__group.csv' : reserve__upDown__group__reserveParam__time <- [reserve, upDown, group, reserveParam, time];
table data IN 'CSV' 'input/timeblocks_in_use.csv' : solve_period_timeblockset <- [solve,period,timeblocks];
table data IN 'CSV' 'input/timeblocks__timeline.csv' : timeblockset__timeline <- [timeblocks,timeline];
table data IN 'CSV' 'solve_data/solve_current.csv' : solve_current <- [solve];
table data IN 'CSV' 'input/p_process_source.csv' : process__source__param <- [process, source, sourceSinkParam];
table data IN 'CSV' 'input/pt_process_source.csv' : process__source__param__time <- [process, source, sourceSinkTimeParam, time];
table data IN 'CSV' 'input/p_process_sink.csv' : process__sink__param <- [process, sink, sourceSinkParam];
table data IN 'CSV' 'input/pt_process_sink.csv' : process__sink__param__time <- [process, sink, sourceSinkTimeParam, time];
table data IN 'CSV' 'input/pd_commodity.csv' : commodity__param__period <- [commodity, commodityParam, period];
table data IN 'CSV' 'input/timeline.csv' : timeline__timestep__duration <- [timeline,timestep,duration];
# Parameters for model data
table data IN 'CSV' 'input/p_commodity.csv' : [commodity, commodityParam], p_commodity;
table data IN 'CSV' 'input/pd_commodity.csv' : [commodity, commodityParam, period], pd_commodity;
table data IN 'CSV' 'input/p_group__process.csv' : [group, process, groupParam], p_group__process;
table data IN 'CSV' 'input/p_group.csv' : [group, groupParam], p_group;
table data IN 'CSV' 'input/pd_group.csv' : [group, groupParam, period], pd_group;
table data IN 'CSV' 'input/p_node.csv' : [node, nodeParam], p_node;
table data IN 'CSV' 'input/pd_node.csv' : [node, nodeParam, period], pd_node;
table data IN 'CSV' 'input/pt_node.csv' : [node, nodeParam, time], pt_node;
table data IN 'CSV' 'input/p_process_node_constraint_flow_coefficient.csv' : [process, node, constraint], p_process_node_constraint_flow_coefficient;
table data IN 'CSV' 'input/p_process_constraint_capacity_coefficient.csv' : [process, constraint], p_process_constraint_capacity_coefficient;
table data IN 'CSV' 'input/p_node_constraint_capacity_coefficient.csv' : [node, constraint], p_node_constraint_capacity_coefficient;
table data IN 'CSV' 'input/p_node_constraint_state_coefficient.csv' : [node, constraint], p_node_constraint_state_coefficient;
table data IN 'CSV' 'input/p_process__reserve__upDown__node.csv' : [process, reserve, upDown, node, reserveParam], p_process_reserve_upDown_node;
table data IN 'CSV' 'input/p_process_sink.csv' : [process, sink, sourceSinkParam], p_process_sink;
table data IN 'CSV' 'input/pt_process_sink.csv' : [process, sink, sourceSinkTimeParam, time], pt_process_sink;
table data IN 'CSV' 'input/p_process_sink_coefficient.csv' : [process, sink], p_process_sink_coefficient;
table data IN 'CSV' 'input/p_process_source.csv' : [process, source, sourceSinkParam], p_process_source;
table data IN 'CSV' 'input/p_process_source_coefficient.csv' : [process, source], p_process_source_coefficient;
table data IN 'CSV' 'input/pt_process_source.csv' : [process, source, sourceSinkTimeParam, time], pt_process_source;
table data IN 'CSV' 'input/p_constraint_constant.csv' : [constraint], p_constraint_constant;
table data IN 'CSV' 'input/p_process.csv' : [process, processParam], p_process;
table data IN 'CSV' 'input/pd_process.csv' : [process, processParam, period], pd_process;
table data IN 'CSV' 'input/pt_process.csv' : [process, processParam, time], pt_process;
table data IN 'CSV' 'input/pt_profile.csv' : [profile, time], pt_profile;
table data IN 'CSV' 'input/p_reserve__upDown__group.csv' : [reserve, upDown, group, reserveParam], p_reserve_upDown_group;
table data IN 'CSV' 'input/pt_reserve__upDown__group.csv' : [reserve, upDown, group, reserveParam, time], pt_reserve_upDown_group;
table data IN 'CSV' 'input/timeline_duration_in_years.csv' : [timeline], p_timeline_duration_in_years;
table data IN 'CSV' 'solve_data/p_discount_years.csv' : [period], p_discount_years;
table data IN 'CSV' 'input/p_discount_rate.csv' : model <- [model];
table data IN 'CSV' 'input/p_discount_rate.csv' : [model], p_discount_rate;
# Parameters from the solve loop
table data IN 'CSV' 'solve_data/steps_in_use.csv' : dt <- [period, step];
table data IN 'CSV' 'solve_data/steps_in_use.csv' : [period, step], step_duration;
table data IN 'CSV' 'solve_data/steps_in_timeline.csv' : period_time <- [period,step];
table data IN 'CSV' 'solve_data/first_timesteps.csv' : period__time_first <- [period,step];
table data IN 'CSV' 'solve_data/last_timesteps.csv' : period__time_last <- [period,step];
table data IN 'CSV' 'solve_data/step_previous.csv' : dtttdt <- [period, time, previous, previous_within_block, previous_period, previous_within_solve];
table data IN 'CSV' 'solve_data/step_previous.csv' : [period, time], dt_jump~jump;
table data IN 'CSV' 'solve_data/realized_periods_of_current_solve.csv' : period_realized <- [period];
table data IN 'CSV' 'solve_data/invest_periods_of_current_solve.csv' : period_invest <- [period];
table data IN 'CSV' 'input/p_model.csv' : [modelParam], p_model;
# After rolling forward the investment model
table data IN 'CSV' 'solve_data/p_entity_invested.csv' : [entity], p_entity_invested;
table data IN 'CSV' 'solve_data/p_entity_divested.csv' : [entity], p_entity_divested;
# Reading results from previous solves
table data IN 'CSV' 'output/costs_discounted.csv' : [param_costs], costs_discounted;
set process__fork_method_yes dimen 2 within {process, fork_method} :=
{p in process, m in fork_method
: (sum{(p, source) in process_source} 1 > 1 || sum{(p, sink) in process_sink} 1 > 1) && m in fork_method_yes};
set process__fork_method_no dimen 2 within {process, fork_method} :=
{p in process, m in fork_method
: (sum{(p, source) in process_source} 1 < 2 && sum{(p, sink) in process_sink} 1 < 2) && m in fork_method_no};
set process__fork_method := process__fork_method_yes union process__fork_method_no;
set process_ct_startup_fork_method :=
{ p in process, m1 in ct_method, m2 in startup_method, m3 in fork_method, m in method
: (m1, m2, m3, m) in methods
&& (p, m1) in process__ct_method
&& (p, m2) in process__startup_method
&& (p, m3) in process__fork_method
};
set process_method := setof {(p, m1, m2, m3, m) in process_ct_startup_fork_method} (p, m);
set process__profileProcess__toSink__profile__profile_method :=
{ p in process, (p2, sink, f, fm) in process__node__profile__profile_method
: p = p2
&& (p, sink) in process_sink
&& (sum{(p, m) in process_method : m in method_indirect} 1
|| sum{(p, source) in process_source} 1 < 1)
};
set process__profileProcess__toSink := setof {(p, p2, sink, f, m) in process__profileProcess__toSink__profile__profile_method} (p, p2, sink);
set process__source__toProfileProcess__profile__profile_method :=
{ (p, source) in process_source, (p2, source, f, fm) in process__node__profile__profile_method
: p = p2
&& (sum{(p, m) in process_method : m in method_indirect} 1
|| sum{(p, sink) in process_sink} 1 < 1)
};
set process__source__toProfileProcess := setof {(p, source, p2, f, m) in process__source__toProfileProcess__profile__profile_method} (p, source, p2);
set process_profile := setof {(p, source, p2) in process__source__toProfileProcess} (p) union setof {(p, p2, sink) in process__profileProcess__toSink} (p);
set process_source_toProcess :=
{ (p, source) in process_source, p2 in process
: p = p2
&& (p2, source) in process_source
&& sum{(p, m) in process_method : m in method_indirect} 1
};
set process_process_toSink :=
{ p in process, (p2, sink) in process_sink
: p = p2
&& (p, sink) in process_sink
&& sum{(p, m) in process_method : m in method_indirect} 1
};
set process_sink_toProcess :=
{ sink in node, p in process, p2 in process
: p = p2
&& (p, sink) in process_sink
&& (p2, sink) in process_sink
&& sum{(p, m) in process_method : m in method_2way_nvar} 1
};
set process_process_toSource :=
{ p in process, (p2, source) in process_source
: p = p2
&& (p, source) in process_source
&& sum{(p, m) in process_method : m in method_2way_nvar} 1
};
set process_source_toSink :=
{ (p, source) in process_source, sink in node
: (p, sink) in process_sink
&& sum{(p, m) in process_method : m in method_direct} 1
};
set process_source_toProcess_direct :=
{ (p, source) in process_source, p2 in process
: p = p2
&& sum{(p, m) in process_method : m in method_direct} 1
};
set process_process_toSink_direct :=
{ p in process, p2 in process, sink in node
: p = p2
&& (p, sink) in process_sink
&& sum{(p, m) in process_method : m in method_direct} 1
};
set process_sink_toProcess_direct :=
{ (p, sink) in process_sink, p2 in process
: p = p2
&& (p, sink) in process_sink
&& sum{(p, m) in process_method : m in method_2way_2var} 1
};
set process_process_toSource_direct :=
{ p in process, p2 in process, source in node
: p = p2
&& (p, source) in process_source
&& sum{(p, m) in process_method : m in method_2way_2var} 1
};
set process_sink_toSource :=
{ (p, sink) in process_sink, source in node
: (p, source) in process_source
&& (p, sink) in process_sink
&& sum{(p, m) in process_method : m in method_2way_2var} 1
};
set process__source__sink__profile__profile_method_direct :=
{ (p, source, sink) in process_source_toSink, f in profile, fm in profile_method
: sum{(p, m) in process_method : m in method_direct} 1
&& ( (p, source, f, fm) in process__node__profile__profile_method
|| (p, sink, f, fm) in process__node__profile__profile_method
)
};
set process_process_toSink_noConversion :=
{ p in process, (p2, sink) in process_sink
: p = p2
&& (p, sink) in process_sink
&& sum{(p, m) in process_method : m in method_1way_1var && not sum{(p, source) in process_source} 1} 1
};
set process_source_toProcess_noConversion :=
{ (p, source) in process_source, p2 in process
: p = p2
&& (p2, source) in process_source
&& sum{(p, m) in process_method : m in method_1way_1var && not sum{(p, sink) in process_sink} 1} 1
};
set process_source_sink :=
process_source_toSink union # Direct 1-variable
process_sink_toSource union # Direct 1-variable, but the other way
process_source_toProcess union # First step for indirect (from source to process)
process_process_toSink union # Second step for indirect (from process to sink)
process_sink_toProcess union # Add the 'wrong' direction in 2-way processes with multiple inputs/outputs
process_process_toSource union # Add the 'wrong' direction in 2-way processes with multiple inputs/outputs
process__profileProcess__toSink union # Add profile based inputs to process
process__source__toProfileProcess union # Add profile based inputs to process
process_process_toSink_noConversion union # Add other operational cost only units
process_source_toProcess_noConversion; # Add other operational cost only units
set process_source_sink_alwaysProcess :=
process_source_toProcess_direct union # Direct 1-variable, but showing the process in between
process_process_toSink_direct union
process_sink_toProcess_direct union
process_process_toSource_direct union
process_source_toProcess union # First step for indirect (from source to process)
process_process_toSink union # Second step for indirect (from process to sink)
process_sink_toProcess union # Add the 'wrong' direction in 2-way processes with multiple inputs/outputs
process_process_toSource union # Add the 'wrong' direction in 2-way processes with multiple inputs/outputs
process__profileProcess__toSink union # Add profile based inputs to process
process__source__toProfileProcess union # Add profile based inputs to process
process_process_toSink_noConversion union # Add other operational cost only units
process_source_toProcess_noConversion; # Add other operational cost only units
set process_source_sink_noEff :=
process_source_toProcess union # First step for indirect (from source to process)
process_process_toSink union # Second step for indirect (from process to sink)
process_sink_toProcess union # Add the 'wrong' direction in 2-way processes with multiple inputs/outputs
process_process_toSource union # Add the 'wrong' direction in 2-way processes with multiple inputs/outputs
process__profileProcess__toSink union # Add profile based inputs to process
process__source__toProfileProcess union # Add profile based inputs to process
process_process_toSink_noConversion union # Add other operational cost only units
process_source_toProcess_noConversion; # Add other operational cost only units
set process_source_sink_eff :=
process_source_toSink union # Direct 1-variable
process_sink_toSource; # Direct 1-variable, but the other way
set process__source__sink__profile__profile_method_connection :=
{ (p, sink, source) in process_source_sink, f in profile, m in profile_method
: (p, f, m) in process__profile__profile_method
};
set process__source__sink__profile__profile_method :=
process__profileProcess__toSink__profile__profile_method union
process__source__toProfileProcess__profile__profile_method union
process__source__sink__profile__profile_method_connection union
process__source__sink__profile__profile_method_direct
;
set process__source__sink_isNodeSink := {(p, source, sink) in process_source_sink : (p, sink) in process_sink};
set process_online_linear 'processes with an online status using linear variable' := setof {(p, m) in process_method : m in method_LP} p;
set process_online_integer 'processes with an online status using integer variable' := setof {(p, m) in process_method : m in method_MIP} p;
set process_online := process_online_linear union process_online_integer;
set peedt := {(p, source, sink) in process_source_sink, (d, t) in dt};
param pdCommodity {c in commodity, param in commodityPeriodParam, d in period} :=
+ if (c, param, d) in commodity__param__period
then pd_commodity[c, param, d]
else p_commodity[c, param];
param pdGroup {g in group, param in groupPeriodParam, d in period} :=
+ if (g, param, d) in group__param__period
then pd_group[g, param, d]
else if (g, param) in group__param
then p_group[g, param]
else 0;
set reserve__upDown__group__method_timeseries := {(r, ud, ng, r_m) in reserve__upDown__group__method
: r_m = 'timeseries_only'
|| r_m = 'timeseries_and_dynamic'
|| r_m = 'timeseries_and_large_failure'
|| r_m = 'all'};
set reserve__upDown__group__method_dynamic := {(r, ud, ng, r_m) in reserve__upDown__group__method
: r_m = 'dynamic_only'
|| r_m = 'timeseries_and_dynamic'
|| r_m = 'dynamic_and_large_failure'
|| r_m = 'all'};
set reserve__upDown__group__method_n_1 := {(r, ud, ng, r_m) in reserve__upDown__group__method
: r_m = 'large_failure_only'
|| r_m = 'timeseries_and_large_failure'
|| r_m = 'dynamic_and_large_failure'
|| r_m = 'all'};
set process__method_indirect := {(p, m) in process_method : m in method_indirect};
set process__source__sink_isNodeSink_no2way := {(p, source, sink) in process_source_sink : (p, sink) in process_sink
&& sum{(p,m) in process_method : m not in method_2way_1var} 1};
set process__source__sink_isNodeSink_yes2way := {(p, source, sink) in process_source_sink : (p, sink) in process_sink
&& sum{(p,m) in process_method : m in method_2way_1var} 1};
set process_isNodeSink_yes2way := setof {(p, source, sink) in process__source__sink_isNodeSink_yes2way} p;
set process__source__sink_isNodeSink_2way_2var := {(p, source, sink) in process_source_sink : (p, sink) in process_sink
&& sum{(p,m) in process_method : m in method_2way_2var } 1};
set gdt_maxInstantFlow := {g in group, (d, t) in dt : pdGroup[g, 'max_instant_flow', d]};
set gdt_minInstantFlow := {g in group, (d, t) in dt : pdGroup[g, 'min_instant_flow', d]};
param pdNode {n in node, param in nodePeriodParam, d in period} :=
+ if (n, param, d) in node__param__period
then pd_node[n, param, d]
else p_node[n, param];
param ptNode {n in node, param in nodeTimeParam, t in time_in_use} :=
+ if (n, param, t) in node__param__time
then pt_node[n, param, t]
else p_node[n, param];
set nodeSelfDischarge := {n in nodeState : sum{(d, t) in dt : ptNode[n, 'self_discharge_loss', t]} 1};
set process__source__timeParam :=
{ (p, source) in process_source, param in sourceSinkTimeParam
: (p, source, param) in process__source__param
|| (p, source, param) in process__source__param_t
};
set process__sink__timeParam :=
{ (p, sink) in process_sink, param in sourceSinkTimeParam
: (p, sink, param) in process__sink__param
|| (p, sink, param) in process__sink__param_t
};
set process__timeParam :=
{ p in process, param in sourceSinkTimeParam
: ((p, param) in process__param && p in process_connection)
|| ((p, param) in process__param_t && p in process_connection)
};
set process__source__sink__param :=
{ (p, source, sink) in process_source_sink, param in sourceSinkParam
: (p, source, param) in process__source__param
|| (p, sink, param) in process__sink__param
|| ((p, param) in process__param && p in process_connection)
};
set process__source__sink__param_t :=
{ (p, source, sink) in process_source_sink, param in sourceSinkTimeParam
: (p, source, param) in process__source__param
|| (p, source, param) in process__source__param_t
|| (p, sink, param) in process__sink__param
|| (p, sink, param) in process__sink__param_t
|| ((p, param) in process__param && p in process_connection)
|| ((p, param) in process__param_t && p in process_connection)
};
param setup1 := gmtime() - datetime0;
display setup1;
set process_source_sink_param_t := {(p, source, sink) in process_source_sink_eff, param in processTimeParam : (p, param) in process__param_t};
set process__source__sink__ramp_method :=
{ (p, source, sink) in process_source_sink, m in ramp_method
: (p, source, m) in process_node_ramp_method
|| (p, sink, m) in process_node_ramp_method
};
param pdProcess {p in process, param in processPeriodParam, d in period} :=
+ if (p, param, d) in process__param__period
then pd_process[p, param, d]
else if (p, param) in process__param
then p_process[p, param]
else 0;
param ptProcess {p in process, param in processTimeParam, t in time_in_use} :=
+ if (p, param, t) in process__param__time
then pt_process[p, param, t]
else if (p, param) in process__param
then p_process[p, param]
else 0;
param p_entity_unitsize {e in entity} :=
+ if e in process
then ( if p_process[e, 'virtual_unitsize']
then p_process[e, 'virtual_unitsize']
else if e in process && p_process[e, 'existing']
then p_process[e, 'existing']
else 1000
)
else if e in node
then ( if p_node[e, 'virtual_unitsize']
then p_node[e, 'virtual_unitsize']
else if e in node && p_node[e, 'existing']
then p_node[e, 'existing']
else 1000
);
param pProcess_source_sink {(p, source, sink, param) in process__source__sink__param} :=
+ if (p, source, param) in process__source__param
then p_process_source[p, source, param]
else if (p, sink, param) in process__sink__param
then p_process_sink[p, sink, param]
else 0;
param ptProcess_source {(p, source) in process_source, param in sourceSinkTimeParam, t in time_in_use} := # : sum{d in period : (d, t) in dt} 1
+ if (p, source, param, t) in process__source__param__time
then pt_process_source[p, source, param, t]
else if (p, source, param) in process__source__param
then p_process_source[p, source, param]
else 0;
param ptProcess_sink {(p, sink) in process_sink, param in sourceSinkTimeParam, t in time_in_use} := # : sum{d in period : (d, t) in dt} 1
+ if (p, sink, param, t) in process__sink__param__time
then pt_process_sink[p, sink, param, t]
else if (p, sink, param) in process__sink__param
then p_process_sink[p, sink, param]
else 0;
param ptProcess_source_sink {(p, source, sink, param) in process__source__sink__param_t, t in time_in_use} := # : sum{d in period : (d, t) in dt} 1
+ if (p, sink, param, t) in process__sink__param__time
then pt_process_sink[p, sink, param, t]
else if (p, source, param, t) in process__source__param__time
then pt_process_source[p, source, param, t]
else if (p, param, t) in connection__param__time
then pt_process[p, param, t]
else if (p, source, param) in process__source__param
then p_process_source[p, source, param]
else if (p, sink, param) in process__sink__param
then p_process_sink[p, sink, param]
else if (p, param) in connection__param
then p_process[p, param]
else 0;
param ptReserve_upDown_group {(r, ud, g) in reserve__upDown__group, param in reserveTimeParam, t in time_in_use} :=
+ if (r, ud, g, param, t) in reserve__upDown__group__reserveParam__time
then pt_reserve_upDown_group[r, ud, g, param, t]
else p_reserve_upDown_group[r, ud, g, param];
set process_reserve_upDown_node_active := {(p, r, ud, n) in process_reserve_upDown_node : sum{(r, ud, g) in reserve__upDown__group} 1};
set prundt := {(p, r, ud, n) in process_reserve_upDown_node_active, (d, t) in dt};
set pdt_online_linear := {p in process_online_linear, (d, t) in dt : pdProcess[p, 'startup_cost', d]};
set pdt_online_integer := {p in process_online_integer, (d, t) in dt : pdProcess[p, 'startup_cost', d]};
param hours_in_period{d in period} := sum {(d, t) in dt} (step_duration[d, t]);
param hours_in_solve := sum {(d, t) in dt} (step_duration[d, t]);
param period_share_of_year{d in period} := hours_in_period[d] / 8760;
param solve_share_of_year := hours_in_solve / 8760;
param period_share_of_annual_flow {n in node, d in period : ((n, 'scale_to_annual_flow') in node__inflow_method || (n, 'scale_to_annual_and_peak_flow') in node__inflow_method)
&& pdNode[n, 'annual_flow', d]} := abs(sum{(d, t) in dt} (ptNode[n, 'inflow', t])) / pdNode[n, 'annual_flow', d];
param period_flow_annual_multiplier {n in node, d in period : ((n, 'scale_to_annual_flow') in node__inflow_method)
&& pdNode[n, 'annual_flow', d]} := period_share_of_year[d] / period_share_of_annual_flow[n, d];
param orig_flow_sum {n in node, d in period : ((n, 'scale_to_annual_flow') in node__inflow_method || (n, 'scale_to_annual_and_peak_flow') in node__inflow_method)
&& pdNode[n, 'annual_flow', d]} := sum{t in time_in_use} ptNode[n, 'inflow', t];
param period_flow_proportional_multiplier {n in node, d in period : (n, 'scale_in_proportion') in node__inflow_method && pdNode[n, 'annual_flow', d]} :=
pdNode[n, 'annual_flow', d] / (abs(sum{t in time} (ptNode[n, 'inflow', t])) / sum{(d, tl) in period__timeline} p_timeline_duration_in_years[tl]);
param new_peak_sign{n in node, d in period : (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d]} :=
(if pdNode[n, 'peak_inflow', d] >= 0 then 1 else -1);
param old_peak_max{n in node, d in period : (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d]} :=
if (n, 'inflow') in node__param_t
then max{t in time} pt_node[n, 'inflow', t]
else p_node[n, 'inflow'];
param old_peak_min{n in node, d in period : (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d]} :=
if (n, 'inflow') in node__param_t
then min{t in time} pt_node[n, 'inflow', t]
else p_node[n, 'inflow'];
param old_peak_sign{n in node, d in period : (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d]} :=
( if (n, 'inflow') in node__param_t
then (if abs(old_peak_max[n, d]) >= abs(old_peak_min[n, d]) then 1 else -1)
else (if p_node[n, 'inflow'] >= 0 then 1 else -1)
);
param old_peak{n in node, d in period : (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d]} :=
(if old_peak_sign[n, d] >= 0 then old_peak_max[n, d] else old_peak_min[n, d]);
printf ('Checking if the sign of new peak inflow is the same as the sign ');
printf ('of the peak inflow in the original inflow time series\n');
check {n in node, d in period : (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d]} new_peak_sign[n, d] = old_peak_sign[n, d];
param new_peak_divided_by_old_peak {n in node, d in period : (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d]} :=
pdNode[n, 'peak_inflow', d] / old_peak[n, d];
param new_peak_divide_by_old_peak_sum_inflow {n in node, d in period : (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d]} :=
new_peak_divided_by_old_peak[n, d] * orig_flow_sum[n, d] / period_share_of_year[d];
param new_peak_inflow_sum {n in node, d in period : (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d]} :=
pdNode[n, 'peak_inflow', d] * 8760;
param new_old_multiplier {n in node, d in period : (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d]} :=
old_peak_sign[n, d] *
( old_peak_sign[n, d] * new_peak_divide_by_old_peak_sum_inflow[n, d] - pdNode[n, 'annual_flow', d]
)
/ ( new_peak_inflow_sum[n, d] - new_peak_divide_by_old_peak_sum_inflow[n, d] );
param new_old_slope {n in node, d in period : (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d]} :=
new_peak_divided_by_old_peak[n, d] * ( 1 + new_old_multiplier[n, d] );
param new_old_section {n in node, d in period : (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d]} :=
pdNode[n, 'peak_inflow', d] * new_old_multiplier[n, d];
param pdtNodeInflow {n in node, (d, t) in dt : (n, 'no_inflow') not in node__inflow_method} :=
( if (n, 'scale_to_annual_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] then
+ period_flow_annual_multiplier[n, d] * ptNode[n, 'inflow', t]
else if (n, 'scale_in_proportion') in node__inflow_method && pdNode[n, 'annual_flow', d] then
+ period_flow_proportional_multiplier[n, d] * ptNode[n, 'inflow', t]
else if (n, 'scale_to_annual_and_peak_flow') in node__inflow_method && pdNode[n, 'annual_flow', d] && pdNode[n, 'peak_inflow', d] then
+ new_old_slope[n, d] * ptNode[n, 'inflow', t]
- new_old_section[n, d]
else ptNode[n, 'inflow', t]
);
param pdtNodeInflow_for_scaling{n in node, (d, t) in dt} := (if (n, 'no_inflow') not in node__inflow_method then abs(pdtNodeInflow[n, d, t]) else 1);
param pgdNodeInflow_for_scaling{g in group, d in period} := sum{(g, n) in group_node} max{t in time_in_use} pdtNodeInflow_for_scaling[n, d, t];
set period__period_next := {d in period, dNext in period : 1 + sum{d2 in period : d2 <=d} 1 = sum{dNext2 in period : dNext2 <=dNext} 1};
param p_disc_rate := (if sum{m in model} 1 then max{m in model} p_discount_rate[m] else 0.05);
param p_disc_offset_investment := (if sum{m in model} 1 then max{m in model} p_discount_offset_investment[m] else 1);
param p_disc_offset_operations := (if sum{m in model} 1 then max{m in model} p_discount_offset_operations[m] else 0.5);
param p_discount_factor_investment{d in period} := 1/(1 + p_disc_rate) ^ (p_discount_years[d] + p_disc_offset_investment);
param p_discount_factor_operations{d in period} := 1/(1 + p_disc_rate) ^ (p_discount_years[d] + p_disc_offset_operations);
param p_discount_in_perpetuity_investment{d in period} := (if p_disc_rate then (1/(1+p_disc_rate)^(p_discount_years[d]+p_disc_offset_investment))/p_disc_rate else 1);
param p_discount_in_perpetuity_operations{d in period} := (if p_disc_rate then (1/(1+p_disc_rate)^(p_discount_years[d]+p_disc_offset_operations))/p_disc_rate else 1);
param p_discount_with_perpetuity_operations{d in period} :=
( if d not in period_last
then sum{(d, dNext) in period__period_next}
( + p_discount_in_perpetuity_operations[d]
- p_discount_in_perpetuity_operations[dNext])
else p_discount_in_perpetuity_operations[d]);
param ed_entity_annual{e in entityInvest, d in period_invest} :=
+ sum{m in invest_method : (e, m) in entity__invest_method && e in node && m not in invest_method_not_allowed}
( + (pdNode[e, 'invest_cost', d] * 1000 * ( pdNode[e, 'interest_rate', d]
/ (1 - (1 / (1 + pdNode[e, 'interest_rate', d])^pdNode[e, 'lifetime', d] ) ) ))
+ pdNode[e, 'fixed_cost', d] * 1000
)
+ sum{m in invest_method : (e, m) in entity__invest_method && e in process && m not in invest_method_not_allowed}
(
+ (pdProcess[e, 'invest_cost', d] * 1000 * ( pdProcess[e, 'interest_rate', d]
/ (1 - (1 / (1 + pdProcess[e, 'interest_rate', d])^pdProcess[e, 'lifetime', d] ) ) ))
+ pdProcess[e, 'fixed_cost', d] * 1000
)
;
param ed_entity_annual_divest{e in entityDivest, d in period_invest} :=
+ sum{m in invest_method : (e, m) in entity__invest_method && e in node && m not in divest_method_not_allowed}
( + (pdNode[e, 'salvage_value', d] * 1000 * ( pdNode[e, 'interest_rate', d]
/ (1 - (1 / (1 + pdNode[e, 'interest_rate', d])^pdNode[e, 'lifetime', d] ) ) ))
+ pdNode[e, 'fixed_cost', d] * 1000
)
+ sum{m in invest_method : (e, m) in entity__invest_method && e in process && m not in divest_method_not_allowed}
(
+ (pdProcess[e, 'salvage_value', d] * 1000 * ( pdProcess[e, 'interest_rate', d]
/ (1 - (1 / (1 + pdProcess[e, 'interest_rate', d])^pdProcess[e, 'lifetime', d] ) ) ))
+ pdProcess[e, 'fixed_cost', d] * 1000
)
;
set process_minload := {p in process : (p, 'min_load_efficiency') in process__ct_method};
param ptProcess_section{p in process_minload, t in time_in_use} :=
+ 1 / ptProcess[p, 'efficiency', t]
- ( 1 / ptProcess[p, 'efficiency', t] - ptProcess[p, 'min_load', t] / ptProcess[p, 'efficiency_at_min_load', t] )
/ (1 - ptProcess[p, 'min_load', t])
;
param ptProcess_slope{p in process, t in time_in_use} :=
1 / ptProcess[p, 'efficiency', t]
- (if p in process_minload then ptProcess_section[p, t] else 0);
# * (if (p, 'min_load_efficiency') in process__ct_method then ptProcess_slope[p, t] else 1 / ptProcess[p, 'efficiency', t])
# * (if p in process_unit then p_process_sink_coefficient[p, sink] / p_process_source_coefficient[p, n] else 1)
param w_calc_slope := gmtime() - datetime0 - setup1;
display w_calc_slope;
param ptProcess__source__sink__dt_varCost {(p, source, sink) in process_source_sink, (d, t) in dt} :=
+ (if (p, source) in process_source then ptProcess_source[p, source, 'other_operational_cost', t])
+ (if (p, sink) in process_sink then ptProcess_sink[p, sink, 'other_operational_cost', t])
+ (if (p, source, sink) in process_source_sink then
( ( if (p, 'other_operational_cost', t) in process__param__time then ptProcess[p, 'other_operational_cost', t]
else (if (p, 'other_operational_cost', d) in process__param__period then pdProcess[p, 'other_operational_cost', d]))
)
)
;
param ptProcess__source__sink__dt_varCost_alwaysProcess {(p, source, sink) in process_source_sink_alwaysProcess, (d, t) in dt} :=
+ (if (p, source) in process_source then ptProcess_source[p, source, 'other_operational_cost', t])
+ (if (p, sink) in process_sink then ptProcess_sink[p, sink, 'other_operational_cost', t])
+ (if (p, source, sink) in process_source_sink_alwaysProcess
&& ((p, sink) in process_sink || (p, sink) in process_source)
then ( if (p, 'other_operational_cost', t) in process__param__time then ptProcess[p, 'other_operational_cost', t]
else (if (p, 'other_operational_cost', d) in process__param__period then pdProcess[p, 'other_operational_cost', d]))
)
;
set pssdt_varCost_noEff := {(p, source, sink) in process_source_sink_noEff, (d, t) in dt : ptProcess__source__sink__dt_varCost[p, source, sink, d, t]};
set pssdt_varCost_eff := {(p, source, sink) in process_source_sink_eff, (d, t) in dt : (p, source) in process_source && ptProcess_source[p, source, 'other_operational_cost', t]}
union {(p, source, sink) in process_source_sink_eff, (d, t) in dt : (p, sink) in process_sink && ptProcess_sink[p, sink, 'other_operational_cost', t]};
set ed_invest := {e in entityInvest, d in period_invest : ed_entity_annual[e, d] || sum{(e, c) in process_capacity_constraint} 1 || sum{(e, c) in node_capacity_constraint} 1 };
set ed_invest_period := {(e, d) in ed_invest : (e, 'invest_period') in entity__invest_method || (e, 'invest_period_total') in entity__invest_method
|| (e, 'invest_retire_period') in entity__invest_method || (e, 'invest_retire_period_total') in entity__invest_method};
set e_invest_total := {e in entityInvest : (e, 'invest_total') in entity__invest_method || (e, 'invest_period_total') in entity__invest_method
|| (e, 'invest_retire_total') in entity__invest_method || (e, 'invest_retire_period_total') in entity__invest_method};
set pd_invest := {(p, d) in ed_invest : p in process};
set nd_invest := {(n, d) in ed_invest : n in node};
set ed_divest := {e in entityDivest, d in period_invest : ed_entity_annual_divest[e, d] || sum{(e, c) in process_capacity_constraint} 1 || sum{(e, c) in node_capacity_constraint} 1 };
set ed_divest_period := {(e, d) in ed_invest : (e, 'retire_period') in entity__invest_method || (e, 'retire_period_total') in entity__invest_method
|| (e, 'invest_retire_period') in entity__invest_method || (e, 'invest_retire_period_total') in entity__invest_method};
set e_divest_total := {e in entityDivest : (e, 'retire_total') in entity__invest_method || (e, 'retire_period_total') in entity__invest_method
|| (e, 'invest_retire_total') in entity__invest_method || (e, 'invest_retire_period_total') in entity__invest_method};
set pd_divest := {(p, d) in ed_divest : p in process};
set nd_divest := {(n, d) in ed_divest : n in node};
set gd_invest := {g in group_invest, d in period_invest : sum{(g, e) in group_entity : (e, d) in ed_invest} 1};
set gd_invest_period := {(g, d) in gd_invest : (g, 'invest_period') in group__invest_method || (g, 'invest_period_total') in group__invest_method
|| (g, 'invest_retire_period') in group__invest_method || (g, 'invest_retire_period_total') in group__invest_method};
set g_invest_total := {g in group_invest : (g, 'invest_total') in group__invest_method || (g, 'invest_period_total') in group__invest_method
|| (g, 'invest_retire_total') in group__invest_method || (g, 'invest_retire_period_total') in group__invest_method};
set gd_divest := {g in group_invest, d in period_invest : sum{(g, e) in group_entity : (e, d) in ed_invest} 1};
set gd_divest_period := {(g, d) in gd_invest : (g, 'retire_period') in group__invest_method || (g, 'retire_period_total') in group__invest_method
|| (g, 'invest_retire_period') in group__invest_method || (g, 'invest_retire_period_total') in group__invest_method};
set g_divest_total := {g in group_divest : (g, 'retire_total') in group__invest_method || (g, 'retire_period_total') in group__invest_method
|| (g, 'invest_retire_total') in group__invest_method || (g, 'invest_retire_period_total') in group__invest_method};
param e_invest_max_total{e in entityInvest} :=
+ (if e in process then p_process[e, 'invest_max_total'])
+ (if e in node then p_node[e, 'invest_max_total'])
;
param e_divest_max_total{e in entityDivest} :=
+ (if e in process then p_process[e, 'retire_max_total'])
+ (if e in node then p_node[e, 'retire_max_total'])
;
param e_invest_min_total{e in entityInvest} :=
+ (if e in process then p_process[e, 'invest_min_total'])
+ (if e in node then p_node[e, 'invest_min_total'])
;
param e_divest_min_total{e in entityDivest} :=
+ (if e in process then p_process[e, 'retire_min_total'])
+ (if e in node then p_node[e, 'retire_min_total'])
;
param ed_invest_max_period{(e, d) in ed_invest} :=
+ (if e in process then pdProcess[e, 'invest_max_period', d])
+ (if e in node then pdNode[e, 'invest_max_period', d])
;
param ed_divest_max_period{(e, d) in ed_divest} :=
+ (if e in process then pdProcess[e, 'retire_max_period', d])
+ (if e in node then pdNode[e, 'retire_max_period', d])
;
param ed_invest_min_period{(e, d) in ed_invest} :=
+ (if e in process then pdProcess[e, 'invest_min_period', d])
+ (if e in node then pdNode[e, 'invest_min_period', d])
;
param ed_divest_min_period{(e, d) in ed_divest} :=
+ (if e in process then pdProcess[e, 'retire_min_period', d])
+ (if e in node then pdNode[e, 'retire_min_period', d])
;
set process_source_sink_ramp_limit_source_up :=
{(p, source, sink) in process_source_sink
: ( sum{(p, source, m) in process_node_ramp_method : m in ramp_limit_method} 1
&& p_process_source[p, source, 'ramp_speed_up'] > 0
)
};
set process_source_sink_ramp_limit_sink_up :=
{(p, source, sink) in process_source_sink
: ( sum{(p, sink, m) in process_node_ramp_method : m in ramp_limit_method} 1
&& p_process_sink[p, sink, 'ramp_speed_up'] > 0
)
};
set process_source_sink_ramp_limit_source_down :=
{(p, source, sink) in process_source_sink
: ( sum{(p, source, m) in process_node_ramp_method : m in ramp_limit_method} 1
&& p_process_source[p, source, 'ramp_speed_down'] > 0
)
};
set process_source_sink_ramp_limit_sink_down :=
{(p, source, sink) in process_source_sink
: ( sum{(p, sink, m) in process_node_ramp_method : m in ramp_limit_method} 1
&& p_process_sink[p, sink, 'ramp_speed_down'] > 0
)
};
set process_source_sink_ramp_cost :=
{(p, source, sink) in process_source_sink
: sum{(p, source, m) in process_node_ramp_method : m in ramp_cost_method} 1
|| sum{(p, sink, m) in process_node_ramp_method : m in ramp_cost_method} 1
};
set process_source_sink_ramp :=
process_source_sink_ramp_limit_source_up
union process_source_sink_ramp_limit_sink_up
union process_source_sink_ramp_limit_source_down
union process_source_sink_ramp_limit_sink_down
union process_source_sink_ramp_cost;
set process_source_sink_dtttdt_ramp_limit_source_up :=
{(p, source, sink) in process_source_sink_ramp_limit_source_up, (d, t, t_previous, t_previous_within_block, d_previous, t_previous_within_solve) in dtttdt :
p_process_source[p, source, 'ramp_speed_up'] * 60 < step_duration[d, t] && dt_jump[d, t] == 1
};
set process_source_sink_dtttdt_ramp_limit_sink_up :=
{(p, source, sink) in process_source_sink_ramp_limit_sink_up, (d, t, t_previous, t_previous_within_block, d_previous, t_previous_within_solve) in dtttdt :
p_process_sink[p, sink, 'ramp_speed_up'] * 60 < step_duration[d, t] && dt_jump[d, t] == 1