001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.logistics.ui.inventory;
028:
029: import java.util.ArrayList;
030:
031: import com.klg.jclass.chart.ChartDataModel;
032: import com.klg.jclass.chart.LabelledChartDataModel;
033: import com.klg.jclass.chart.ChartDataSupport;
034: import com.klg.jclass.chart.ChartDataEvent;
035: import com.klg.jclass.chart.ChartDataManageable;
036: import com.klg.jclass.chart.ChartDataManager;
037:
038: import org.cougaar.util.log.Logging;
039: import org.cougaar.util.log.Logger;
040:
041: /**
042: * <pre>
043: *
044: * The ShortfallChartDataModel is the ChartDataModel for the
045: * calculation of shortfall lines from chartdatamodels that
046: * contain requested and allocation results displayed in their
047: * y coordinates.
048: *
049: * @see InventoryBaseChartDataModel
050: * @see RequisitionsChartDataModel
051: * @see ProjectionsChartDataModel
052: *
053: **/
054:
055: public class InventoryShortfallChartDataModel extends
056: ShortfallChartDataModel {
057:
058: protected InventoryLevelChartDataModel invModel;
059:
060: public final static int INVENTORY_SHORTFALL_SERIES_INDEX = 0;
061:
062: private double minShortfall;
063:
064: public InventoryShortfallChartDataModel(
065: InventoryLevelChartDataModel invDM,
066: RequisitionsChartDataModel reqDM,
067: ProjectionsChartDataModel projDM) {
068: this (SHORTFALL_LEGEND, invDM, reqDM, projDM);
069: }
070:
071: public InventoryShortfallChartDataModel(String theLegendTitle,
072: InventoryLevelChartDataModel invDM,
073: RequisitionsChartDataModel reqDM,
074: ProjectionsChartDataModel projDM) {
075: inventory = null;
076: legendTitle = theLegendTitle;
077: invModel = invDM;
078: reqModel = reqDM;
079: projModel = projDM;
080: nSeries = 1;
081: seriesLabels = new String[nSeries];
082: seriesLabels[INVENTORY_SHORTFALL_SERIES_INDEX] = SHORTFALL_SERIES_LABEL;
083: logger = Logging.getLogger(this );
084: initValues();
085: }
086:
087: public void setShortfallValues() {
088: shortfallExists = false;
089: if ((reqModel.getNumSeries() == 0)
090: || (projModel.getNumSeries() == 0)
091: || (invModel.getNumSeries() == 0)) {
092: return;
093: }
094: nValues = reqModel.getXSeries(0).length;
095: if (nValues != projModel.getXSeries(0).length) {
096: logger
097: .debug("Whoa! Different number of values between reqModel "
098: + nValues
099: + " and projModel! "
100: + projModel.getXSeries(0).length);
101: }
102:
103: xvalues = new double[nSeries][];
104: yvalues = new double[nSeries][nValues];
105:
106: xvalues[INVENTORY_SHORTFALL_SERIES_INDEX] = reqModel
107: .getXSeries(0);
108:
109: if (nValues == 0) {
110: return;
111: }
112:
113: minShortfall = 0;
114:
115: double tolerance = 0.01;
116:
117: if (invModel.getYSeries(0)[0] - tolerance <= 0) {
118: yvalues[INVENTORY_SHORTFALL_SERIES_INDEX][0] = ((reqModel
119: .getYSeries(ACTUAL_SERIES_INDEX)[0] - reqModel
120: .getYSeries(REQUESTED_SERIES_INDEX)[0]) + (projModel
121: .getRealYSeries(ACTUAL_SERIES_INDEX)[0] - projModel
122: .getRealYSeries(REQUESTED_SERIES_INDEX)[0]));
123:
124: } else {
125: yvalues[0][0] = 0;
126: }
127: int i;
128:
129: for (i = 1; i < nValues; i++) {
130: if (invModel.getYSeries(0)[i] - tolerance <= 0) {
131: yvalues[INVENTORY_SHORTFALL_SERIES_INDEX][i] = ((reqModel
132: .getYSeries(ACTUAL_SERIES_INDEX)[i] - reqModel
133: .getYSeries(REQUESTED_SERIES_INDEX)[i])
134: + (projModel
135: .getRealYSeries(ACTUAL_SERIES_INDEX)[i] - projModel
136: .getRealYSeries(REQUESTED_SERIES_INDEX)[i]) + yvalues[INVENTORY_SHORTFALL_SERIES_INDEX][i - 1]);
137:
138: } else {
139: yvalues[INVENTORY_SHORTFALL_SERIES_INDEX][i] = 0;
140: }
141: if (yvalues[INVENTORY_SHORTFALL_SERIES_INDEX][i] < 0) {
142: shortfallExists = true;
143: logger.debug("Shortfall value point("
144: + xvalues[INVENTORY_SHORTFALL_SERIES_INDEX][i]
145: + "," + yvalues[0][i] + ")");
146: minShortfall = Math.min(minShortfall,
147: yvalues[INVENTORY_SHORTFALL_SERIES_INDEX][i]);
148: }
149: //get rid of negative shortfall
150: else if (yvalues[INVENTORY_SHORTFALL_SERIES_INDEX][i - 1] > 0) {
151: //yvalues[0][i-1] = 0;
152: }
153: }
154:
155: if ((nValues > 1)
156: && (yvalues[INVENTORY_SHORTFALL_SERIES_INDEX][nValues - 1] > 0)) {
157: yvalues[INVENTORY_SHORTFALL_SERIES_INDEX][nValues - 1] = 0;
158: }
159:
160: }
161:
162: public void setDisplayCDay(boolean doUseCDay) {
163: if (doUseCDay != useCDay) {
164: invModel.setDisplayCDay(doUseCDay);
165: super .setDisplayCDay(doUseCDay);
166: }
167: }
168:
169: public double getMinShortfall() {
170: return minShortfall;
171: }
172:
173: }
|