本文整理汇总了Python中scipy.io.mmio.mmread函数的典型用法代码示例。如果您正苦于以下问题:Python mmread函数的具体用法?Python mmread怎么用?Python mmread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mmread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_var_bounds
def test_var_bounds(self):
""" Test bounds on optimisation variables.
"""
msg = self.case_name
_, xmin, xmax = self.solver._var_bounds()
mpxmin = mmread(join(DATA_DIR, self.case_name, "opf", "xmin_AC.mtx"))
mpxmax = mmread(join(DATA_DIR, self.case_name, "opf", "xmax_AC.mtx"))
self.assertTrue(mfeq1(xmin, mpxmin.flatten()), msg)
self.assertTrue(mfeq1(xmax, mpxmax.flatten()), msg)
示例2: test_constraints
def test_constraints(self):
""" Test equality and inequality constraints.
"""
AA, ll, uu = self.solver._linear_constraints(self.om)
mpA = mmread(join(DATA_DIR, self.case_name, "opf", "A_DC.mtx"))
mpl = mmread(join(DATA_DIR, self.case_name, "opf", "l_DC.mtx"))
mpu = mmread(join(DATA_DIR, self.case_name, "opf", "u_DC.mtx"))
self.assertTrue(mfeq2(AA, mpA.tocsr()), self.case_name)
self.assertTrue(mfeq1(ll, mpl.flatten()), self.case_name)
self.assertTrue(mfeq1(uu, mpu.flatten()), self.case_name)
示例3: testYbus
def testYbus(self):
""" Test bus and branch admittance matrices.
"""
self.case.index_buses()
Ybus, Yf, Yt = self.case.Y
mpYbus = mmread(join(DATA_DIR, self.case_name, "Ybus.mtx")).tocsr()
mpYf = mmread(join(DATA_DIR, self.case_name, "Yf.mtx")).tocsr()
mpYt = mmread(join(DATA_DIR, self.case_name, "Yt.mtx")).tocsr()
self.assertTrue(mfeq2(Ybus, mpYbus, diff=1e-12), self.case_name)
self.assertTrue(mfeq2(Yf, mpYf, diff=1e-12), self.case_name)
self.assertTrue(mfeq2(Yt, mpYt, diff=1e-12), self.case_name)
示例4: testAy
def testAy(self):
""" Test basin constraints for piece-wise linear gen cost variables.
"""
msg = self.case_name
self.case.sort_generators() # ext2int
_, _, gn = self.opf._remove_isolated(self.case)
_, ycon = self.opf._pwl_gen_costs(gn, self.case.base_mva)
if ycon is not None:
Ay = mmread(join(DATA_DIR, self.case_name, "opf", "Ay_DC.mtx"))
by = mmread(join(DATA_DIR, self.case_name, "opf", "by_DC.mtx"))
self.assertTrue(mfeq2(ycon.A, Ay.tocsr()), msg)
self.assertTrue(mfeq1(ycon.u, by.flatten()), msg)
示例5: testPg
def testPg(self):
""" Test active power variable.
"""
msg = self.case_name
self.case.sort_generators() # ext2int
_, _, gn = self.opf._remove_isolated(self.case)
Pg = self.opf._get_pgen_var(gn, self.case.base_mva)
mpPg0 = mmread(join(DATA_DIR, self.case_name, "opf", "Pg0.mtx"))
mpPmin = mmread(join(DATA_DIR, self.case_name, "opf", "Pmin.mtx"))
mpPmax = mmread(join(DATA_DIR, self.case_name, "opf", "Pmax.mtx"))
self.assertTrue(mfeq1(Pg.v0, mpPg0.flatten()), msg)
self.assertTrue(mfeq1(Pg.vl, mpPmin.flatten()), msg)
self.assertTrue(mfeq1(Pg.vu, mpPmax.flatten()), msg)
示例6: testVa
def testVa(self):
""" Test voltage angle variable.
"""
msg = self.case_name
bs, _, _ = self.opf._remove_isolated(self.case)
_, refs = self.opf._ref_check(self.case)
Va = self.opf._get_voltage_angle_var(refs, bs)
mpVa0 = mmread(join(DATA_DIR, self.case_name, "opf", "Va0.mtx"))
mpVal = mmread(join(DATA_DIR, self.case_name, "opf", "Val.mtx"))
mpVau = mmread(join(DATA_DIR, self.case_name, "opf", "Vau.mtx"))
self.assertTrue(mfeq1(Va.v0, mpVa0.flatten()), msg)
self.assertTrue(mfeq1(Va.vl, mpVal.flatten()), msg)
self.assertTrue(mfeq1(Va.vu, mpVau.flatten()), msg)
示例7: test_dSbus_dV
def test_dSbus_dV(self):
""" Test partial derivative of power injection w.r.t. voltage.
"""
mpYbus = mmread(join(DATA_DIR, self.case_name, "Ybus.mtx")).tocsr()
mpV0 = mmread(join(DATA_DIR, self.case_name, "V0.mtx")).flatten()
dSbus_dVm, dSbus_dVa = self.case.dSbus_dV(mpYbus, mpV0)
mp_dSbus_dVm = mmread(join(DATA_DIR, self.case_name, "dSbus_dVm0.mtx"))
mp_dSbus_dVa = mmread(join(DATA_DIR, self.case_name, "dSbus_dVa0.mtx"))
self.assertTrue(mfeq2(dSbus_dVm, mp_dSbus_dVm.tocsr(), 1e-12),
self.case_name)
self.assertTrue(mfeq2(dSbus_dVa, mp_dSbus_dVa.tocsr(), 1e-12),
self.case_name)
示例8: testVLConstPF
def testVLConstPF(self):
""" Test dispatchable load, constant power factor constraints.
"""
msg = self.case_name
_, _, gn = self.opf._remove_isolated(self.case)
vl = self.opf._const_pf_constraints(gn, self.case.base_mva)
if vl.A.shape[0] != 0:
Avl = mmread(join(DATA_DIR, self.case_name, "opf", "Avl.mtx"))
self.assertTrue(mfeq2(vl.A, Avl.tocsr()), msg)
lvl = mmread(join(DATA_DIR, self.case_name, "opf", "lang.mtx"))
self.assertTrue(mfeq1(vl.l, lvl.flatten()), msg)
uvl = mmread(join(DATA_DIR, self.case_name, "opf", "uang.mtx"))
self.assertTrue(mfeq1(vl.u, uvl.flatten()), msg)
示例9: testPfPt
def testPfPt(self):
""" Test branch flow limit constraints.
"""
msg = self.case_name
_, ln, _ = self.opf._remove_isolated(self.case)
_, Bf, _, Pfinj = self.case.Bdc
Pf, Pt = self.opf._branch_flow_dc(ln, Bf, Pfinj, self.case.base_mva)
lpf = mmread(join(DATA_DIR, self.case_name, "opf", "lpf.mtx"))
upf = mmread(join(DATA_DIR, self.case_name, "opf", "upf.mtx"))
upt = mmread(join(DATA_DIR, self.case_name, "opf", "upt.mtx"))
self.assertTrue(mfeq1(Pf.l, lpf.flatten()), msg)
self.assertTrue(mfeq1(Pf.u, upf.flatten()), msg)
self.assertTrue(mfeq1(Pt.l, lpf.flatten()), msg)
self.assertTrue(mfeq1(Pt.u, upt.flatten()), msg)
示例10: testPmis
def testPmis(self):
""" Test active power mismatch constraints.
"""
msg = self.case_name
case = self.case
case.sort_generators() # ext2int
B, _, Pbusinj, _ = case.Bdc
bs, _, gn = self.opf._remove_isolated(case)
Pmis = self.opf._power_mismatch_dc(bs, gn, B, Pbusinj, case.base_mva)
mpAmis = mmread(join(DATA_DIR, self.case_name, "opf", "Amis.mtx"))
mpbmis = mmread(join(DATA_DIR, self.case_name, "opf", "bmis.mtx"))
self.assertTrue(mfeq2(Pmis.A, mpAmis.tocsr(), 1e-12), msg)
self.assertTrue(mfeq1(Pmis.l, mpbmis.flatten()), msg)
self.assertTrue(mfeq1(Pmis.u, mpbmis.flatten()), msg)
示例11: check_read
def check_read(self, example, a, info):
f = open(self.fn, 'w')
f.write(example)
f.close()
assert_equal(mminfo(self.fn), info)
b = mmread(self.fn).todense()
assert_array_almost_equal(a, b)
示例12: test_simple_rectangular
def test_simple_rectangular(self):
a = [[1, 2, 3], [4, 5, 6]]
fn = self.fn
mmwrite(fn, a)
assert_equal(mminfo(fn), (2, 3, 6, "array", "integer", "general"))
b = mmread(fn)
assert_array_almost_equal(a, b)
示例13: test_simple_rectangular
def test_simple_rectangular(self):
a = [[1,2,3],[4,5,6]]
fn = mktemp()
mmwrite(fn,a)
assert_equal(mminfo(fn),(2,3,6,'array','integer','general'))
b = mmread(fn)
assert_array_almost_equal(a,b)
示例14: test_simple_rectangular_real
def test_simple_rectangular_real(self):
a = [[1, 2], [3.5, 4], [5, 6]]
fn = self.fn
mmwrite(fn, a)
assert_equal(mminfo(fn), (3, 2, 6, "array", "real", "general"))
b = mmread(fn)
assert_array_almost_equal(a, b)
示例15: test_simple_hermitian
def test_simple_hermitian(self):
a = [[1,2+3j],[2-3j,4]]
fn = mktemp()
mmwrite(fn,a)
assert_equal(mminfo(fn),(2,2,4,'array','complex','hermitian'))
b = mmread(fn)
assert_array_almost_equal(a,b)