1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Runs an optimal power flow with unit-decommitment heuristic.
18 """
19
20 from sys import stderr
21
22 from os.path import dirname, join
23
24 from pypower.ppoption import ppoption
25 from pypower.uopf import uopf
26 from pypower.printpf import printpf
27 from pypower.savecase import savecase
28
29
30 -def runuopf(casedata=None, ppopt=None, fname='', solvedcase=''):
31 """Runs an optimal power flow with unit-decommitment heuristic.
32
33 @see: L{rundcopf}, L{runuopf}
34
35 @author: Ray Zimmerman (PSERC Cornell)
36 @author: Richard Lincoln
37 """
38
39 if casedata is None:
40 casedata = join(dirname(__file__), 'case9')
41 ppopt = ppoption(ppopt)
42
43
44 r = uopf(casedata, ppopt)
45
46
47 if fname:
48 fd = None
49 try:
50 fd = open(fname, "wb")
51 except Exception, detail:
52 stderr.write("Error opening %s: %s.\n" % (fname, detail))
53 finally:
54 if fd is not None:
55 printpf(r, fd, ppopt)
56 fd.close()
57
58 printpf(r, ppopt=ppopt)
59
60
61 if solvedcase:
62 savecase(solvedcase, r)
63
64 return r
65