-
Notifications
You must be signed in to change notification settings - Fork 4
/
bus13_optcontrol.py
50 lines (38 loc) · 1.46 KB
/
bus13_optcontrol.py
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
# Kevin Moy 8/12/2020
# Method to instantiate OpenDSS IEEE 13-bus and find optimal action (control of capacitors) based on lowest reward
# TODO: this
import win32com.client
import numpy as np
NUM_STEPS = 4
def find_opt_action(loadkws):
# input: loadkws: NumPy array of load configurations
# output: opt_action, opt_reward: optimal action, optimal reward tuple
# Instantiate environment for testing
# Instantiate the OpenDSS Object
try:
DSSObj = win32com.client.Dispatch("OpenDSSEngine.DSS")
except:
print("Unable to start the OpenDSS Engine")
raise SystemExit
print("OpenDSS Engine started\n")
# Set up the Text, Circuit, and Solution Interfaces
DSSText = DSSObj.Text
DSSCircuit = DSSObj.ActiveCircuit
DSSSolution = DSSCircuit.Solution
# Load in an example circuit
DSSText.Command = r"Compile 'C:\Program Files\OpenDSS\IEEETestCases\13Bus\IEEE13Nodeckt.dss'"
# Disable voltage regulators
DSSText.Command = "Disable regcontrol.Reg1"
DSSText.Command = "Disable regcontrol.Reg2"
DSSText.Command = "Disable regcontrol.Reg3"
loadNames = np.array(DSSCircuit.Loads.AllNames)
# Test all four actions
opt_reward = -np.Inf
opt_action = -np.Inf
for step in range(NUM_STEPS):
action = step
obs, reward, done, info = env.step(action)
if reward > opt_reward:
opt_reward = reward
opt_action = action
return opt_action, opt_reward