001: /*--------------------------------------------------------------------------
002: * <copyright>
003: *
004: * Copyright 1999-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: package org.cougaar.glm.plugins.inventory;
027:
028: import org.cougaar.planning.ldm.policy.BooleanRuleParameter;
029: import org.cougaar.planning.ldm.policy.DoubleRuleParameter;
030: import org.cougaar.planning.ldm.policy.IntegerRuleParameter;
031: import org.cougaar.planning.ldm.policy.Policy;
032: import org.cougaar.planning.ldm.policy.RuleParameterIllegalValueException;
033: import org.cougaar.planning.ldm.policy.StringRuleParameter;
034:
035: /**
036: * The PolicyPlugin
037: *
038: *
039: */
040:
041: public class InventoryPolicy extends Policy {
042: public static final String ResourceType = "ResourceType";
043: public static final String DaysOnHand = "DaysOnHand";
044: public static final String DaysForward = "DaysForward";
045: public static final String DaysBackward = "DaysBackward";
046: public static final String GoalLevelMultiplier = "GoalLevelMultiplier";
047: public static final String WithdrawSwitchoverDay = "WithdrawSwitchoverDay";
048: public static final String RefillSwitchoverDay = "RefillSwitchoverDay";
049: public static final String TurnOffProjections = "TurnOffProjections";
050: public static final String FillToCapacity = "FillToCapacity";
051: public static final String MaintainAtCapacity = "MaintainAtCapacity";
052:
053: public InventoryPolicy() {
054: super ("DaysOnHandPolicy");
055: StringRuleParameter ic = new StringRuleParameter(ResourceType);
056: try {
057: ic.setValue(new String());
058: } catch (RuleParameterIllegalValueException ex) {
059: System.out.println(ex);
060: }
061: Add(ic);
062:
063: IntegerRuleParameter dbd = new IntegerRuleParameter(DaysOnHand,
064: 0, 40);
065: try {
066: dbd.setValue(new Integer(1));
067: } catch (RuleParameterIllegalValueException ex) {
068: System.out.println(ex);
069: }
070: Add(dbd);
071:
072: IntegerRuleParameter frp = new IntegerRuleParameter(
073: DaysForward, 0, 40);
074: try {
075: frp.setValue(new Integer(15));
076: } catch (RuleParameterIllegalValueException ex) {
077: System.out.println(ex);
078: }
079: Add(frp);
080:
081: IntegerRuleParameter brp = new IntegerRuleParameter(
082: DaysBackward, 0, 40);
083: try {
084: brp.setValue(new Integer(15));
085: } catch (RuleParameterIllegalValueException ex) {
086: System.out.println(ex);
087: }
088: Add(brp);
089:
090: DoubleRuleParameter drp = new DoubleRuleParameter(
091: GoalLevelMultiplier, 1.0, 30.0);
092: try {
093: drp.setValue(new Double(2.0));
094: } catch (RuleParameterIllegalValueException ex) {
095: System.out.println(ex);
096: }
097: Add(drp);
098: }
099:
100: public String getResourceType() {
101: StringRuleParameter param = (StringRuleParameter) Lookup(ResourceType);
102: return (String) param.getValue();
103: }
104:
105: public void setResourceType(String name) {
106: StringRuleParameter param = (StringRuleParameter) Lookup(ResourceType);
107: try {
108: param.setValue(name);
109: } catch (RuleParameterIllegalValueException ex) {
110: System.out.println(ex);
111: }
112: }
113:
114: public int getDaysOnHand() {
115: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(DaysOnHand);
116: return ((Integer) (param.getValue())).intValue();
117: }
118:
119: public void setDaysBetweenDemand(int days) {
120: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(DaysOnHand);
121: try {
122: param.setValue(new Integer(days));
123: } catch (RuleParameterIllegalValueException ex) {
124: System.out.println(ex);
125: }
126: }
127:
128: public int getDaysForward() {
129: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(DaysForward);
130: return ((Integer) (param.getValue())).intValue();
131: }
132:
133: public void setDaysForward(int days) {
134: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(DaysForward);
135: try {
136: param.setValue(new Integer(days));
137: } catch (RuleParameterIllegalValueException ex) {
138: System.out.println(ex);
139: }
140: }
141:
142: public int getDaysBackward() {
143: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(DaysBackward);
144: return ((Integer) (param.getValue())).intValue();
145: }
146:
147: public void setDaysBackward(int days) {
148: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(DaysBackward);
149: try {
150: param.setValue(new Integer(days));
151: } catch (RuleParameterIllegalValueException ex) {
152: System.out.println(ex);
153: }
154: }
155:
156: public int getWindowSize() {
157: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(DaysForward);
158: int forward = ((Integer) (param.getValue())).intValue();
159: param = (IntegerRuleParameter) Lookup(DaysBackward);
160: int backward = ((Integer) (param.getValue())).intValue();
161: return forward + backward;
162: }
163:
164: public double getGoalLevelMultiplier() {
165: DoubleRuleParameter param = (DoubleRuleParameter) Lookup(GoalLevelMultiplier);
166: return ((Double) (param.getValue())).doubleValue();
167: }
168:
169: public void setGoalLevelMultiplier(double multiplier) {
170: DoubleRuleParameter param = (DoubleRuleParameter) Lookup(GoalLevelMultiplier);
171: try {
172: param.setValue(new Double(multiplier));
173: } catch (RuleParameterIllegalValueException ex) {
174: System.out.println(ex);
175: }
176: }
177:
178: public boolean getFillToCapacity() {
179: BooleanRuleParameter param = (BooleanRuleParameter) Lookup(FillToCapacity);
180: return ((Boolean) (param.getValue())).booleanValue();
181: }
182:
183: public void setFillToCapacity(boolean fill_to_capacity) {
184: BooleanRuleParameter param = (BooleanRuleParameter) Lookup(FillToCapacity);
185: try {
186: param.setValue(new Boolean(fill_to_capacity));
187: } catch (RuleParameterIllegalValueException ex) {
188: System.out.println(ex);
189: }
190: }
191:
192: public boolean hasFillToCapacityRule() {
193: return Lookup(FillToCapacity) != null;
194: }
195:
196: public boolean getMaintainAtCapacity() {
197: BooleanRuleParameter param = (BooleanRuleParameter) Lookup(MaintainAtCapacity);
198: return ((Boolean) (param.getValue())).booleanValue();
199: }
200:
201: public void setMaintainAtCapacity(boolean fill_to_capacity) {
202: BooleanRuleParameter param = (BooleanRuleParameter) Lookup(MaintainAtCapacity);
203: try {
204: param.setValue(new Boolean(fill_to_capacity));
205: } catch (RuleParameterIllegalValueException ex) {
206: System.out.println(ex);
207: }
208: }
209:
210: public boolean hasMaintainAtCapacityRule() {
211: return Lookup(MaintainAtCapacity) != null;
212: }
213:
214: public boolean hasSwitchoverRule() {
215: return Lookup(WithdrawSwitchoverDay) != null
216: && Lookup(RefillSwitchoverDay) != null
217: || Lookup(TurnOffProjections) != null;
218: }
219:
220: public int getWithdrawSwitchoverDay() {
221: if (getTurnOffProjections()) {
222: return Integer.MAX_VALUE;
223: } else {
224: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(WithdrawSwitchoverDay);
225: return param.intValue();
226: }
227: }
228:
229: public int getRefillSwitchoverDay() {
230: if (getTurnOffProjections()) {
231: return Integer.MAX_VALUE;
232: } else {
233: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(RefillSwitchoverDay);
234: return param.intValue();
235: }
236: }
237:
238: public boolean getTurnOffProjections() {
239: BooleanRuleParameter param = (BooleanRuleParameter) Lookup(TurnOffProjections);
240: if (param == null)
241: return false;
242: return param.getValue().equals(Boolean.TRUE);
243: }
244: }
|