def test_control_curve_interpolated(model): m = model m.scenarios.setup() si = ScenarioIndex(0, np.array([0], dtype=np.int32)) s = Storage(m, 'Storage', max_volume=100.0) cc = ConstantParameter(0.8) values = [20.0, 5.0, 0.0] s.cost = ControlCurveInterpolatedParameter(s, cc, values) s.setup(m) for v in (0.0, 10.0, 50.0, 80.0, 90.0, 100.0): s.initial_volume = v s.reset() assert_allclose(s.get_cost(m.timestepper.current, si), np.interp(v/100.0, [0.0, 0.8, 1.0], values[::-1])) # special case when control curve is 100% cc.update(np.array([1.0,])) s.initial_volume == 100.0 s.reset() assert_allclose(s.get_cost(m.timestepper.current, si), values[1]) # special case when control curve is 0% cc.update(np.array([0.0,])) s.initial_volume == 0.0 s.reset() assert_allclose(s.get_cost(m.timestepper.current, si), values[0])
def test_with_values(self, model): """Test with `values` keyword argument""" m = model s = Storage(m, 'Storage', max_volume=100.0) # Return 10.0 when above 0.0 when below s.cost = ControlCurveParameter(s, [0.8, 0.6], [1.0, 0.7, 0.4]) self._assert_results(m, s)
def test_with_parameters(self, model): """ Test with `parameters` keyword argument. """ m = model s = Storage(m, 'Storage', max_volume=100.0) # Two different control curves cc = [ConstantParameter(0.8), ConstantParameter(0.6)] # Three different parameters to return params = [ ConstantParameter(1.0), ConstantParameter(0.7), ConstantParameter(0.4) ] s.cost = ControlCurveParameter(s, cc, parameters=params) self._assert_results(m, s)