Skip to content
Snippets Groups Projects
test_esipp_prices.py 39.2 KiB
Newer Older
  • Learn to ignore specific revisions
  •          (True, NODE_PRICE_DELTA),
             (True, NODE_PRICE_LAMBDA),
             (False, NODE_PRICE_OTHER),
             (False, NODE_PRICE_DELTA),
             (False, NODE_PRICE_LAMBDA)]
            )
        def test_direct_imp_exp_network_higher_exp_prices(self, use_prices_block, node_price_model):
    
    Pedro L. Magalhães's avatar
    Pedro L. Magalhães committed
            
            # time frame
            q = 0
            tf = EconomicTimeFrame(
                discount_rate=3.5/100,
                reporting_periods={q: (0,1)},
                reporting_period_durations={q: (365 * 24 * 3600,365 * 24 * 3600)},
                time_intervals={q: (0,1)},
                time_interval_durations={q: (1,1)},
            )    
            
            # 4 nodes: one import, one export, two supply/demand nodes
            mynet = Network()
        
            # import node
            imp_node_key = 'thatimpnode'
            imp_prices = {
                qpk: ResourcePrice(
                    prices=0.5,
    
                    volumes=None if node_price_model == NODE_PRICE_OTHER else 1e4,
    
    Pedro L. Magalhães's avatar
    Pedro L. Magalhães committed
                )
                for qpk in tf.qpk()
                }
            mynet.add_import_node(
                node_key=imp_node_key,
                prices=imp_prices
            )
        
            # export node
            exp_node_key = 'thatexpnode'
            exp_prices = {
                qpk: ResourcePrice(
                    prices=1.5,
    
                    volumes=None if node_price_model == NODE_PRICE_OTHER else 1e4,
    
    Pedro L. Magalhães's avatar
    Pedro L. Magalhães committed
                )
                for qpk in tf.qpk()
                }
            mynet.add_export_node(
                node_key=exp_node_key,
                prices=exp_prices,
            )
            
            # add arc without fixed losses from import node to export
            arc_tech_IE = Arcs(
                name="IE",
                # efficiency=[1, 1, 1, 1],
                efficiency={(0, 0): 1, (0, 1): 1, (0, 2): 1, (0, 3): 1},
                efficiency_reverse=None,
                static_loss=None,
                validate=False,
                capacity=[0.5, 1.0, 2.0],
                minimum_cost=[5, 5.1, 5.2],
                specific_capacity_cost=1,
                capacity_is_instantaneous=False,
            )
            mynet.add_directed_arc(
                node_key_a=imp_node_key, node_key_b=exp_node_key, arcs=arc_tech_IE
            )
        
            # no sos, regular time intervals
    
    Pedro L. Magalhães's avatar
    Pedro L. Magalhães committed
                solver_options={},
                perform_analysis=False,
                plot_results=False,  # True,
                print_solver_output=False,
                networks={"mynet": mynet},
                time_frame=tf,
                static_losses_mode=InfrastructurePlanningProblem.STATIC_LOSS_MODE_DEP,
                mandatory_arcs=[],
    
                use_prices_block=use_prices_block,
                node_price_model=node_price_model
    
    Pedro L. Magalhães's avatar
    Pedro L. Magalhães committed
            )
        
            # export prices are higher: it makes sense to install the arc since the
            # revenue (@ max. cap.) exceeds the cost of installing the arc
    
            assert (
                True
                in ipp.networks["mynet"]
                .edges[(imp_node_key, exp_node_key, 0)][Network.KEY_ARC_TECH]
                .options_selected
            )
    
    Pedro L. Magalhães's avatar
    Pedro L. Magalhães committed
            # overview
            (imports_qpk, 
             exports_qpk, 
             balance_qpk, 
             import_costs_qpk, 
             export_revenue_qpk, 
             ncf_qpk, 
             aggregate_static_demand_qpk,
             aggregate_static_supply_qpk,
             aggregate_static_balance_qpk) = statistics(ipp)
    
            # there should be no imports
    
            abs_tol = 1e-6
            
            abs_tol = 1e-3
            imports_qp = sum(imports_qpk[qpk] for qpk in tf.qpk() if qpk[1] == 0)
            assert imports_qp > 0.0 - abs_tol
    
            abs_tol = 1e-3
            import_costs_qp = sum(import_costs_qpk[qpk] for qpk in tf.qpk() if qpk[1] == 0)
            assert import_costs_qp > 0.0 - abs_tol
    
            # there should be no exports
    
            abs_tol = 1e-2
    
            exports_qp = sum(exports_qpk[(q, 0, k)] for k in tf.time_intervals[q])
            export_revenue_qp = sum(export_revenue_qpk[(q, 0, k)] for k in tf.time_intervals[q])
            assert exports_qp > 0.0 - abs_tol
            assert export_revenue_qp > 0.0 - abs_tol
    
            # the revenue should exceed the costs
    
            abs_tol = 1e-2
    
            assert (
                export_revenue_qp > import_costs_qp - abs_tol
            )
    
            # the capex should be positive
    
            abs_tol = 1e-6
    
            assert pyo.value(ipp.instance.var_capex) > 0 - abs_tol
            
        # *************************************************************************
        # *************************************************************************
    
    # *****************************************************************************
    # *****************************************************************************