Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPartition_Univariate.py
More file actions
2153 lines (2047 loc) · 99.2 KB
/
Copy pathPartition_Univariate.py
File metadata and controls
2153 lines (2047 loc) · 99.2 KB
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
"""
Written by Alex Zolan
Univariate Paritioning Model (U)
This module contains a collection of methods used to build and solve instances
of a Remote Microgrid Optimization Model, which we refer to as Model (U) in the
paper. This model uses McCormick sub-envelopes using a univariate partitioning
scheme to approximate bilinear terms for the product of a battery's current and
its state of charge.
Note that we use a separate module, InputReader, for the
purpose of reading inputs.
"""
#import DieselGenerator, PVArray, Battery
import multiprocessing
import scipy
import InputReader
import cplex
import time
#update working directory to current directory.
import os
#setting one global variable
local = True
def FractionOfSolar(tech,start_period,end_period):
return scipy.sum([tech.CalculatePowerAvailable(t)
for t in range(start_period-1,end_period)]) / scipy.sum([
tech.CalculatePowerAvailable(t)
for t in range(len(tech.GetPVAvailability())) ])
def FractionOfDemand(loads,start_period,end_period):
return sum(loads[start_period-1:end_period]) / sum(loads)
def SolvePartition(inputs, scenario, start_period, end_period,
inv_mult=0.0, upper_bound = False, mipgap=0.05,
reslim=3600, test=False, design_mults = [0,0],
IFS = None, batPartsMinus = [0.0,0.25,0.5,0.75,1.0],
batPartsPlus = [0.0,0.25,0.5,0.75,1.0], boundary_soc = 0.5,
output=False, amortize_on_demand = True, min_PV=0, procs=1, mincap=0):
"""creates a full partition of the model.
start_period -- starting period for the model
end_period -- ending period for the model
inv_mult -- price of SOC constraint violation (start = end = reset point)
upper_bound -- indicator of whether the upper bound or lower
bound is to be solved
rhsmin -- input from the scenario - this is not yet in
InputReader
batParts -- fraction of max current over which the McCormick underestimators
for current operate. Default values are evenly spaced on the [0,1]
interval but our input comes from the linear model solution and is the
25th,50th, and 75th percentiles of current (as well as the min and max
allowable).
retval -- cplex solution and objective value
"""
numBatParts = len(batPartsPlus)-1
technologies = inputs["technologies"]
generators = [tech for tech in technologies if tech.GetType() == "DieselGenerator"]
batteries = [tech for tech in technologies if tech.GetType() == "Battery"]
pv_arrays = [tech for tech in technologies if tech.GetType() == "PVArray"]
tech_maxes = inputs["tech_maxes"][scenario]
scalars = inputs["scalars"]
loads = scipy.array(inputs["loads"][scenario][
start_period-1:end_period])
pvs = inputs["pv_avail"][scenario]
fuel_costs = scipy.array(inputs["fuel_costs"][scenario])
tech_maxes = inputs["tech_maxes"][scenario]
mingens = inputs["cuts"][scenario]['rhsmin']
num_periods = end_period+1-start_period
prob = 1.0*num_periods/8760
for tech in technologies:
if tech.GetType() != "PVArray":
tech.SetTechMax(tech_maxes[tech.GetName()])
else:
tech.SetPVAvailability(pvs[tech.GetName()])
tech.ConvertPVAvailability(len(inputs["loads"][scenario]))
W_init = inputs["W_init"]
X_init = inputs["X_init"]
#print technologies[0].GetType()
#print tech_maxes
#initialize problem and suppress console output
p = cplex.Cplex()
p.set_error_stream(None)
p.set_warning_stream(None)
if not output:
p.set_log_stream(None)
p.set_results_stream(None)
else:
p.set_log_stream(scenario+"-"+str(start_period)+"_log.txt")
if upper_bound:
resfilename = scenario+"-"+str(start_period)+"_UB.txt"
else:
resfilename = scenario+"-"+str(start_period)+"_LB.txt"
p.set_results_stream(resfilename)
p.parameters.timelimit.set(reslim)
p.parameters.workmem.set(50)
p.parameters.mip.tolerances.mipgap.set(mipgap)
p.parameters.threads.set(procs)
p.parameters.lpmethod.set(4)
p.parameters.mip.strategy.rinsheur.set(10)
p.parameters.mip.strategy.heuristicfreq.set(100)
p.parameters.mip.strategy.file.set(2)
#p.parameters.simplex.tolerances.feasibility.set(0.0001)
p.parameters.emphasis.mip.set(2)
p.parameters.mip.strategy.branch.set(1)
def flatten(l):
out = []
for item in l:
if isinstance(item, (list, tuple)):
out.extend(flatten(item))
else:
out.append(item)
return out
def getName(name, *args):
return '%s_%s'%(name, args)
#define decision variable names
def W_var(tech,k): return "W_"+tech.GetName()+".K"+str(k)
def X_var(pv): return "X_"+pv.GetName()
def P_minus_var(tech,k,t): return "P_minus_" + tech.GetName()+".K" + str(k) + ".TT" + str(t)
def P_plus_var(tech,k,t): return "P_plus_" + tech.GetName()+".K" + str(k) + ".TT" + str(t)
def P_PV_var(pv,t): return "P_PV_"+pv.GetName()+".TT"+str(t)
def F_tilde_var(t): return "F_tilde_TT"+str(t)
def soc_start_var(bat,k): return "soc_start_"+bat.GetName() + ".K" + str(k)
def B_soc_var(bat,k,t):
if t == start_period-1:
return soc_start_var(bat,k)
return "B_soc_" + bat.GetName() + ".K" + str(k) + ".TT" + str(t)
def soc_end_var(bat,k): return B_soc_var(bat,k,end_period)
def I_minus_var(bat,k,t): return "I_minus_" + bat.GetName() + ".K" + str(k) + ".TT" + str(t)
def I_plus_var(bat,k,t): return "I_plus_" + bat.GetName() + ".K" + str(k) + ".TT" + str(t)
def V_soc_var(bat,k,t): return "V_soc_" + bat.GetName() + ".K" + str(k) + ".TT" + str(t)
def Z_minus_var(bat,k,t): return "Z_minus_" + bat.GetName() + ".K" + str(k) + ".TT" + str(t)
def Z_plus_var(bat,k,t): return "Z_plus_" + bat.GetName() + ".K" + str(k) + ".TT" + str(t)
def B_minus_var(bat,k,t): return "B_minus_" + bat.GetName() + ".K" + str(k) + ".TT" + str(t)
def B_plus_var(bat,k,t): return "B_plus_" + bat.GetName() + ".K" + str(k) + ".TT" + str(t)
def G_var(gen,k,t): return "G_" + gen.GetName()+".K" + str(k) + ".TT" + str(t)
def lambda_minus_var(bat,k,n,t): return "lambda_minus_"+bat.GetName() + ".K" + str(k) + ".N"+ str(n) + ".TT" + str(t)
def lambda_plus_var(bat,k,n,t): return "lambda_plus_"+bat.GetName() + ".K" + str(k) + ".N"+ str(n) + ".TT" + str(t)
W_names = flatten([["W_" + tech.GetName() + ".K" + str(i+1)
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() != "PVArray"])
X_names = ["X_" + tech.GetName() for tech in technologies
if tech.GetType() == "PVArray"]
P_minus_names = [[["P_minus_" + tech.GetName()+".K" + str(i+1)
+ ".TT" + str(t) for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() != "PVArray"]
for t in range(start_period, end_period+1)]
P_minus_names_gen = [[["P_minus_" + tech.GetName()+".K" + str(i+1)
+ ".TT" + str(t) for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "DieselGenerator"]
for t in range(start_period, end_period+1)]
P_plus_names = [[["P_plus_" + tech.GetName() + ".K" + str(i+1)
+ ".TT" + str(t) for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]
for t in range(start_period, end_period+1)]
P_PV_names = [["P_PV_"+tech.GetName()+".TT"+str(t)
for tech in technologies
if tech.GetType() == "PVArray"]
for t in range(start_period, end_period+1)]
F_tilde_names = ["F_tilde_TT"+str(t) for t in range(
start_period, end_period+1)]
B_soc_names = [[["B_soc_" + tech.GetName() + ".K" + str(i+1)
+ ".TT" + str(t) for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]
for t in range(start_period, end_period+1)]
I_minus_names = [[["I_minus_" + tech.GetName() + ".K" + str(i+1)
+ ".TT" + str(t) for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]
for t in range(start_period, end_period+1)]
I_plus_names = [[["I_plus_" + tech.GetName() + ".K" + str(i+1)
+ ".TT" + str(t) for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]
for t in range(start_period, end_period+1)]
Z_minus_names = [[["Z_minus_" + tech.GetName() + ".K" + str(i+1)
+ ".TT" + str(t) for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]
for t in range(start_period, end_period+1)]
Z_plus_names = [[["Z_plus_" + tech.GetName() + ".K" + str(i+1)
+ ".TT" + str(t) for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]
for t in range(start_period, end_period+1)]
B_minus_names = [[["B_minus_" + tech.GetName() + ".K" + str(i+1)
+ ".TT" + str(t) for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]
for t in range(start_period, end_period+1)]
B_plus_names = [[["B_plus_" + tech.GetName() + ".K" + str(i+1)
+ ".TT" + str(t) for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]
for t in range(start_period, end_period+1)]
G_names = [[["G_" + tech.GetName() + ".K" + str(i+1)
+ ".TT" + str(t) for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "DieselGenerator"]
for t in range(start_period, end_period+1)]
lambda_plus_names = [[[["lambda_plus_" + tech.GetName() + ".K" + str(i+1)
+ ".N" + str(n+1) + ".TT" + str(t)
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies if tech.GetType() == "Battery"]
for n in range(numBatParts)]
for t in range(start_period, end_period+1)]
lambda_minus_names = [[[["lambda_minus_" + tech.GetName() + ".K" + str(i+1)
+ ".N" + str(n+1) + ".TT" + str(t)
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies if tech.GetType() == "Battery"]
for n in range(numBatParts)]
for t in range(start_period, end_period+1)]
soc_start_names = [[soc_start_var(tech,(i+1))
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]
soc_end_names = [[soc_end_var(tech,(i+1))
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]
Jhat_flat = flatten(P_minus_names)
Bhat_flat = flatten(P_plus_names) #batteries
S_flat = flatten(P_PV_names)
Ghat_flat = flatten(G_names)
lamb_flat = flatten(lambda_plus_names)
soc_start_flat = flatten(soc_start_names)
num_Jhat = len(Jhat_flat)
num_Bhat = len(Bhat_flat)
num_S = len(S_flat)
num_Ghat = len(Ghat_flat)
num_lamb = len(lamb_flat)
num_soc = len(soc_start_flat)
#define parameters that will be used in calculating cost
if amortize_on_demand:
purchase_costs = ( FractionOfDemand(inputs["loads"][scenario],
start_period,end_period) *
scipy.array( flatten( [[tech.GetPurchaseCost()
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() != "PVArray"]) ) ) + design_mults[0]
solar_costs = ( scipy.array([
FractionOfSolar(tech,start_period,end_period) *
tech.GetPurchaseCost()
for tech in technologies
if tech.GetType() == "PVArray"]) ) + design_mults[1]
else:
purchase_costs = prob*scipy.array(flatten([[tech.GetPurchaseCost()
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() != "PVArray"])) + design_mults[0]
solar_costs = prob*scipy.array([tech.GetPurchaseCost()
for tech in technologies
if tech.GetType() == "PVArray"]) + design_mults[1]
lambda_multipliers = scipy.array(flatten([[tech.GetMaxPower()
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]))
max_lambda_mult = lambda_multipliers.max()
lambda_multipliers /= max_lambda_mult
#lifecycle costs for I, Z variables (identical for charge and discharge)
I_costs = [[[float(scalars["tau"])*tech.GetLifeCycleCost()*tech.GetASOC()/(2.*tech.GetReferenceCapacity())
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]
for t in range(start_period, end_period+1)]
Z_costs = [[[float(scalars["tau"])*tech.GetLifeCycleCost()*tech.GetDSOC()/(-2.*tech.GetReferenceCapacity())
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]
for t in range(start_period, end_period+1)]
G_costs = [[[tech.GetLifeCycleCost() for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "DieselGenerator"]
for t in range(start_period, end_period+1)]
#creation of variables
#W_bk -- purchase variables
p.variables.add(obj=purchase_costs,
lb=scipy.zeros_like(purchase_costs),
ub=scipy.ones_like(purchase_costs),
types=[p.variables.type.binary]*len(purchase_costs),
names= flatten(W_names) )
#X_s -- Solar Purchase Costs
p.variables.add(obj=solar_costs,
lb=scipy.zeros_like(solar_costs,dtype=float),
ub=[cplex.infinity]*len(solar_costs),
types=[p.variables.type.continuous]*len(solar_costs),
names= X_names )
#P_minus_jkt -- Power out by variable by time period
p.variables.add(obj=scipy.zeros(num_Jhat,dtype=float),
lb=scipy.zeros(num_Jhat,dtype=float),
ub=[cplex.infinity]*num_Jhat,
types=[p.variables.type.continuous]*num_Jhat,
names=flatten(P_minus_names) )
#P_plus_jkt -- Power out by technology (no solar) by time period
p.variables.add(obj=scipy.zeros(num_Bhat,dtype=float),
lb=scipy.zeros(num_Bhat,dtype=float),
ub=[cplex.infinity]*num_Bhat,
types=[p.variables.type.continuous]*num_Bhat,
names=flatten(P_plus_names) )
#P_PV_st -- Power out by variable by time period
p.variables.add(obj=scipy.zeros_like(S_flat,dtype=float),
lb=scipy.zeros(num_S,dtype=float),
ub=[cplex.infinity]*len(S_flat),
types=[p.variables.type.continuous]*num_S,
names=flatten(P_PV_names) )
#F_tilde_t -- Fuel consumed (gal) by time period
p.variables.add(obj=scipy.array(fuel_costs[start_period-1:end_period]),
lb=scipy.zeros_like(F_tilde_names,dtype=float),
ub=[cplex.infinity]*len(F_tilde_names),
types=[p.variables.type.continuous]*len(F_tilde_names),
names=F_tilde_names )
#B_soc_bkt -- State of charge by battery by time period
p.variables.add(obj=scipy.zeros_like(Bhat_flat,dtype=float),
lb=scipy.zeros(num_Bhat,dtype=float),
ub=scipy.ones(num_Bhat,dtype=float),
types=[p.variables.type.continuous]*num_Bhat,
names=flatten(B_soc_names) )
#I_minus_bkt -- Current out by battery by time period
p.variables.add(obj=scipy.array(flatten(I_costs)),
lb=scipy.zeros(num_Bhat,dtype=float),
ub=[cplex.infinity]*num_Bhat,
types=[p.variables.type.continuous]*num_Bhat,
names=flatten(I_minus_names) )
#I_plus_bkt -- Current in by battery by time period
p.variables.add(obj=scipy.array(flatten(I_costs)),
lb=scipy.zeros(num_Bhat,dtype=float),
ub=[cplex.infinity]*num_Bhat,
types=[p.variables.type.continuous]*num_Bhat,
names=flatten(I_plus_names) )
#Z_minus_bkt -- Current out*State of charge by battery by time period
p.variables.add(obj=scipy.array(flatten(Z_costs)),
lb=scipy.zeros(num_Bhat,dtype=float),
ub=[cplex.infinity]*num_Bhat,
types=[p.variables.type.continuous]*num_Bhat,
names=flatten(Z_minus_names) )
#Z_plus_bkt -- Current in*State of charge by battery by time period
p.variables.add(obj=scipy.array(flatten(Z_costs)),
lb=scipy.zeros(num_Bhat,dtype=float),
ub=[cplex.infinity]*num_Bhat,
types=[p.variables.type.continuous]*num_Bhat,
names=flatten(Z_plus_names) )
#B_minus_bkt -- 1 if battery discharges, 0 o.w. by time period
p.variables.add(obj=scipy.zeros_like(Bhat_flat,dtype=float),
lb=scipy.zeros(num_Bhat,dtype=float),
ub=scipy.ones(num_Bhat,dtype=float),
types=[p.variables.type.binary]*num_Bhat,
names=flatten(B_minus_names) )
#B_plus_bkt -- 1 if battery charges, 0 o.w. by time period
p.variables.add(obj=scipy.zeros_like(Bhat_flat,dtype=float),
lb=scipy.zeros(num_Bhat,dtype=float),
ub=scipy.ones(num_Bhat,dtype=float),
types=[p.variables.type.binary]*num_Bhat,
names=flatten(B_plus_names) )
#G_gkt -- 1 if generator on, 0 o.w. by time period
p.variables.add(obj=scipy.array(flatten(G_costs)),
lb=scipy.zeros(num_Ghat,dtype=float),
ub=scipy.ones(num_Ghat,dtype=float),
types=[p.variables.type.binary]*num_Ghat,
names=flatten(G_names) )
#lambda_plus - 1 if SOC is in given in range and battery is charging, 0 o.w.
p.variables.add(obj=scipy.zeros_like(lamb_flat,dtype=float),
lb=scipy.zeros(num_lamb,dtype=float),
ub=scipy.ones(num_lamb,dtype=float),
types=[p.variables.type.binary]*num_lamb,
names=flatten(lambda_plus_names) )
#lambda_minus - 1 if SOC is in given in range and battery is charging, 0 o.w.
p.variables.add(obj=scipy.zeros_like(lamb_flat,dtype=float),
lb=scipy.zeros(num_lamb,dtype=float),
ub=scipy.ones(num_lamb,dtype=float),
types=[p.variables.type.binary]*num_lamb,
names=flatten(lambda_minus_names) )
#soc_start by scenario
p.variables.add(obj=scipy.zeros(num_soc),
lb=[0.0]*num_soc,
ub=[1.0]*num_soc,
types=[p.variables.type.continuous]*num_soc,
names=flatten(soc_start_names) )
#inventory
p.variables.add(obj=[inv_mult],
lb=[0.0],
ub=[cplex.infinity],
types=[p.variables.type.continuous],
names=['battery_inv'] )
#prioritize branching
orders = []
for gen in generators:
for k in range(tech_maxes[gen.GetName()]):
orders.append((W_var(gen,k+1),1+int(gen.GetName()[1:]),p.order.branch_direction.up))
for bat in batteries:
for k in range(tech_maxes[bat.GetName()]):
orders.append((W_var(bat,k+1),1,p.order.branch_direction.up))
p.order.set(orders)
#minimize cost
p.objective.set_sense( p.objective.sense.minimize )
#constraint 15a - power flow
val = flatten([[tech.GetEfficiencyOut()
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() != "PVArray"])
val.extend( [1.0
for tech in technologies
if tech.GetType() == "PVArray"] )
val.extend(flatten([[ -1.0
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"]))
p.linear_constraints.add(lin_expr=[
cplex.SparsePair(flatten(P_minus_names[t]+
P_PV_names[t]+P_plus_names[t]), val)
for t in range(num_periods)],
senses=['G' for t in range(num_periods)],
rhs=loads,
names=['Sys_Op_15a_'+str(t+start_period)
for t in range(num_periods)])
#constraint 15b - spinning reserve
#eta_out*p_max*Bsoc for all batteries in time t
val = flatten([[ tech.GetEfficiencyOut()*tech.GetMaxPower()*
tech.GetSOC()
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "Battery"])
#p_max*G for all generators in time t
val.extend(flatten([[ tech.GetMaxPower()
for i in range(tech_maxes[tech.GetName()])]
for tech in technologies
if tech.GetType() == "DieselGenerator"]))
#-P_minus for all generators in time t
val.extend(scipy.ones(int(num_Ghat/num_periods)))
#-k_sol*P_solar
val.extend(-1.0*float(scalars["k_sol"])*scipy.ones(int(num_S/num_periods),dtype=float))
p.linear_constraints.add(lin_expr=[
cplex.SparsePair(flatten(B_soc_names[t]+
G_names[t]+P_minus_names_gen[t]+
P_PV_names[t]), val)
for t in range(num_periods)],
senses=['G' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Sys_Op_15b_'+str(t+start_period)
for t in range(num_periods)])
#constraint 15c -- break purchasing symmetry
for tech in technologies:
if tech.GetType() != "PVArray":
for i in range(tech_maxes[tech.GetName()]-1):
ind = ["W_" + tech.GetName() + ".K" + str(i+1),
"W_" + tech.GetName() + ".K" + str(i+2)]
val = [1,-1]
p.linear_constraints.add(lin_expr=[
cplex.SparsePair( ind,val )],
senses = ['G'],
rhs = [0],
names = ['Sys_Op_15c_'+tech.GetName()+
".K"+str(i)])
### Generator Operations
#constraint 16a -- Generator Max Power
for gen in generators:
for k in range(tech_maxes[gen.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([G_var(gen,k+1,t+start_period),
P_minus_var(gen,k+1,(t+start_period))],
[-1*gen.GetMaxPower(),1])
for t in range(num_periods)],
senses=['L' for t in range(num_periods)],
rhs=scipy.zeros(num_periods,dtype=float),
names=['Gen_Op_16a1_'+gen.GetName()+".K"
+str(k+1)+".TT"+str(t+start_period)
for t in range(num_periods)])
#constraint 16a2 -- Generator Min Power
for gen in generators:
for k in range(tech_maxes[gen.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([G_var(gen,k+1,t+start_period),
P_minus_var(gen,k+1,(t+start_period))],
[-1*gen.GetMinPower(),1])
for t in range(num_periods)],
senses=['G' for t in range(num_periods)],
rhs=scipy.zeros(num_periods,dtype=float),
names=['Gen_Op_16a2_'+gen.GetName()+".K"
+str(k+1)+".TT"+str(t+start_period)
for t in range(num_periods)])
#constraint 16b -- Fuel Usage
val = [1]
val.extend(flatten([[gen.GetFuelUseB()/-1000.0 for i in range(tech_maxes[gen.GetName()])]
for gen in generators] ) )
val.extend(flatten([[-1.0*gen.GetFuelUseC() for i in range(tech_maxes[gen.GetName()])]
for gen in generators] ))
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([F_tilde_names[t]]+
flatten(P_minus_names_gen[t]
+ G_names[t] ), val)
for t in range(num_periods)],
senses=['G' for t in range(num_periods)],
rhs=scipy.zeros(num_periods,dtype=float),
names=['Gen_Op_16b_'+str(t+start_period)
for t in range(num_periods)])
#constraint 16c -- Use only generators that are purchased
for gen in generators:
for k in range(tech_maxes[gen.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([
"G_" + gen.GetName()
+ ".K" + str(k+1)
+ ".TT" + str(t+start_period), "W_" +
gen.GetName() + ".K" + str(k+1)],[1,-1])
for t in range(num_periods)],
senses=['L' for t in range(num_periods)],
rhs=scipy.zeros(num_periods,dtype=float),
names=['Gen_Op_16c_'+gen.GetName()+".K"
+str(k+1)+".TT"+str(t+start_period)
for t in range(num_periods)])
#constraint 16d -- Break generator power out symmetry
for gen in generators:
for k in range(tech_maxes[gen.GetName()]-1):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([
"P_minus_" + gen.GetName() + ".K" + str(k+1)
+ ".TT" + str(t+start_period),
"P_minus_" + gen.GetName()
+ ".K" + str(k+2)
+ ".TT" + str(t+start_period)],[1,-1])
for t in range(num_periods)],
senses=['G' for t in range(num_periods)],
rhs=scipy.zeros(num_periods,dtype=float),
names=['Gen_Op_16d_'+gen.GetName()+".K"
+str(k+2)+".TT"+str(t+start_period)
for t in range(num_periods)])
#constraint 16e -- Break generator use symmetry
for gen in generators:
for k in range(tech_maxes[gen.GetName()]-1):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([
"G_" + gen.GetName() + ".K" + str(k+1)
+ ".TT" + str(t+start_period),
"G_" + gen.GetName()
+ ".K" + str(k+2)
+ ".TT" + str(t+start_period)],[1,-1])
for t in range(num_periods)],
senses=['G' for t in range(num_periods)],
rhs=scipy.zeros(num_periods,dtype=float),
names=['Gen_Op_16d_'+gen.GetName()+".K"
+str(k+2)+".TT"+str(t+start_period)
for t in range(num_periods)])
#constraint 17a -- PV out limited by solar power and # purchased
for pv in pv_arrays:
p.linear_constraints.add(lin_expr=[
cplex.SparsePair(["P_PV_"+pv.GetName()
+ ".TT"+str(t+start_period),"X_"+pv.GetName()],
[1.0,
-1.0*pv.CalculatePowerAvailable(t+start_period-1)])
for t in range(num_periods)],
senses=['L' for t in range(num_periods)],
rhs=scipy.zeros(num_periods,dtype=float),
names=['PV_Op_17a_'+pv.GetName()
+ ".TT"+str(t+start_period)
for t in range(num_periods)]
)
#constraint 17b -- upper bound on purchases
for pv in pv_arrays:
p.linear_constraints.add(lin_expr=[
cplex.SparsePair(["X_"+pv.GetName()],
[1.0])],
senses=['L'],
rhs=[75],#[float(scalars["solar_max"])],
names=['PV_Op_17b_'+pv.GetName()]
)
#constraints 18a, 18b use Z in the place of B_soc*I_plus, substituted via
#constraints 23-24, which are not implemented here for efficiency.
#constraint Linear_18a: Linearization of P_plus (Z replaces B_soc*I_plus)
for bat in batteries:
val = [1,
-1.0*bat.GetVoltageA(),
-1.0*bat.GetVoltageB()-(bat.GetAvgCurrent()*
bat.GetResistance())]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(
lin_expr=[cplex.SparsePair([
P_plus_var(bat,k+1,t),
Z_plus_var(bat,k+1,t),
I_plus_var(bat,k+1,t)]
,val) for t in range(start_period,
end_period+1)],
senses=['E' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Linear_18a_'+bat.GetName()+".K"+str(k+1)
+".TT"+str(t) for t in range(start_period,
end_period+1)])
#constraint Linear_18b: Linearization of P_minus (Z replaces B_soc*I_minus)
for bat in batteries:
val = [1,
-1.0*bat.GetVoltageA(),
-1.0*bat.GetVoltageB()+(bat.GetAvgCurrent()*
bat.GetResistance())]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(
lin_expr=[cplex.SparsePair([
P_minus_var(bat,k+1,t),
Z_minus_var(bat,k+1,t),
I_minus_var(bat,k+1,t)]
,val) for t in range(start_period,
end_period+1)],
senses=['E' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Linear_18b_'+bat.GetName()+".K"+str(k+1)
+".TT"+str(t) for t in range(start_period,
end_period+1)])
#constraint 18c -- State of charge tracking
for bat in batteries:
val = [1.0,-1.0,-1.0*(
float(scalars["tau"])*bat.GetEfficiencyIn()
/ bat.GetReferenceCapacity()),
1.0*(float(scalars["tau"]) / bat.GetReferenceCapacity())]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([B_soc_var(bat,k+1,t),
B_soc_var(bat,k+1,t-1),
I_plus_var(bat,k+1,t),
I_minus_var(bat,k+1,t)]
,val) for t in range(start_period,end_period+1)],
senses=['E' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Bat_Op_18c_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
for bat in batteries:
#constraint 18d1 -- SOC maximum (note: includes soc_start)
val = [1,-1.0*float(scalars["soc_max"])]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([B_soc_var(bat,k+1,t),
W_var(bat,k+1)]
,val) for t in range(start_period-1,end_period+1)],
senses=['L' for t in range(num_periods+1)],
rhs=scipy.zeros(num_periods+1),
names=['Bat_Op_18d1_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period-1,end_period+1)])
for bat in batteries:
#constraint 18d2 -- SOC minimum (note: includes soc_start)
val = [1,-1.0*float(scalars["soc_min"])]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([B_soc_var(bat,k+1,t),
W_var(bat,k+1)]
,val) for t in range(start_period-1,end_period+1)],
senses=['G' for t in range(num_periods+1)],
rhs=scipy.zeros(num_periods+1),
names=['Bat_Op_18d2_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period-1,end_period+1)])
for bat in batteries:
#constraint 18e -- SOC equal for all batteries of type b
val = [1.0,-1.0,1.0]
for k in range(tech_maxes[bat.GetName()]-1):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([B_soc_var(bat,k+1,t),
B_soc_var(bat,k+2,t),
W_var(bat,k+1)]
,val) for t in range(start_period,end_period+1)],
senses=['L' for t in range(num_periods+1)],
rhs=1.0*scipy.ones(num_periods),
names=['Bat_Op_18e_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
for bat in batteries:
#constraint 18f -- SOC equal for all batteries of type b
val = [1.0,1.0,-1.0]
for k in range(tech_maxes[bat.GetName()]-1):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([B_soc_var(bat,k+1,t),
B_soc_var(bat,k+2,t),
W_var(bat,k+1)]
,val) for t in range(start_period,end_period+1)],
senses=['G' for t in range(num_periods)],
rhs=-1.0*scipy.ones(num_periods),
names=['Bat_Op_18f_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
#constraint 18g -- tracks starting storage inventory
ind = ['battery_inv'] #R^ell
val = [-1.0]
for bat in batteries:
for k in range(1,tech_maxes[bat.GetName()]+1):
ind.append(soc_start_var(bat,k))
val.append(bat.GetReferenceCapacity())
p.linear_constraints.add(
lin_expr=[cplex.SparsePair(ind,val)],
senses=['E'],
rhs=[0],
names=['INVENTORY_18g'])
#constraint 18h -- tracks ending storage inventory
ind = ['battery_inv']
val = [-1.0]
for bat in batteries:
for k in range(1,tech_maxes[bat.GetName()]+1):
ind.append(soc_end_var(bat,k))
val.append(bat.GetReferenceCapacity())
p.linear_constraints.add(
lin_expr=[cplex.SparsePair(ind,val)],
senses=['E'],
rhs=[0],
names=['INVENTORY_18h'])
for bat in batteries:
#constraint 18i1 -- power out upper limits of battery type b
val = [1.0,-1.0*bat.GetMaxPower()]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([P_plus_var(bat,k+1,t),
B_plus_var(bat,k+1,t)]
,val) for t in range(start_period,end_period+1)],
senses=['L' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Bat_Op_18i1_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
for bat in batteries:
#constraint 18i2 -- power in lower limits of battery type b
val = [1.0,-1.0*bat.GetMinPower()]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([P_plus_var(bat,k+1,t),
B_plus_var(bat,k+1,t)]
,val) for t in range(start_period,end_period+1)],
senses=['G' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Bat_Op_18i2_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
for bat in batteries:
#constraint 18j1 -- power in upper limits of battery type b
val = [1.0,-1.0*bat.GetMaxPower()]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([P_minus_var(bat,k+1,t),
B_minus_var(bat,k+1,t)]
,val) for t in range(start_period,end_period+1)],
senses=['L' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Bat_Op_18j1_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
for bat in batteries:
#constraint 18j2 -- power out lower limits of battery type b
val = [1.0,-1.0*bat.GetMinPower()]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([P_minus_var(bat,k+1,t),
B_minus_var(bat,k+1,t)]
,val) for t in range(start_period,end_period+1)],
senses=['G' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Bat_Op_18j2_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
for bat in batteries:
#constraint 18k1 -- current in upper limits (semicontinuous)
val = [1.0,-1.0*bat.GetIUPlus()]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([I_plus_var(bat,k+1,t),
B_plus_var(bat,k+1,t)]
,val) for t in range(start_period,end_period+1)],
senses=['L' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Bat_Op_18k1_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
for bat in batteries:
#constraint 18k2 -- current in lower limits (semicontinuous)
val = [1.0,-1.0*bat.GetMinCurrent()]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([I_plus_var(bat,k+1,t),
B_plus_var(bat,k+1,t)]
,val) for t in range(start_period,end_period+1)],
senses=['G' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Bat_Op_18k2_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
for bat in batteries:
#constraint 18l1 -- current out upper limits (semicontinuous)
val = [1.0,-1.0*bat.GetIUMinus()]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([I_minus_var(bat,k+1,t),
B_minus_var(bat,k+1,t)]
,val) for t in range(start_period,end_period+1)],
senses=['L' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Bat_Op_18l1_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
for bat in batteries:
#constraint 18l2 -- current out upper limits (semicontinuous)
val = [1.0,-1.0*bat.GetMinCurrent()]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([I_minus_var(bat,k+1,t),
B_minus_var(bat,k+1,t)]
,val) for t in range(start_period,end_period+1)],
senses=['G' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Bat_Op_18l2_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
for bat in batteries:
#constraint 18m -- current out upper limits (bound by SOC)
val = [1.0,-1.0*(bat.GetIUMinus())]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([I_minus_var(bat,k+1,t),
B_soc_var(bat,k+1,t-1)]
,val) for t in range(start_period,end_period+1)],
senses=['L' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Bat_Op_18m_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
for bat in batteries:
#constraint 18n -- Only use batteries that you buy
val = [1,1,-1]
for k in range(tech_maxes[bat.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([B_minus_var(bat,k+1,t),
B_plus_var(bat,k+1,t),
W_var(bat,k+1)],val)
for t in range(start_period,end_period+1)],
senses=['L' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Bat_Op_18n_'+bat.GetName()+".K"+str(k+1) +
".TT"+str(t) for t in range(start_period,end_period+1)])
for bat in batteries:
#constraint 18o -- Can't simultaneously charge and discharge batteries
val=[1,1]
for batp in batteries:
if batp != bat:
for k in range(tech_maxes[bat.GetName()]):
for kp in range(tech_maxes[batp.GetName()]):
p.linear_constraints.add(lin_expr=[
cplex.SparsePair([B_plus_var(bat,k+1,t),
B_minus_var(batp,kp+1,t)],val)
for t in range(
start_period,end_period+1)],
senses=['L' for t in range(num_periods)],
rhs=scipy.ones(num_periods,dtype=float),
names=['Bat_Op_18o_'+bat.GetName()+".K"+str(k+1)
+".BP"+batp.GetName()[-1]+
".KP"+str(kp+1)+".TT"+str(t)
for t in range(start_period,end_period+1)])
#Constraint 19a: Nonanticipativity of W
#Fix purchase decision if running the upper bound model
if upper_bound:
inds = []
vals = []
for tech in technologies:
if tech.GetType() != "PVArray":
for k in range(1,tech_maxes[tech.GetName()]+1):
inds.append(W_var(tech,k))
if tech.GetName() in W_init[scenario].keys():
if "K"+str(k) in W_init[scenario][tech.GetName()].keys():
vals.append(W_init[scenario][tech.GetName()]["K"+str(k)])
else: vals.append(0)
else: vals.append(0)
#print inds, vals
p.variables.set_upper_bounds(zip(inds,vals))
p.variables.set_lower_bounds(zip(inds,vals))
#Constraint 19b: Nonanticipativity of X
#Fix purchase decision if running the upper bound model
if upper_bound:
inds = []
vals = []
for tech in technologies:
if tech.GetType() == "PVArray":
inds.append(X_var(tech))
if tech.GetName() in X_init[scenario].keys():
vals.append(X_init[scenario][tech.GetName()])
else: vals.append(0)
#print inds, vals
p.variables.set_upper_bounds(zip(inds,vals))
p.variables.set_lower_bounds(zip(inds,vals))
#Constraint 19c: Nonanticipativity of R^\ell. This is enforced by
#fixing the starting state of charge for all batteriesin the upper bound.
#model, and is relaxed in the lower bound model.
if upper_bound and start_period != 1:
val = [1.0,-1.0*boundary_soc]
sense = ['E']
for bat in batteries:
for k in range(1,tech_maxes[bat.GetName()]+1):
p.linear_constraints.add(
lin_expr=[cplex.SparsePair([soc_start_var(bat,k),W_var(bat,k)],
val)],
senses=sense,
rhs=[0],
names=['Storage_inv_start_UB_19c1'+bat.GetName()+".K"+str(k)])
if upper_bound and start_period != 1:
val = [1.0,-1.0*boundary_soc]
sense = ['E']
ending = 'UB_'
for bat in batteries:
for k in range(1,tech_maxes[bat.GetName()]+1):
p.linear_constraints.add(
lin_expr=[cplex.SparsePair([soc_end_var(bat,k),W_var(bat,k)],
val)],
senses=sense,
rhs=[0],
names=['Storage_inv_end_UB_19c2'+bat.GetName()+".K"+str(k)])
#Constraint 20: boundary condition for battery state-of-charge
if start_period == 1:
val = [1.0,-1.0*scalars["b_init"]]
sense = ['E']
for bat in batteries:
for k in range(1,tech_maxes[bat.GetName()]+1):
p.linear_constraints.add(
lin_expr=[cplex.SparsePair([soc_start_var(bat,k),W_var(bat,k)],
val)],
senses=sense,
rhs=[0],
names=['Storage_inv_boundary_'+bat.GetName()+".K"+str(k)])
#constraints (21) denote variable bounds
#constraints (22)-(24) not directly implemented
def i_u_part_minus(bat,n):
"""
This defines:
i^{L-}_{bn} = i_u_part_minus(bat,n-1), and
i^{U-}_{bn} = i_u_part_minus(n)
"""
return bat.GetMinCurrent() + batPartsMinus[n]*(bat.GetIUMinus()-bat.GetMinCurrent())
def i_u_part_plus(bat,n):
"""
This defines:
i^{L+}_{bn} = i_u_part_plus(bat,n-1), and
i^{U+}_{bn} = i_u_part_plus(n)
"""
return bat.GetMinCurrent() + batPartsPlus[n]*(bat.GetIUPlus()-bat.GetMinCurrent())
#constraint 25a -- one lambda per BKT - reconcile plus.
val = [1.0 for i in range(1,numBatParts+1)]+[-1.0]
for bat in batteries:
for k in range(1,tech_maxes[bat.GetName()]+1):
p.linear_constraints.add(
lin_expr=[cplex.SparsePair([lambda_plus_var(bat,k,n,t)
for n in range(1,numBatParts+1)]+[B_plus_var(bat,k,t)],
val) for t in range(start_period,
end_period+1)],
senses=['E' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Linear_25a_'+bat.GetName()+".K"+str(k)+
".TT"+str(t) for t in range(start_period,
end_period+1)])
#constraint 25b -- one lambda per BKT - reconcile minus.
for bat in batteries:
for k in range(1,tech_maxes[bat.GetName()]+1):
p.linear_constraints.add(
lin_expr=[cplex.SparsePair([lambda_minus_var(bat,k,n,t)
for n in range(1,numBatParts+1)]+[B_minus_var(bat,k,t)],
val) for t in range(start_period,
end_period+1)],
senses=['E' for t in range(num_periods)],
rhs=scipy.zeros(num_periods),
names=['Linear_25b_'+bat.GetName()+".K"+str(k)+
You can’t perform that action at this time.
