Source Code Cross Referenced for GLMPreference.java in  » Science » Cougaar12_4 » org » cougaar » glm » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.glm.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.Date;
031:
032:        import org.cougaar.glm.ldm.plan.GeolocLocation;
033:        import org.cougaar.lib.util.UTILPluginException;
034:        import org.cougaar.lib.util.UTILPreference;
035:        import org.cougaar.planning.ldm.PlanningFactory;
036:        import org.cougaar.planning.ldm.plan.AllocationResult;
037:        import org.cougaar.planning.ldm.plan.AspectLocation;
038:        import org.cougaar.planning.ldm.plan.AspectType;
039:        import org.cougaar.planning.ldm.plan.AspectValue;
040:        import org.cougaar.planning.ldm.plan.PlanElement;
041:        import org.cougaar.planning.ldm.plan.Preference;
042:        import org.cougaar.planning.ldm.plan.ScoringFunction;
043:        import org.cougaar.planning.ldm.plan.Task;
044:        import org.cougaar.util.log.Logger;
045:
046:        /** 
047:         * This class contains preference-related methods.
048:         * Can ask basic questions like ready at, early, best, and latest date for
049:         * tasks.
050:         *
051:         * Can also create an various kinds of preferences.
052:         */
053:
054:        public class GLMPreference extends UTILPreference {
055:            private static String myName = "GLMPreference";
056:            private static double ONE_DAY = 1000 * 60 * 60 * 24; // millis
057:            private static double ONE_OVER_ONE_DAY = 1.0d / ONE_DAY; // millis
058:            private static double fiftyYears = ONE_DAY * 365 * 50; // millis
059:            private static double boundaryDefaultScore = 0.75;
060:
061:            public GLMPreference(Logger l) {
062:                super (l);
063:            }
064:
065:            /**
066:             * Make a POD preference.
067:             *
068:             * Score increases as distance from best location increases...
069:             * 
070:             * This needs work...
071:             *
072:             * What should we do with the weight of the preference?
073:             * Should this be set by a policy object?
074:             */
075:            public Preference makePODPreference(PlanningFactory ldmf,
076:                    GeolocLocation loc) {
077:                GLMLocationScoringFunction podSF = new GLMLocationScoringFunction(
078:                        loc, logger);
079:                Preference podPref = ldmf.newPreference(AspectType.POD, podSF,
080:                        1.0);
081:                return podPref;
082:            }
083:
084:            /**
085:             * What should we do with the weight of the preference?
086:             * Should this be set by a policy object?
087:             *
088:             * Note that it uses one day as the slope -- i.e.
089:             * a day after the POD date, the pref is exceeded.
090:             */
091:            public Preference makePODDatePreference(PlanningFactory ldmf,
092:                    Date bestDate) {
093:                if (bestDate == null || bestDate.before(new Date(1000))) {
094:                    System.err
095:                            .println("GLMPreference creating bad POD_Date preference: the date is "
096:                                    + bestDate);
097:                }
098:                AspectValue podAV = AspectValue.newAspectValue(
099:                        AspectType.POD_DATE, bestDate.getTime());
100:                ScoringFunction podSF = ScoringFunction.createPreferredAtValue(
101:                        podAV, ONE_OVER_ONE_DAY);
102:                Preference podPref = ldmf.newPreference(AspectType.POD_DATE,
103:                        podSF, 1.0);
104:                return podPref;
105:            }
106:
107:            /**
108:             * Returns the POD Date from task object, null if POD date not a pref on this task
109:             *
110:             * @param  t - the Task with the pref
111:             * @return Date point of departure date for task, null if no POD date pref
112:             */
113:
114:            public Date getPODDate(Task t) {
115:                Preference pod_pref = getPrefWithAspectType(t,
116:                        AspectType.POD_DATE);
117:                if (pod_pref == null)
118:                    return null;
119:
120:                Date pod_date = new Date((long) (pod_pref.getScoringFunction()
121:                        .getBest().getValue()));
122:
123:                return pod_date;
124:            }
125:
126:            /**
127:             * Get reported POD date from plan element
128:             */
129:            public Date getReportedPODDate(PlanElement pe) {
130:                return getReportedPODDate(pe.getReportedResult());
131:            }
132:
133:            /**
134:             * Get reported POD date from allocation result
135:             */
136:            public Date getReportedPODDate(AllocationResult result) {
137:                double value = result.getValue(AspectType.POD_DATE);
138:                if (value != NO_ASPECT_VALUE)
139:                    return new Date((long) value);
140:                return null;
141:            }
142:
143:            /**
144:             * Returns the POD location from task object, null if POD not a pref on this task
145:             *
146:             * @param  t - the Task with the pref
147:             * @return Date point of departure for task, null if no POD pref
148:             */
149:
150:            public GeolocLocation getPODLocation(Task t) {
151:                Preference pod_pref = getPrefWithAspectType(t, AspectType.POD);
152:                if (pod_pref == null)
153:                    return null;
154:
155:                GeolocLocation geoloc = ((GLMLocationScoringFunction) pod_pref
156:                        .getScoringFunction()).getLocation();
157:
158:                return geoloc;
159:            }
160:
161:            /**
162:             * Get reported POD location from plan element
163:             */
164:            public GeolocLocation getReportedPODLocation(PlanElement pe) {
165:                return getReportedPODLocation(pe.getReportedResult());
166:            }
167:
168:            /**
169:             * Get reported POD location from allocation result
170:             */
171:            public GeolocLocation getReportedPODLocation(AllocationResult result) {
172:                if (result == null)
173:                    return null;
174:
175:                Object aspectValue = null;
176:                AspectValue[] results = result.getAspectValueResults();
177:
178:                try {
179:                    for (int i = 0; i < results.length; i++) {
180:                        if (results[i].getAspectType() == AspectType.POD) {
181:                            aspectValue = results[i];
182:                            AspectLocation loc = (AspectLocation) aspectValue;
183:                            return (GeolocLocation) loc.getLocationValue();
184:                        }
185:                    }
186:                } catch (ClassCastException cce) {
187:                    throw new UTILPluginException(
188:                            classname
189:                                    + ".getReportedPODLocation - expecting an AspectLocation as POD aspect value. "
190:                                    + "\nInstead got " + aspectValue.getClass());
191:                }
192:
193:                return null;
194:            }
195:
196:            private static final String classname = GLMPreference.class
197:                    .getName();
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.