001: /* */
002: /*
003: * <copyright>
004: *
005: * Copyright 1997-2004 BBNT Solutions, LLC
006: * under sponsorship of the Defense Advanced Research Projects
007: * Agency (DARPA).
008: *
009: * You can redistribute this software and/or modify it under the
010: * terms of the Cougaar Open Source License as published on the
011: * Cougaar Open Source Website (www.cougaar.org).
012: *
013: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
014: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
015: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
016: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
017: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
018: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
019: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
020: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
021: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
022: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
023: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
024: *
025: * </copyright>
026: */
027:
028: package org.cougaar.glm.util;
029:
030: import java.util.Enumeration;
031:
032: import org.cougaar.glm.ldm.plan.GeolocLocation;
033: import org.cougaar.planning.ldm.plan.AspectLocation;
034: import org.cougaar.planning.ldm.plan.AspectScorePoint;
035: import org.cougaar.planning.ldm.plan.AspectType;
036: import org.cougaar.planning.ldm.plan.AspectValue;
037: import org.cougaar.planning.ldm.plan.ScoringFunction;
038: import org.cougaar.util.Empty;
039: import org.cougaar.util.log.Logger;
040:
041: /**
042: * Represents a location scoring function - score gets worse (higher or lower?)
043: * as straight-line distance from Lat, Lon increases.
044: * ?We'd like this to be part of the COUGAAR baseline...?
045: */
046:
047: public class GLMLocationScoringFunction extends
048: ScoringFunction.PreferredValueScoringFunction {
049: public static double EPSILON = 1.0d;
050:
051: /**
052: * Makes an AspectLocation, which I assume to have type AspectType.POD.
053: * (It's not clear anywhere that it should be anything else...)
054: *
055: * @see org.cougaar.planning.ldm.plan.AspectLocation
056: * @see org.cougaar.planning.ldm.plan.AspectType
057: */
058: public GLMLocationScoringFunction(GeolocLocation loc, Logger logger) {
059: super (AspectValue.newAspectValue(AspectType.POD, loc), 0);
060: // my_loc = loc;
061: measureHelper = new GLMMeasure(logger);
062: }
063:
064: /**
065: * This doesn't make any sense --- there is no way to represent this.
066: * Geolocs are two-tuples, and so don't map onto AspectValues, which
067: * are doubles.
068: *
069: * @param lowerbound (ignored)
070: * @param upperbound (ignored)
071: * @return Enumeration
072: */
073: public Enumeration getValidRanges(AspectValue lowerbound,
074: AspectValue upperbound) {
075: return Empty.enumeration;
076: }
077:
078: /**
079: * This doesn't make any sense --- there is no way to represent this.
080: * Geolocs are two-tuples, and so don't map onto AspectValues, which
081: * are doubles.
082: *
083: * @param lowerbound (ignored)
084: * @param upperbound (ignored)
085: * @return null
086: */
087: public AspectScorePoint getMinInRange(AspectValue lowerbound,
088: AspectValue upperbound) {
089: AspectScorePoint asp = null;
090: return asp;
091: }
092:
093: /**
094: * This doesn't make any sense --- there is no way to represent this.
095: * Geolocs are two-tuples, and so don't map onto AspectValues, which
096: * are doubles.
097: *
098: * @param lowerbound (ignored)
099: * @param upperbound (ignored)
100: * @return null
101: */
102: public AspectScorePoint getMaxInRange(AspectValue lowerbound,
103: AspectValue upperbound) {
104: AspectScorePoint asp = null;
105: return asp;
106: }
107:
108: /**
109: * The score is based on the distance between the two points in furlongs.
110: * There are many better measures, but this works for now.
111: *
112: * @return WORST if bad data only, though we should probably throw an exception
113: */
114: public double getScore(AspectValue av) {
115: if (!(av instanceof AspectLocation))
116: return ScoringFunction.WORST;
117:
118: AspectLocation av_loc = (AspectLocation) av;
119: GeolocLocation loc = (GeolocLocation) av_loc.getLocationValue();
120: GeolocLocation my_loc = getLocation();
121:
122: if (loc != null) {
123: if (loc.getLongitude() != null && loc.getLatitude() != null
124: && my_loc.getLongitude() != null
125: && my_loc.getLatitude() != null) {
126:
127: double score_as_distance = measureHelper
128: .distanceBetween(loc, my_loc).getFurlongs();
129: return score_as_distance;
130: }
131: }
132:
133: // drop through - WORST after last point.
134: return ScoringFunction.WORST;
135: }
136:
137: // Do we want to return a copy? i.e. a new instance?
138: // The dates used to be new instances of dates...
139: public GeolocLocation getLocation() {
140: AspectLocation al = (AspectLocation) getBest().getAspectValue();
141: return (GeolocLocation) al.getLocationValue();
142: }
143:
144: public static void main(String[] args) {
145: // PlanningFactory ldmf = getLDM().getFactory();
146:
147: // NewGeolocLocation new_gl = ldmf.newGeolocLocation();
148: // new_gl.setName("Ad Dammam, SA");
149: // new_gl.setGeolocCode("ABFL");
150: // new_gl.setLatitude(Latitude.newDegrees("26.43"));
151: // new_gl.setLongitude(Longitude.newDegrees("50.1"));
152:
153: // ScoringFunction sf = new GLMLocationScoringFunction (new_gl);
154: // setDebug (true);
155:
156: // AspectLocation a_loc = new AspectLocation (AspectType.POD,
157: // (double) beforeearly.getTime ());
158: // logger.isDebugEnabled() ("Score for before early " + sf.getScore (a_loc));
159:
160: // a_loc = new AspectLocation (AspectType.POD, (double) early.getTime ());
161: // logger.isDebugEnabled() ("Score for early " + sf.getScore (a_loc));
162:
163: //USE THIS ONE FIRST a_loc = new AspectLocation (AspectType.POD, new_gl);
164: // logger.isDebugEnabled() ("Score for best " + sf.getScore (a_loc));
165:
166: // a_loc = new AspectLocation (AspectType.POD, (double) late.getTime ());
167: // logger.isDebugEnabled() ("Score for late " + sf.getScore (a_loc));
168:
169: // a_loc = new AspectLocation (AspectType.POD, (double) afterlate.getTime ());
170: // logger.isDebugEnabled() ("Score for after late " + sf.getScore (a_loc));
171: }
172:
173: protected GLMMeasure measureHelper;
174: }
|