######################################################################## # # MIDACO solves Multi-Objective Mixed-Integer Non-Linear Problems: # # # Minimize F_1(X),... F_O(X) where X(1,...N-NI) is CONTINUOUS # and X(N-NI+1,...N) is DISCRETE # # subject to G_j(X) = 0 (j=1,...ME) equality constraints # G_j(X) >= 0 (j=ME+1,...M) inequality constraints # # and bounds XL <= X <= XU # # # The problem statement of this example is given below. You can use # this example as template to run your own problem. To do so: Replace # the objective functions 'F' (and in case the constraints 'G') given # here with your own problem and follow the below instruction steps. # ######################################################################## import numpy as np import midaco def network_data(): # 38-bus islanded microgrid of the CEC 2020 power system problems. # Lines [bus i, bus j, resistance, reactance at nominal frequency]: LN = np.array([[1, 2, 0.000574, 0.000293], [2, 3, 0.00307, 0.001564], [3, 4, 0.002279, 0.001161], [4, 5, 0.002373, 0.001209], [5, 6, 0.0051, 0.004402], [6, 7, 0.00116, 0.003853], [7, 8, 0.00443, 0.001464], [8, 9, 0.006411, 0.004668], [9, 10, 0.006501, 0.004608], [10, 11, 0.001224, 0.000405], [11, 12, 0.002331, 0.000771], [12, 13, 0.009141, 0.007192], [13, 14, 0.003372, 0.004439], [14, 15, 0.00368, 0.003275], [15, 16, 0.004647, 0.003394], [16, 17, 0.008026, 0.010716], [17, 18, 0.004558, 0.003574], [2, 19, 0.001021, 0.000974], [19, 20, 0.009366, 0.00844], [20, 21, 0.00255, 0.002979], [21, 22, 0.004414, 0.005836], [3, 23, 0.002809, 0.00192], [23, 24, 0.005592, 0.004415], [24, 25, 0.005579, 0.004366], [6, 26, 0.001264, 0.000644], [26, 27, 0.00177, 0.000901], [27, 28, 0.006594, 0.005814], [28, 29, 0.005007, 0.004362], [29, 30, 0.00316, 0.00161], [30, 31, 0.006067, 0.005996], [31, 32, 0.001933, 0.002253], [32, 33, 0.002123, 0.003301], [8, 34, 0.012453, 0.012453], [9, 35, 0.012453, 0.012453], [12, 36, 0.012453, 0.012453], [18, 37, 0.003113, 0.003113], [25, 38, 0.003113, 0.003113]]) # loads of the buses: active/reactive power and voltage exponents PL = np.array([0, 0.1, 0.09, 0.12, 0.06, 0.06, 0.2, 0.2, 0.06, 0.06, 0.045, 0.06, 0.06, 0.12, 0.06, 0.06, 0.06, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.42, 0.42, 0.06, 0.06, 0.06, 0.12, 0.2, 0.15, 0.21, 0.06, 0, 0, 0, 0, 0]) PE = np.array([0, 0.92, 0.18, 1.51, 0.92, 0.18, 1.51, 1.51, 0.18, 1.51, 1.51, 0.92, 1.51, 0.92, 1.51, 0.18, 1.51, 0.18, 0.92, 1.51, 0.18, 0.92, 1.51, 1.51, 1.51, 1.51, 0.18, 1.51, 1.51, 1.51, 0.92, 0.92, 1.51, 0, 0, 0, 0, 0]) QL = np.array([0, 0.06, 0.04, 0.08, 0.03, 0.02, 0.1, 0.1, 0.02, 0.02, 0.03, 0.035, 0.035, 0.08, 0.01, 0.02, 0.02, 0.04, 0.04, 0.04, 0.04, 0.04, 0.05, 0.2, 0.2, 0.025, 0.025, 0.02, 0.07, 0.6, 0.07, 0.1, 0.04, 0, 0, 0, 0, 0]) QE = np.array([0, 4.04, 6, 3.4, 4.04, 6, 3.4, 3.4, 6, 3.4, 3.4, 4.04, 3.4, 4.04, 3.4, 6, 3.4, 6, 4.04, 3.4, 6, 4.04, 3.4, 3.4, 3.4, 3.4, 6, 3.4, 3.4, 3.4, 4.04, 4.04, 3.4, 0, 0, 0, 0, 0]) return LN, PL, PE, QL, QE LN, PL, PE, QL, QE = network_data() FB = LN[:,0].astype(int) - 1 TB = LN[:,1].astype(int) - 1 ######################################################################## def problem_function(x): x = np.array(x[:86], dtype=float) w = x[74] # frequency of the islanded grid y = 1.0/(LN[:,2] + 1j*w*LN[:,3]) # line admittances at frequency w Y = np.zeros((38,38), dtype=complex) # admittance matrix np.add.at(Y, (FB, TB), -y); np.add.at(Y, (TB, FB), -y) np.add.at(Y, (FB, FB), y); np.add.at(Y, (TB, TB), y) V = np.concatenate(([x[75] + 1e-5], x[0:37] + 1j*x[37:74])) # bus voltages Pdg = np.zeros(38); Pdg[33:38] = x[76:81] # active droop gains of the 5 DG units Qdg = np.zeros(38); Qdg[33:38] = x[81:86] # reactive droop gains of the 5 DG units Va = np.abs(V) Psp = Pdg*(1.0 - w) - PL*Va**PE # droop controlled generation minus Qsp = Qdg*(1.0 - Va) - QL*Va**QE # voltage dependent loads I = Y @ V # bus currents dI = I - np.conj((Psp + 1j*Qsp)/V) # Equality constraints G(X) = 0: the 2 x 38 current balance equations g = np.concatenate((dI.real, dI.imag)) # Objective: active and reactive power injections f = 0.5*(Qsp.sum() + Psp.sum()) return [float(f)], g.tolist() ######################################################################## key = b'************************************************************' problem = {} option = {} problem['@'] = problem_function problem['o'] = 1 # Number of objectives problem['n'] = 86 # Number of variables (in total) problem['ni'] = 0 # Number of integer variables (0 <= ni <= n) problem['m'] = 76 # Number of constraints (in total) problem['me'] = 76 # Number of equality constraints (0 <= me <= m) problem['xl'] = [-1.0]*74 + [0.0]*12 problem['xu'] = [ 1.0]*74 + [2.0, 2.0] + [500.0]*10 problem['x'] = list(problem['xl']) # Starting point: lower bounds option['maxeval'] = 1000000 option['maxtime'] = 60*60*24 option['printeval'] = 250 option['save2file'] = 1 option['resumable'] = 0 option['param1'] = 1e-08 # ACCURACY option['param2'] = 0.0 # SEED option['param3'] = 0.07983597 + 0.07983597*1e-4 # FSTOP option['param4'] = 0.0 # ALGOSTOP option['param5'] = 0.0 # EVALSTOP option['param6'] = 0.0 # FOCUS option['param7'] = 0.0 # ANTS option['param8'] = 0.0 # KERNEL option['param9'] = 0.0 # ORACLE option['param10'] = 0.0 # PARETOMAX option['param11'] = 0.0 # EPSILON option['param12'] = 0.0 # BALANCE option['param13'] = 0.0 # CHARACTER option['param14'] = 0.0 # SURROGATE option['param15'] = 2.0 # PMISQP option['parallel'] = 0 # Serial: 0 or 1, Parallel: 2,3,4,5,6,7,8... option['paradigm'] = 0 # Parallel mode: 0 = multiprocessing, 1 = mpi4py, 2 = vectorized ######################################################################## if __name__ == '__main__': solution = midaco.run(problem, option, key)