16 package emlab.gen.domain.factory;
18 import java.util.List;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.springframework.beans.factory.InitializingBean;
25 import org.springframework.transaction.annotation.Transactional;
38 private double capacityMargin;
40 private Map<PowerGeneratingTechnology, Double> portfolioShares = null;
42 private Set<PowerGridNode> nodes;
46 private List<EnergyProducer> producers;
48 static final Logger logger = LoggerFactory.getLogger(ElectricityProducerFactory.class);
51 public void afterPropertiesSet()
throws Exception {
52 createPowerPlantsForMarket(market);
58 String label = energyProducer.getName() +
" - " + technology.getName();
60 plant.setTechnology(technology);
61 plant.setOwner(energyProducer);
62 plant.setLocation(location);
63 plant.setConstructionStartTime(-(technology.getExpectedLeadtime() + technology.getExpectedPermittime() + Math.round((Math.random() * technology
64 .getExpectedLifetime()))) + 2);
68 plant.setActualLeadtime(plant.getTechnology().getExpectedLeadtime());
69 plant.setActualPermittime(plant.getTechnology().getExpectedPermittime());
70 plant.setExpectedEndOfLife(plant.getConstructionStartTime() + plant.getActualPermittime() + plant.getActualLeadtime()
71 + plant.getTechnology().getExpectedLifetime());
72 plant.setActualNominalCapacity(technology.getCapacity() * location.getCapacityMultiplicationFactor());
73 plant.calculateAndSetActualInvestedCapital(plant.getConstructionStartTime());
74 plant.calculateAndSetActualEfficiency(plant.getConstructionStartTime());
75 plant.calculateAndSetActualFixedOperatingCosts(plant.getConstructionStartTime());
76 plant.setDismantleTime(1000);
78 loan.setFrom(energyProducer);
80 double amountPerPayment = determineLoanAnnuities(plant.getActualInvestedCapital() * energyProducer.getDebtRatioOfInvestments(),
81 plant.getTechnology().getDepreciationTime(), energyProducer.getLoanInterestRate());
82 loan.setAmountPerPayment(amountPerPayment);
83 loan.setTotalNumberOfPayments(plant.getTechnology().getDepreciationTime());
84 loan.setLoanStartTime(plant.getConstructionStartTime());
85 loan.setNumberOfPaymentsDone(-plant.getConstructionStartTime());
96 double maxLoad = Double.MIN_NORMAL;
98 for (
SegmentLoad segmentLoad : market.getLoadDurationCurve()) {
100 if (maxLoad < segmentLoad.getBaseLoad()) {
101 maxLoad = segmentLoad.getBaseLoad();
104 double requiredCapacity = maxLoad * (1 + capacityMargin);
105 logger.info(
"required capacity for market {} is {}", market, requiredCapacity);
107 double pctValue = portfolioShares.get(technology);
108 double requiredCapacityForTechnology = pctValue * requiredCapacity;
109 logger.info(
"required capacity within this market for technology {} is {}", technology, requiredCapacityForTechnology);
112 while (requiredCapacityForTechnology > 0) {
114 PowerPlant plant = createPowerPlant(technology, energyProducer, getNodeForZone(market.getZone()));
115 requiredCapacityForTechnology -= plant.getAvailableCapacity(0);
123 private EnergyProducer getRandomProducer(List<EnergyProducer> producers) {
124 if (producers.size() > 0) {
125 int size = producers.size();
126 int index = getRandomIndexFromList(size);
127 return producers.get(index);
132 private int getRandomIndexFromList(
int size) {
133 return (
int) Math.min(Math.floor(Math.random() * size), size - 1);
138 if (node.getZone().equals(zone)) {
145 public double getCapacityMargin() {
146 return capacityMargin;
149 public void setCapacityMargin(
double capacityMargin) {
150 this.capacityMargin = capacityMargin;
153 public Map<PowerGeneratingTechnology, Double> getPortfolioShares() {
154 return portfolioShares;
157 public void setPortfolioShares(Map<PowerGeneratingTechnology, Double> portfolioShares) {
158 this.portfolioShares = portfolioShares;
161 public Set<PowerGridNode> getNodes() {
165 public void setNodes(Set<PowerGridNode> nodes) {
174 logger.info(
"setting market {}", market);
175 this.market = market;
178 public List<EnergyProducer> getProducers() {
182 public void setProducers(List<EnergyProducer> producers) {
183 this.producers = producers;
186 public double determineLoanAnnuities(
double totalLoan,
double payBackTime,
double interestRate) {
188 double q = 1 + interestRate;
189 double annuity = totalLoan * (Math.pow(q, payBackTime) * (q - 1)) / (Math.pow(q, payBackTime) - 1);