@@ -22,7 +22,8 @@ namespace GridKit
2222 using SystemT = OPF ::SystemModel<RealT, IdxT>;
2323
2424 public:
25- // Ipopt stops with the constraints and the stationarity within its tolerance. They reach 5e-13 and 2e-13.
25+ // Ipopt stops with the constraints and the stationarity within its tolerance. They reach 5e-13 and 2e-13,
26+ // and the marginal prices 8e-13.
2627 static constexpr RealT kTol = static_cast <RealT>(1.0e-10 );
2728
2829 TestOutcome reference ()
@@ -41,10 +42,9 @@ namespace GridKit
4142 return success.report (__func__);
4243 }
4344
44- const RealT* x = system.x ().getData ();
45-
46- success *= isEqual (x[1 ], ZERO <RealT>, kTol );
47- success *= !isEqual (x[3 ], ZERO <RealT>, kTol ) && !isEqual (x[5 ], ZERO <RealT>, kTol );
45+ success *= isEqual (system.getBus (1 )->Vi (), ZERO <RealT>, kTol );
46+ success *= !isEqual (system.getBus (2 )->Vi (), ZERO <RealT>, kTol );
47+ success *= !isEqual (system.getBus (3 )->Vi (), ZERO <RealT>, kTol );
4848
4949 return success.report (__func__);
5050 }
@@ -65,22 +65,50 @@ namespace GridKit
6565 return success.report (__func__);
6666 }
6767
68- success *= system.evaluateConstraints () == 0 ;
69- if (!success)
70- {
71- return success.report (__func__);
72- }
7368 const RealT* g = system.g ().getData ();
7469 for (const IdxT i : SystemTestData::BALANCE_ROWS )
7570 {
7671 success *= isEqual (g[i], ZERO <RealT>, kTol );
7772 }
7873 success *= isEqual (g[SystemTestData::FLOW_ROWS [0 ]], SystemTestData::SMAX * SystemTestData::SMAX , kTol );
7974
80- const RealT* x = system.x ().getData ();
75+ const RealT p1 = system.getGenerator (" gen_1" )->P ();
76+ const RealT p3 = system.getGenerator (" gen_3" )->P ();
77+
78+ success *= p1 > p3;
79+ success *= p3 > ZERO <RealT>;
8180
82- success *= x[6 ] > x[8 ];
83- success *= x[8 ] > ZERO <RealT>;
81+ return success.report (__func__);
82+ }
83+
84+ // / The negative of the active power multiplier of a bus is the marginal
85+ // / cost of a generator there within its limits
86+ TestOutcome marginalPrices ()
87+ {
88+ TestStatus success = true ;
89+
90+ SystemT system (SystemTestData::data ());
91+ success *= system.allocate () == 0 && system.initialize () == 0 ;
92+ if (!success)
93+ {
94+ return success.report (__func__);
95+ }
96+ success *= optimize (system);
97+ if (!success)
98+ {
99+ return success.report (__func__);
100+ }
101+
102+ const auto price = [&system](IdxT number)
103+ {
104+ const auto P = static_cast <size_t >(OPF ::BusInternalConstraints::P);
105+ return -system.getBus (number)->lambda ().getData ()[P];
106+ };
107+ const auto marginalCost = [&system](const char * id, RealT c1)
108+ { return c1 + TWO <RealT> * SystemTestData::C2 * system.getGenerator (id)->P (); };
109+
110+ success *= isEqual (price (1 ), marginalCost (" gen_1" , SystemTestData::C1_GEN_1 ), kTol );
111+ success *= isEqual (price (3 ), marginalCost (" gen_3" , SystemTestData::C1_GEN_3 ), kTol );
84112
85113 return success.report (__func__);
86114 }
0 commit comments