List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setToolTipGenerator
@Override public void setToolTipGenerator(XYToolTipGenerator generator)
From source file:Output.SplitChart.java
public void drawBranchPowerFlowData(String outputTimeTypeSelect, int iStartTime, int iEndTime, int iDayHour, int[] selectIndex) { String[] names = { "Branch Name", "Day Index", "Hour", "Power (MW)", "MaxCap (MW)" }; this.chartTitle = "Branch Power Flows"; boolean bSubtitle = false; String subtitles = ""; String xLabel = ""; iStartTime = iStartTime - 1;/*from w ww .j a va2 s.c o m*/ iEndTime = iEndTime - 1; ArrayList branchFlowByDay = this.amesFrame.getAMESMarket().getBranchFlowByDay(); ArrayList hasSolutionByDay = this.amesFrame.getAMESMarket().getHasSolutionByDay(); int[] hasSolutions; Object[][] branchData = this.amesFrame.getBranchData(); int iBranchNumber = branchData.length; boolean draw3DChart = false; this.dataset = new XYSeriesCollection(); DefaultCategoryDataset dataset3D = new DefaultCategoryDataset(); if ((selectIndex.length < 1) || (selectIndex[0] == 0)) { if (outputTimeTypeSelect.equalsIgnoreCase("Entire Run (Selected Hour)")) { this.chartTitle = this.chartTitle + "\n " + "For Entire Run (At Hour " + iDayHour + ":00)\n"; xLabel = "Day"; XYSeries noSolutionSeries = new XYSeries("No solution"); this.dataset.addSeries(noSolutionSeries); boolean bNoSolution = false; int iDayNumber = branchFlowByDay.size(); double[][] branchFlow; for (int j = 0; j < iBranchNumber; j++) { XYSeries series = new XYSeries((String) branchData[j][0]); for (int iDay = 0; iDay < iDayNumber; iDay++) { branchFlow = (double[][]) branchFlowByDay.get(iDay); hasSolutions = (int[]) hasSolutionByDay.get(iDay); series.add(iDay + 2, (Math.round(branchFlow[iDayHour][j] * 1000)) / 1000.0); if (hasSolutions[iDayHour] == 0) { noSolutionSeries.add(iDay + 2, 0.0); bNoSolution = true; } } this.dataset.addSeries(series); } if (!bNoSolution) { this.dataset.removeSeries(noSolutionSeries); } } else if (outputTimeTypeSelect.equalsIgnoreCase("Start to End Day (Selected Hour)")) { int iDayNumber = (iEndTime - iStartTime) + 1; XYSeries noSolutionSeries = new XYSeries("No solution"); this.dataset.addSeries(noSolutionSeries); boolean bNoSolution = false; double[][] branchFlow; for (int j = 0; j < iBranchNumber; j++) { XYSeries series = new XYSeries((String) branchData[j][0]); for (int iDay = iStartTime - 1; iDay < iEndTime; iDay++) { branchFlow = (double[][]) branchFlowByDay.get(iDay); hasSolutions = (int[]) hasSolutionByDay.get(iDay); series.add(iDay + 2, (Math.round(branchFlow[iDayHour][j] * 1000)) / 1000.0); if (hasSolutions[iDayHour] == 0) { noSolutionSeries.add(iDay + 2, 0.0); bNoSolution = true; } } this.dataset.addSeries(series); } if (!bNoSolution) { this.dataset.removeSeries(noSolutionSeries); } this.chartTitle = this.chartTitle + "\n " + "From Day " + (iStartTime + 1) + " to Day " + (iEndTime + 1) + " (At Hour " + iDayHour + ":00)"; xLabel = "Day"; } else if (outputTimeTypeSelect.equalsIgnoreCase("Entire Run (All Hours)")) { int iDayNumber = branchFlowByDay.size(); XYSeries noSolutionSeries = new XYSeries("No solution"); this.dataset.addSeries(noSolutionSeries); boolean bNoSolution = false; double[][] branchFlow; for (int j = 0; j < iBranchNumber; j++) { XYSeries series = new XYSeries((String) branchData[j][0]); for (int iDay = 0; iDay < iDayNumber; iDay++) { hasSolutions = (int[]) hasSolutionByDay.get(iDay); branchFlow = (double[][]) branchFlowByDay.get(iDay); for (int i = 0; i < 24; i++) { series.add(iDay + 1 + (i / 24.0), (Math.round(branchFlow[i][j] * 1000)) / 1000.0); if (hasSolutions[i] == 0) { noSolutionSeries.add(iDay + 1 + (i / 24.0), 0.0); bNoSolution = true; } } } this.dataset.addSeries(series); } if (!bNoSolution) { this.dataset.removeSeries(noSolutionSeries); } this.chartTitle = this.chartTitle + "\n " + "For Entire Run (All Hours)"; xLabel = "Day"; } else if (outputTimeTypeSelect.equalsIgnoreCase("Start to End Day (All Hours)")) { int iDayNumber = (iEndTime - iStartTime) + 1; XYSeries noSolutionSeries = new XYSeries("No solution"); this.dataset.addSeries(noSolutionSeries); boolean bNoSolution = false; double[][] branchFlow; for (int j = 0; j < iBranchNumber; j++) { XYSeries series = new XYSeries((String) branchData[j][0]); for (int iDay = iStartTime - 1; iDay < iEndTime; iDay++) { hasSolutions = (int[]) hasSolutionByDay.get(iDay); branchFlow = (double[][]) branchFlowByDay.get(iDay); for (int i = 0; i < 24; i++) { series.add(iDay + 1 + (i / 24.0), (Math.round(branchFlow[i][j] * 1000)) / 1000.0); if (hasSolutions[i] == 0) { noSolutionSeries.add(iDay + 1 + (i / 24.0), 0.0); bNoSolution = true; } } } this.dataset.addSeries(series); } if (!bNoSolution) { this.dataset.removeSeries(noSolutionSeries); } this.chartTitle = this.chartTitle + "\n " + "From Day " + (iStartTime + 1) + " to Day " + (iEndTime + 1) + " (All Hours)"; xLabel = "Day"; } } else { int iDataNumber = selectIndex.length; if (iDataNumber == 1) { bSubtitle = true; } int iField = names.length; if (outputTimeTypeSelect.equalsIgnoreCase("Entire Run (Selected Hour)")) { XYSeries noSolutionSeries = new XYSeries("No solution"); this.dataset.addSeries(noSolutionSeries); boolean bNoSolution = false; int iDayNumber = branchFlowByDay.size(); double[][] branchFlow; for (int j = 0; j < iDataNumber; j++) { XYSeries series = new XYSeries((String) branchData[selectIndex[j] - 1][0]); subtitles += branchData[selectIndex[j] - 1][0] + " Thermal Limit: " + branchData[selectIndex[j] - 1][3].toString() + "\n"; for (int iDay = 0; iDay < iDayNumber; iDay++) { hasSolutions = (int[]) hasSolutionByDay.get(iDay); branchFlow = (double[][]) branchFlowByDay.get(iDay); series.add(iDay + 2, (Math.round(branchFlow[iDayHour][selectIndex[j] - 1] * 1000)) / 1000.0); if (hasSolutions[iDayHour] == 0) { noSolutionSeries.add(iDay + 2, 0.0); bNoSolution = true; } } this.dataset.addSeries(series); } if (!bNoSolution) { this.dataset.removeSeries(noSolutionSeries); } this.chartTitle = this.chartTitle + "\n " + "For Entire Run (At Hour " + iDayHour + ":00)"; xLabel = "Day"; } else if (outputTimeTypeSelect.equalsIgnoreCase("Start to End Day (Selected Hour)")) { XYSeries noSolutionSeries = new XYSeries("No solution"); this.dataset.addSeries(noSolutionSeries); boolean bNoSolution = false; int iDayNumber = (iEndTime - iStartTime) + 1; double[][] branchFlow; for (int j = 0; j < iDataNumber; j++) { XYSeries series = new XYSeries((String) branchData[selectIndex[j] - 1][0]); subtitles += branchData[selectIndex[j] - 1][0] + " Thermal Limit: " + branchData[selectIndex[j] - 1][3].toString() + "\n"; for (int iDay = iStartTime - 1; iDay < iEndTime; iDay++) { hasSolutions = (int[]) hasSolutionByDay.get(iDay); branchFlow = (double[][]) branchFlowByDay.get(iDay); series.add(iDay + 2, (Math.round(branchFlow[iDayHour][selectIndex[j] - 1] * 1000)) / 1000.0); if (hasSolutions[iDayHour] == 0) { noSolutionSeries.add(iDay + 2, 0.0); bNoSolution = true; } } this.dataset.addSeries(series); } if (!bNoSolution) { this.dataset.removeSeries(noSolutionSeries); } this.chartTitle = this.chartTitle + "\n " + "From Day " + (iStartTime + 1) + " to Day " + (iEndTime + 1) + " (At Hour " + iDayHour + ":00)"; xLabel = "Day"; } else if (outputTimeTypeSelect.equalsIgnoreCase("Entire Run (All Hours)")) { XYSeries noSolutionSeries = new XYSeries("No solution"); this.dataset.addSeries(noSolutionSeries); boolean bNoSolution = false; int iDayNumber = branchFlowByDay.size(); double[][] branchFlow; for (int j = 0; j < iDataNumber; j++) { XYSeries series = new XYSeries((String) branchData[selectIndex[j] - 1][0]); subtitles += branchData[selectIndex[j] - 1][0] + " Thermal Limit: " + branchData[selectIndex[j] - 1][3].toString() + "\n"; for (int iDay = 0; iDay < iDayNumber; iDay++) { hasSolutions = (int[]) hasSolutionByDay.get(iDay); branchFlow = (double[][]) branchFlowByDay.get(iDay); for (int i = 0; i < 24; i++) { series.add(iDay + 1 + (i / 24.0), (Math.round(branchFlow[i][selectIndex[j] - 1] * 1000)) / 1000.0); if (hasSolutions[i] == 0) { noSolutionSeries.add(iDay + 1 + (i / 24.0), 0.0); bNoSolution = true; } } } this.dataset.addSeries(series); } if (!bNoSolution) { this.dataset.removeSeries(noSolutionSeries); } this.chartTitle = this.chartTitle + "\n " + "For Entire Run (All Hours)"; xLabel = "Day"; } else if (outputTimeTypeSelect.equalsIgnoreCase("Start to End Day (All Hours)")) { XYSeries noSolutionSeries = new XYSeries("No solution"); this.dataset.addSeries(noSolutionSeries); boolean bNoSolution = false; int iDayNumber = (iEndTime - iStartTime) + 1; double[][] branchFlow; for (int j = 0; j < iDataNumber; j++) { XYSeries series = new XYSeries((String) branchData[selectIndex[j] - 1][0]); subtitles += branchData[selectIndex[j] - 1][0] + " Thermal Limit: " + branchData[selectIndex[j] - 1][3].toString() + "\n"; for (int iDay = iStartTime - 1; iDay < iEndTime; iDay++) { hasSolutions = (int[]) hasSolutionByDay.get(iDay); branchFlow = (double[][]) branchFlowByDay.get(iDay); for (int i = 0; i < 24; i++) { series.add(iDay + 1 + (i / 24.0), (Math.round(branchFlow[i][selectIndex[j] - 1] * 1000)) / 1000.0); if (hasSolutions[i] == 0) { noSolutionSeries.add(iDay + 1 + (i / 24.0), 0.0); bNoSolution = true; } } } this.dataset.addSeries(series); } if (!bNoSolution) { this.dataset.removeSeries(noSolutionSeries); } this.chartTitle = this.chartTitle + "\n " + "From Day " + (iStartTime + 1) + " to Day " + (iEndTime + 1) + " (All Hours)"; xLabel = "Day"; } } // create the chart... this.chart = ChartFactory.createXYLineChart(this.chartTitle, // chart title xLabel, // x axis label "Power (MWs)", // y axis label this.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); if (bSubtitle) { TextTitle subTitle = new TextTitle(); subTitle.setText(subtitles); this.chart.addSubtitle(subTitle); } // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... this.chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final XYPlot plot = this.chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.blue); plot.setRangeGridlinePaint(Color.blue); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")); renderer.setToolTipGenerator(generator); plot.setRenderer(renderer); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); this.chart.getTitle().setFont(this.font); this.chartPanel.setChart(this.chart); }
From source file:Output.SplitChart.java
public void drawAggreagtedSupplyAndDemandWithTrueCostData(String outputTimeTypeSelect, int iStartTime, int iEndTime, int iDayHour, int[] selectIndex) { ArrayList genAgentSupplyOfferByDay = this.amesFrame.getAMESMarket().getGenAgentSupplyOfferByDay(); Object[][] genData = this.amesFrame.getGeneratorData(); int iGenNumber = genData.length; double[][] genOfferData = new double[iGenNumber][8]; // a, b, minCap, maxCap, 1/b, a/b, currentPower, currentPrice double[][] offerPrices = new double[iGenNumber * 2][2]; // price, index for (int i = 0; i < iGenNumber; i++) { genOfferData[i][0] = Support.parseDouble(genData[i][4].toString()); genOfferData[i][1] = Support.parseDouble(genData[i][5].toString()); genOfferData[i][2] = Support.parseDouble(genData[i][6].toString()); genOfferData[i][3] = Support.parseDouble(genData[i][7].toString()); genOfferData[i][4] = 1.0 / genOfferData[i][1]; genOfferData[i][5] = genOfferData[i][0] / genOfferData[i][1]; offerPrices[2 * i][0] = genOfferData[i][0] + (2 * genOfferData[i][1] * genOfferData[i][2]); offerPrices[2 * i][1] = 2 * i;//from ww w. j ava2s. c om offerPrices[(2 * i) + 1][0] = genOfferData[i][0] + (2 * genOfferData[i][1] * genOfferData[i][3]); offerPrices[(2 * i) + 1][1] = (2 * i) + 1; genOfferData[i][6] = genOfferData[i][2]; genOfferData[i][7] = offerPrices[2 * i][0]; } // sort the price of each generator double dTemp = 0; double iTemp = 0; for (int i = 0; i < (2 * iGenNumber); i++) { for (int j = i + 1; j < (2 * iGenNumber); j++) { if (offerPrices[i][0] > offerPrices[j][0]) { dTemp = offerPrices[i][0]; iTemp = offerPrices[i][1]; offerPrices[i][0] = offerPrices[j][0]; offerPrices[i][1] = offerPrices[j][1]; offerPrices[j][0] = dTemp; offerPrices[j][1] = iTemp; } } } double[][] genAggregateOfferDataPoints = new double[(iGenNumber * 2) - 1][4]; // leftPoint(power, price), rightPoint(power, price) int[][] genAggregateOfferCommit = new int[(iGenNumber * 2) - 1][iGenNumber * 2]; // in the first iGenNumber of each row is the index of gen whose output is fixed // in the second iGenNumber of each row is the index of gen whose output is variable // otherwise -1 for (int i = 0; i < ((2 * iGenNumber) - 1); i++) { for (int j = 0; j < (2 * iGenNumber); j++) { genAggregateOfferCommit[i][j] = -1; } } double leftPrice = offerPrices[0][0]; for (int i = 0; i < iGenNumber; i++) { if (leftPrice >= genOfferData[i][7]) { genAggregateOfferDataPoints[0][0] += genOfferData[i][6]; } } for (int i = 0; i < ((2 * iGenNumber) - 1); i++) { genAggregateOfferDataPoints[i][1] = offerPrices[i][0]; genAggregateOfferDataPoints[i][3] = offerPrices[i + 1][0]; if (i > 0) { genAggregateOfferDataPoints[i][0] = genAggregateOfferDataPoints[i - 1][2]; } genAggregateOfferDataPoints[i][2] = genAggregateOfferDataPoints[i][0]; int iIndexFixed = 0; int iIndexVariable = 0; double rightPrice = offerPrices[i + 1][0]; for (int j = 0; j < iGenNumber; j++) { if (rightPrice > genOfferData[j][7]) { if (Math.abs(genOfferData[j][6] - genOfferData[j][3]) < 0.000001) { // already at maxCap genAggregateOfferCommit[i][iIndexFixed++] = j; } else { double power = (rightPrice - genOfferData[j][0]) / (2 * genOfferData[j][1]); genAggregateOfferDataPoints[i][2] += power - genOfferData[j][6]; genAggregateOfferCommit[i][iGenNumber + iIndexVariable] = j; iIndexVariable++; genOfferData[j][7] = rightPrice; genOfferData[j][6] = power; } } } } double HighestGenOfferPrice = genAggregateOfferDataPoints[(iGenNumber * 2) - 2][3]; double HighestGenOfferPower = genAggregateOfferDataPoints[(iGenNumber * 2) - 2][2]; // Demand Object[][][] lsePriceSensitiveData = this.amesFrame.getLSEPriceSensitiveDemandData(); Object[][] lseHybridData = this.amesFrame.getLSEHybridDemandData(); Object[][] lseData = this.amesFrame.getLSEData(); int iLSENumber = lsePriceSensitiveData.length; double[][] lseDemandData = new double[iLSENumber][6]; // c, d, slMax, fixed demand, currentPower, currentPrice double[][] lsePrices = new double[iLSENumber * 2][2]; // price, index int hourlyLoadHybridFlagByLSE = 0; double priceCap = 1000.0; for (int i = 0; i < iLSENumber; i++) { hourlyLoadHybridFlagByLSE = Integer.parseInt(lseHybridData[i][iDayHour + 3].toString()); if ((hourlyLoadHybridFlagByLSE & 2) == 2) { double c = Support.parseDouble(lsePriceSensitiveData[i][iDayHour][4].toString()); double d = Support.parseDouble(lsePriceSensitiveData[i][iDayHour][5].toString()); double slMax = Support.parseDouble(lsePriceSensitiveData[i][iDayHour][6].toString()); lseDemandData[i][0] = c; lseDemandData[i][1] = d; lseDemandData[i][2] = slMax; lseDemandData[i][4] = 0.0; lseDemandData[i][5] = c; lsePrices[2 * i][0] = c; lsePrices[2 * i][1] = 2 * i; lsePrices[(2 * i) + 1][0] = c - (2 * d * slMax); lsePrices[(2 * i) + 1][1] = (2 * i) + 1; } else { lseDemandData[i][0] = 0.0; lseDemandData[i][1] = 0.0; lseDemandData[i][2] = 0.0; lseDemandData[i][4] = 0.0; lseDemandData[i][5] = priceCap; lsePrices[2 * i][0] = priceCap; lsePrices[2 * i][1] = 2 * i; lsePrices[(2 * i) + 1][0] = priceCap; lsePrices[(2 * i) + 1][1] = (2 * i) + 1; } if ((hourlyLoadHybridFlagByLSE & 1) == 1) { // fixed demand lseDemandData[i][3] = Support.parseDouble(lseData[i][iDayHour + 3].toString()); } } // sort the price of each lse for (int i = 0; i < (2 * iLSENumber); i++) { for (int j = i + 1; j < (2 * iLSENumber); j++) { if (lsePrices[i][0] < lsePrices[j][0]) { dTemp = lsePrices[i][0]; iTemp = lsePrices[i][1]; lsePrices[i][0] = lsePrices[j][0]; lsePrices[i][1] = lsePrices[j][1]; lsePrices[j][0] = dTemp; lsePrices[j][1] = iTemp; } } } double[][] lseAggregateDemandDataPoints = new double[(iLSENumber * 2) - 1][4]; // leftPoint(power, price), rightPoint(power, price) int[][] lseAggregateDemandCommit = new int[(iLSENumber * 2) - 1][iLSENumber * 2]; // in the first iLSENumber of each row is the index of LSE whose commit is fixed // in the second iLSENumber of each row is the index of LSE whose commit is variable // otherwise -1 for (int i = 0; i < ((2 * iLSENumber) - 1); i++) { for (int j = 0; j < (2 * iLSENumber); j++) { lseAggregateDemandCommit[i][j] = -1; } } leftPrice = lsePrices[0][0]; for (int i = 0; i < iLSENumber; i++) { lseAggregateDemandDataPoints[0][0] += lseDemandData[i][3]; if (leftPrice <= lseDemandData[i][5]) { lseAggregateDemandDataPoints[0][0] += lseDemandData[i][4]; } } for (int i = 0; i < ((2 * iLSENumber) - 1); i++) { lseAggregateDemandDataPoints[i][1] = lsePrices[i][0]; lseAggregateDemandDataPoints[i][3] = lsePrices[i + 1][0]; if (i > 0) { lseAggregateDemandDataPoints[i][0] = lseAggregateDemandDataPoints[i - 1][2]; } lseAggregateDemandDataPoints[i][2] = lseAggregateDemandDataPoints[i][0]; int iIndexFixed = 0; int iIndexVariable = 0; double rightPrice = lsePrices[i + 1][0]; for (int j = 0; j < iLSENumber; j++) { if (rightPrice < lseDemandData[j][5]) { if (Math.abs(lseDemandData[j][4] - lseDemandData[j][2]) < 0.000001) { // already at slMax lseAggregateDemandCommit[i][iIndexFixed++] = j; } else { double power = (lseDemandData[j][0] - rightPrice) / (2 * lseDemandData[j][1]); lseAggregateDemandDataPoints[i][2] += power - lseDemandData[j][4]; lseAggregateDemandCommit[i][iLSENumber + iIndexVariable] = j; iIndexVariable++; lseDemandData[j][5] = rightPrice; lseDemandData[j][4] = power; } } } } double HighestLSEDemandPrice = lseAggregateDemandDataPoints[0][1]; double HighestLSEDemandPower = lseAggregateDemandDataPoints[0][0]; double highestPrice = (HighestGenOfferPrice > HighestLSEDemandPrice) ? HighestGenOfferPrice : HighestLSEDemandPrice; highestPrice += 50; this.chartTitle = "True Total Supply and Demand Curves at Hour " + iDayHour; String xLabel = "Power (MWs)"; this.dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Supply"); ArrayList genTipList = new ArrayList(); String tipString = ""; leftPrice = genAggregateOfferDataPoints[0][1]; double leftPower = genAggregateOfferDataPoints[0][0]; series.add(leftPower, leftPrice); tipString = String.format("Power=%1$.2f Price=%2$.2f", leftPower, leftPrice); genTipList.add(new String(tipString)); double rightPrice = 0; double rightPower = 0; for (int i = 0; i < ((2 * iGenNumber) - 1); i++) { rightPrice = genAggregateOfferDataPoints[i][3]; rightPower = genAggregateOfferDataPoints[i][2]; series.add(rightPower, rightPrice); // For tip display tipString = String.format("Power=%1$.2f Price=%2$.2f", rightPower, rightPrice); String tempFixed = " FixedGen: "; String tempVariable = " Marginal GenCos: "; String temp; boolean bFixed = false; boolean bVariable = false; for (int j = 0; j < (2 * iGenNumber); j++) { if ((j < iGenNumber) && (genAggregateOfferCommit[i][j] != -1)) { bFixed = true; tempFixed += genData[genAggregateOfferCommit[i][j]][0] + " "; } if ((j >= iGenNumber) && (genAggregateOfferCommit[i][j] != -1)) { bVariable = true; tempVariable += genData[genAggregateOfferCommit[i][j]][0] + " "; } } if (bFixed) { tipString += tempFixed; } if (bVariable) { tipString += tempVariable; } genTipList.add(new String(tipString)); } // last infinity part series.add(rightPower, highestPrice); tipString = String.format("Power=%1$.2f Price=%2$.2f", rightPower, highestPrice); genTipList.add(new String(tipString)); this.dataset.addSeries(series); series = new XYSeries("Demand"); ArrayList LSETipList = new ArrayList(); //first infinity part series.add(HighestLSEDemandPower, highestPrice); tipString = String.format("Power=%1$.2f Price=%2$.2f", HighestLSEDemandPower, highestPrice); LSETipList.add(new String(tipString)); //second point leftPrice = lseAggregateDemandDataPoints[0][1]; leftPower = lseAggregateDemandDataPoints[0][0]; series.add(leftPower, leftPrice); tipString = String.format("Power=%1$.2f Price=%2$.2f", leftPower, leftPrice); LSETipList.add(new String(tipString)); for (int i = 0; i < ((2 * iLSENumber) - 1); i++) { rightPrice = lseAggregateDemandDataPoints[i][3]; rightPower = lseAggregateDemandDataPoints[i][2]; series.add(rightPower, rightPrice); // For tip display tipString = String.format("Power=%1$.2f Price=%2$.2f", rightPower, rightPrice); String tempFixed = " MaxPS LSE: "; String tempVariable = " VariablePS LSE: "; String temp; boolean bFixed = false; boolean bVariable = false; for (int j = 0; j < (2 * iLSENumber); j++) { if ((j < iLSENumber) && (lseAggregateDemandCommit[i][j] != -1)) { bFixed = true; tempFixed += lseData[lseAggregateDemandCommit[i][j]][0] + " "; } if ((j >= iLSENumber) && (lseAggregateDemandCommit[i][j] != -1)) { bVariable = true; tempVariable += lseData[lseAggregateDemandCommit[i][j]][0] + " "; } } if (bFixed) { tipString += tempFixed; } if (bVariable) { tipString += tempVariable; } LSETipList.add(new String(tipString)); } // last infinity part series.add(rightPower, 0.0); tipString = String.format("Power=%1$.2f Price=%2$.2f", rightPower, 0.0); LSETipList.add(new String(tipString)); this.dataset.addSeries(series); // create the chart... this.chart = ChartFactory.createXYLineChart(this.chartTitle, // chart title xLabel, // x axis label "Price ($/MWh)", // y axis label this.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); this.chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final XYPlot plot = this.chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.blue); plot.setRangeGridlinePaint(Color.blue); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")); CustomXYToolTipGenerator customTip = new CustomXYToolTipGenerator(); customTip.addToolTipSeries(genTipList); customTip.addToolTipSeries(LSETipList); renderer.setToolTipGenerator(customTip); plot.setRenderer(renderer); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); this.chart.getTitle().setFont(this.font); this.chartPanel.setChart(this.chart); }
From source file:Output.SplitChart.java
public void drawAggreagtedSupplyAndDemandData(String outputTimeTypeSelect, int iStartTime, int iEndTime, int iDayHour, int[] selectIndex) { ArrayList genAgentSupplyOfferByDay = this.amesFrame.getAMESMarket().getGenAgentSupplyOfferByDay(); double[][] genOffer = (double[][]) genAgentSupplyOfferByDay.get(iStartTime - 2); Object[][] genData = this.amesFrame.getGeneratorData(); int iGenNumber = genData.length; double[][] genOfferData = new double[iGenNumber][8]; // a, b, minCap, maxCap, 1/b, a/b, currentPower, currentPrice double[][] offerPrices = new double[iGenNumber * 2][2]; // price, index for (int i = 0; i < iGenNumber; i++) { genOfferData[i][0] = genOffer[i][0]; genOfferData[i][1] = genOffer[i][1]; genOfferData[i][2] = genOffer[i][2]; genOfferData[i][3] = genOffer[i][3]; genOfferData[i][4] = 1.0 / genOfferData[i][1]; genOfferData[i][5] = genOfferData[i][0] / genOfferData[i][1]; offerPrices[2 * i][0] = genOfferData[i][0] + (2 * genOfferData[i][1] * genOfferData[i][2]); offerPrices[2 * i][1] = 2 * i;/*from w ww .j a v a2 s. co m*/ offerPrices[(2 * i) + 1][0] = genOfferData[i][0] + (2 * genOfferData[i][1] * genOfferData[i][3]); offerPrices[(2 * i) + 1][1] = (2 * i) + 1; genOfferData[i][6] = genOfferData[i][2]; genOfferData[i][7] = offerPrices[2 * i][0]; } // sort the price of each generator double dTemp = 0; double iTemp = 0; for (int i = 0; i < (2 * iGenNumber); i++) { for (int j = i + 1; j < (2 * iGenNumber); j++) { if (offerPrices[i][0] > offerPrices[j][0]) { dTemp = offerPrices[i][0]; iTemp = offerPrices[i][1]; offerPrices[i][0] = offerPrices[j][0]; offerPrices[i][1] = offerPrices[j][1]; offerPrices[j][0] = dTemp; offerPrices[j][1] = iTemp; } } } double[][] genAggregateOfferDataPoints = new double[(iGenNumber * 2) - 1][4]; // leftPoint(power, price), rightPoint(power, price) int[][] genAggregateOfferCommit = new int[(iGenNumber * 2) - 1][iGenNumber * 2]; // in the first iGenNumber of each row is the index of gen whose output is fixed // in the second iGenNumber of each row is the index of gen whose output is variable // otherwise -1 for (int i = 0; i < ((2 * iGenNumber) - 1); i++) { for (int j = 0; j < (2 * iGenNumber); j++) { genAggregateOfferCommit[i][j] = -1; } } double leftPrice = offerPrices[0][0]; for (int i = 0; i < iGenNumber; i++) { if (leftPrice >= genOfferData[i][7]) { genAggregateOfferDataPoints[0][0] += genOfferData[i][6]; } } for (int i = 0; i < ((2 * iGenNumber) - 1); i++) { genAggregateOfferDataPoints[i][1] = offerPrices[i][0]; genAggregateOfferDataPoints[i][3] = offerPrices[i + 1][0]; if (i > 0) { genAggregateOfferDataPoints[i][0] = genAggregateOfferDataPoints[i - 1][2]; } genAggregateOfferDataPoints[i][2] = genAggregateOfferDataPoints[i][0]; int iIndexFixed = 0; int iIndexVariable = 0; double rightPrice = offerPrices[i + 1][0]; for (int j = 0; j < iGenNumber; j++) { if (rightPrice > genOfferData[j][7]) { if (Math.abs(genOfferData[j][6] - genOfferData[j][3]) < 0.000001) { // already at maxCap genAggregateOfferCommit[i][iIndexFixed++] = j; } else { double power = (rightPrice - genOfferData[j][0]) / (2 * genOfferData[j][1]); genAggregateOfferDataPoints[i][2] += power - genOfferData[j][6]; genAggregateOfferCommit[i][iGenNumber + iIndexVariable] = j; iIndexVariable++; genOfferData[j][7] = rightPrice; genOfferData[j][6] = power; } } } } double HighestGenOfferPrice = genAggregateOfferDataPoints[(iGenNumber * 2) - 2][3]; double HighestGenOfferPower = genAggregateOfferDataPoints[(iGenNumber * 2) - 2][2]; // Demand Object[][][] lsePriceSensitiveData = this.amesFrame.getLSEPriceSensitiveDemandData(); Object[][] lseHybridData = this.amesFrame.getLSEHybridDemandData(); Object[][] lseData = this.amesFrame.getLSEData(); int iLSENumber = lsePriceSensitiveData.length; double[][] lseDemandData = new double[iLSENumber][6]; // c, d, slMax, fixed demand, currentPower, currentPrice double[][] lsePrices = new double[iLSENumber * 2][2]; // price, index int hourlyLoadHybridFlagByLSE = 0; double priceCap = 1000.0; for (int i = 0; i < iLSENumber; i++) { hourlyLoadHybridFlagByLSE = Integer.parseInt(lseHybridData[i][iDayHour + 3].toString()); if ((hourlyLoadHybridFlagByLSE & 2) == 2) { double c = Support.parseDouble(lsePriceSensitiveData[i][iDayHour][4].toString()); double d = Support.parseDouble(lsePriceSensitiveData[i][iDayHour][5].toString()); double slMax = Support.parseDouble(lsePriceSensitiveData[i][iDayHour][6].toString()); lseDemandData[i][0] = c; lseDemandData[i][1] = d; lseDemandData[i][2] = slMax; lseDemandData[i][4] = 0.0; lseDemandData[i][5] = c; lsePrices[2 * i][0] = c; lsePrices[2 * i][1] = 2 * i; lsePrices[(2 * i) + 1][0] = c - (2 * d * slMax); lsePrices[(2 * i) + 1][1] = (2 * i) + 1; } else { lseDemandData[i][0] = 0.0; lseDemandData[i][1] = 0.0; lseDemandData[i][2] = 0.0; lseDemandData[i][4] = 0.0; lseDemandData[i][5] = priceCap; lsePrices[2 * i][0] = priceCap; lsePrices[2 * i][1] = 2 * i; lsePrices[(2 * i) + 1][0] = priceCap; lsePrices[(2 * i) + 1][1] = (2 * i) + 1; } if ((hourlyLoadHybridFlagByLSE & 1) == 1) { // fixed demand lseDemandData[i][3] = Support.parseDouble(lseData[i][iDayHour + 3].toString()); } } // sort the price of each lse for (int i = 0; i < (2 * iLSENumber); i++) { for (int j = i + 1; j < (2 * iLSENumber); j++) { if (lsePrices[i][0] < lsePrices[j][0]) { dTemp = lsePrices[i][0]; iTemp = lsePrices[i][1]; lsePrices[i][0] = lsePrices[j][0]; lsePrices[i][1] = lsePrices[j][1]; lsePrices[j][0] = dTemp; lsePrices[j][1] = iTemp; } } } double[][] lseAggregateDemandDataPoints = new double[(iLSENumber * 2) - 1][4]; // leftPoint(power, price), rightPoint(power, price) int[][] lseAggregateDemandCommit = new int[(iLSENumber * 2) - 1][iLSENumber * 2]; // in the first iLSENumber of each row is the index of LSE whose commit is fixed // in the second iLSENumber of each row is the index of LSE whose commit is variable // otherwise -1 for (int i = 0; i < ((2 * iLSENumber) - 1); i++) { for (int j = 0; j < (2 * iLSENumber); j++) { lseAggregateDemandCommit[i][j] = -1; } } leftPrice = lsePrices[0][0]; for (int i = 0; i < iLSENumber; i++) { lseAggregateDemandDataPoints[0][0] += lseDemandData[i][3]; if (leftPrice <= lseDemandData[i][5]) { lseAggregateDemandDataPoints[0][0] += lseDemandData[i][4]; } } for (int i = 0; i < ((2 * iLSENumber) - 1); i++) { lseAggregateDemandDataPoints[i][1] = lsePrices[i][0]; lseAggregateDemandDataPoints[i][3] = lsePrices[i + 1][0]; if (i > 0) { lseAggregateDemandDataPoints[i][0] = lseAggregateDemandDataPoints[i - 1][2]; } lseAggregateDemandDataPoints[i][2] = lseAggregateDemandDataPoints[i][0]; int iIndexFixed = 0; int iIndexVariable = 0; double rightPrice = lsePrices[i + 1][0]; for (int j = 0; j < iLSENumber; j++) { if (rightPrice < lseDemandData[j][5]) { if (Math.abs(lseDemandData[j][4] - lseDemandData[j][2]) < 0.000001) { // already at slMax lseAggregateDemandCommit[i][iIndexFixed++] = j; } else { double power = (lseDemandData[j][0] - rightPrice) / (2 * lseDemandData[j][1]); lseAggregateDemandDataPoints[i][2] += power - lseDemandData[j][4]; lseAggregateDemandCommit[i][iLSENumber + iIndexVariable] = j; iIndexVariable++; lseDemandData[j][5] = rightPrice; lseDemandData[j][4] = power; } } } } double HighestLSEDemandPrice = lseAggregateDemandDataPoints[0][1]; double HighestLSEDemandPower = lseAggregateDemandDataPoints[0][0]; double highestPrice = (HighestGenOfferPrice > HighestLSEDemandPrice) ? HighestGenOfferPrice : HighestLSEDemandPrice; highestPrice += 50; this.chartTitle = "Reported Total Supply and Demand Curves at Day " + iStartTime + " Hour " + iDayHour; String xLabel = "Power (MWs)"; this.dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Supply"); ArrayList genTipList = new ArrayList(); String tipString = ""; leftPrice = genAggregateOfferDataPoints[0][1]; double leftPower = genAggregateOfferDataPoints[0][0]; series.add(leftPower, leftPrice); tipString = String.format("Power=%1$.2f Price=%2$.2f", leftPower, leftPrice); genTipList.add(new String(tipString)); double rightPrice = 0; double rightPower = 0; for (int i = 0; i < ((2 * iGenNumber) - 1); i++) { rightPrice = genAggregateOfferDataPoints[i][3]; rightPower = genAggregateOfferDataPoints[i][2]; series.add(rightPower, rightPrice); // For tip display tipString = String.format("Power=%1$.2f Price=%2$.2f", rightPower, rightPrice); String tempFixed = " FixedGen: "; String tempVariable = " Marginal GenCos: "; String temp; boolean bFixed = false; boolean bVariable = false; for (int j = 0; j < (2 * iGenNumber); j++) { if ((j < iGenNumber) && (genAggregateOfferCommit[i][j] != -1)) { bFixed = true; tempFixed += genData[genAggregateOfferCommit[i][j]][0] + " "; } if ((j >= iGenNumber) && (genAggregateOfferCommit[i][j] != -1)) { bVariable = true; tempVariable += genData[genAggregateOfferCommit[i][j]][0] + " "; } } if (bFixed) { tipString += tempFixed; } if (bVariable) { tipString += tempVariable; } genTipList.add(new String(tipString)); } // last infinity part series.add(rightPower, highestPrice); tipString = String.format("Power=%1$.2f Price=%2$.2f", rightPower, highestPrice); genTipList.add(new String(tipString)); this.dataset.addSeries(series); series = new XYSeries("Demand"); ArrayList LSETipList = new ArrayList(); //first infinity part series.add(HighestLSEDemandPower, highestPrice); tipString = String.format("Power=%1$.2f Price=%2$.2f", HighestLSEDemandPower, highestPrice); LSETipList.add(new String(tipString)); //second point leftPrice = lseAggregateDemandDataPoints[0][1]; leftPower = lseAggregateDemandDataPoints[0][0]; series.add(leftPower, leftPrice); tipString = String.format("Power=%1$.2f Price=%2$.2f", leftPower, leftPrice); LSETipList.add(new String(tipString)); for (int i = 0; i < ((2 * iLSENumber) - 1); i++) { rightPrice = lseAggregateDemandDataPoints[i][3]; rightPower = lseAggregateDemandDataPoints[i][2]; series.add(rightPower, rightPrice); // For tip display tipString = String.format("Power=%1$.2f Price=%2$.2f", rightPower, rightPrice); String tempFixed = " MaxPS LSE: "; String tempVariable = " VariablePS LSE: "; String temp; boolean bFixed = false; boolean bVariable = false; for (int j = 0; j < (2 * iLSENumber); j++) { if ((j < iLSENumber) && (lseAggregateDemandCommit[i][j] != -1)) { bFixed = true; tempFixed += lseData[lseAggregateDemandCommit[i][j]][0] + " "; } if ((j >= iLSENumber) && (lseAggregateDemandCommit[i][j] != -1)) { bVariable = true; tempVariable += lseData[lseAggregateDemandCommit[i][j]][0] + " "; } } if (bFixed) { tipString += tempFixed; } if (bVariable) { tipString += tempVariable; } LSETipList.add(new String(tipString)); } // last infinity part series.add(rightPower, 0.0); tipString = String.format("Power=%1$.2f Price=%2$.2f", rightPower, 0.0); LSETipList.add(new String(tipString)); this.dataset.addSeries(series); // create the chart... this.chart = ChartFactory.createXYLineChart(this.chartTitle, // chart title xLabel, // x axis label "Price ($/MWh)", // y axis label this.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); this.chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final XYPlot plot = this.chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.blue); plot.setRangeGridlinePaint(Color.blue); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")); CustomXYToolTipGenerator customTip = new CustomXYToolTipGenerator(); customTip.addToolTipSeries(genTipList); customTip.addToolTipSeries(LSETipList); renderer.setToolTipGenerator(customTip); //renderer.setSeriesStroke(0, new BasicStroke(3.0f)); //renderer.setSeriesStroke(1, new BasicStroke(3.0f)); plot.setRenderer(renderer); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //xAxis.setLabelFont(font); //xAxis.setTickLabelFont(font); //NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); //yAxis.setLabelFont(font); //yAxis.setTickLabelFont(font); this.chart.getTitle().setFont(this.font); this.chartPanel.setChart(this.chart); }