<commit_before>package com.projects.systems.simulation;

import com.projects.models.PowerPlant;
import com.projects.models.Structure;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * Created by Dan on 6/29/2015.
 */
public class SupplyManager
{
    private List<PowerPlant> powerPlants;
    private List<Structure> structures;
    private double emissions;
    private double price;

    public SupplyManager()
    {
        structures = new ArrayList<Structure>();
        powerPlants = new ArrayList<PowerPlant>();
        reset();
    }

    public boolean calculateSupply(double demand)
    {
        double watts = demand;
        price = 0;
        emissions = 0;

        for (PowerPlant powerPlant : powerPlants)
        {
            double capacity = powerPlant.getCapacity();
            powerPlant.setCurrentOutput(0);

            if (demand > 0)
            {
                if (demand <= capacity)
                {
                    price += demand * powerPlant.getProductionCost();
                    emissions += demand * powerPlant.getEmissionRate();
                    powerPlant.setCurrentOutput(demand);
                    demand -= demand;
                }
                else
                {
                    price +=  capacity * powerPlant.getProductionCost();
                    emissions += capacity * powerPlant.getEmissionRate();
                    powerPlant.setCurrentOutput(capacity);
                    demand -= capacity;
                }
            }
        }

        if (watts > 0)
        {
            price /= watts; // $ per kWh
            emissions /= watts; // g per kWh
        }

        if (demand > 0)
        {
            price = 0;
            emissions = 0;
            return false;
        }

        return true;
    }

    public void reset()
    {<commit_msg>Power plant production costs and emission rates now vary depending on how much production is needed to meet demands. Power plants no longer have to function at full capacity if there isn't the need for it.<commit_after>package com.projects.systems.simulation;

import com.projects.models.PowerPlant;
import com.projects.models.Structure;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * Created by Dan on 6/29/2015.
 */
public class SupplyManager
{
    private List<PowerPlant> powerPlants;
    private List<Structure> structures;
    private double emissions;
    private double price;

    public SupplyManager()
    {
        structures = new ArrayList<Structure>();
        powerPlants = new ArrayList<PowerPlant>();
        reset();
    }

    public boolean calculateSupply(double demand)
    {
        price = 0;
        emissions = 0;

        for (PowerPlant powerPlant : powerPlants)
        {
            powerPlant.setCurrentOutput(0);

            if (demand > 0)
            {
                double capacity = powerPlant.getCapacity();
                double productionNeeded = demand/capacity;

                if (productionNeeded > 1)
                    productionNeeded = 1.0;

                double production = productionNeeded * capacity;
                powerPlant.setCurrentOutput(production);
                price += productionNeeded * powerPlant.getProductionCost();
                emissions += productionNeeded * powerPlant.getEmissionRate();
                demand -= production;
            }
        }

        if (demand > 0)
        {
            price = 0;
            emissions = 0;
            return false;
        }

        return true;
    }

    public void reset()
    {
{'fraction_non_alphanumeric': 0.08509485094850948, 'fraction_numerical': 0.008672086720867209, 'mean_word_length': 1.7259970457902511, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7554402', 'n_tokens_mistral': 985, 'n_tokens_neox': 911, 'n_words': 245}