Source Code Cross Referenced for DefaultPreferenceAggregator.java in  » Science » Cougaar12_4 » org » cougaar » glm » packer » 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.packer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 1999-2004 Honeywell Inc
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.glm.packer;
028:
029:        //utils
030:        import java.util.ArrayList;
031:        import java.util.Calendar;
032:        import java.util.Iterator;
033:
034:        import org.cougaar.planning.ldm.PlanningFactory;
035:        import org.cougaar.planning.ldm.plan.AspectType;
036:        import org.cougaar.planning.ldm.plan.AspectValue;
037:        import org.cougaar.planning.ldm.plan.Preference;
038:        import org.cougaar.planning.ldm.plan.ScoringFunction;
039:        import org.cougaar.planning.ldm.plan.Task;
040:
041:        /**
042:         * This is the PreferenceAggregator used by the packer created by
043:         * HTC.  The set of preferences it creates is set up to meet the
044:         * needs of the TOPS MCCGlobalMode cluster that will be receiving
045:         * the tasks the packer creates.
046:         */
047:        public class DefaultPreferenceAggregator implements 
048:                PreferenceAggregator {
049:            // Start time is set to 40 days prior to the specified end time
050:            private static long MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
051:            private static long START_DECREMENT = 40 * MILLIS_PER_DAY;
052:
053:            /* Increments added to specified end time to come up with an earliest, 
054:             * best, and latest for TOPS. Distribution specified by
055:             * tops team
056:             */
057:            private static long EARLIEST_INCREMENT = -(21 * MILLIS_PER_DAY);
058:            private static long BEST_INCREMENT = 0 * MILLIS_PER_DAY;
059:            private static long LATEST_INCREMENT = 0 * MILLIS_PER_DAY;
060:
061:            private Calendar myCalendar = Calendar.getInstance();
062:
063:            /**
064:             * Will create a preference as follows:
065:             * START_TIME should be at or greater than 0.0
066:             * END_TIME should be bracketed around the earliest END_TIME of
067:             * the input tasks and
068:             * QUANTITY should be set at the sum of the quantities of the
069:             * input tasks.
070:             */
071:            public ArrayList aggregatePreferences(Iterator tasks,
072:                    PlanningFactory rootFactory) {
073:
074:                ArrayList prefs = new ArrayList();
075:                double endTime = java.lang.Double.POSITIVE_INFINITY;
076:                double startTime = 0.0;
077:                double quantity = 0.0;
078:
079:                // find values for endTime and quantity
080:                while (tasks.hasNext()) {
081:                    Task t = (Task) tasks.next();
082:
083:                    // replaced min with this CWG
084:                    if (t.getPreferredValue(AspectType.END_TIME) < endTime) {
085:                        endTime = t.getPreferredValue(AspectType.END_TIME);
086:                    }
087:
088:                    // replaced min with this CWG
089:                    if (t.getPreferredValue(AspectType.START_TIME) > startTime) {
090:                        startTime = t.getPreferredValue(AspectType.START_TIME);
091:                    }
092:                    quantity += t.getPreferredValue(AspectType.QUANTITY);
093:                }
094:
095:                // make the START_TIME preference
096:                // this is a placeholder for more faithful logic later...
097:                // [1999/11/15:goldman]
098:                //
099:                // MSB 1-25-2000 : Make Start time 40 days before end_time
100:                startTime = endTime - START_DECREMENT;
101:
102:                prefs.add(makeStartPreference(startTime, rootFactory));
103:
104:                // make the endTime preference...
105:                prefs.add(makeEndPreference(endTime, rootFactory));
106:
107:                prefs.add(makeQuantityPreference(quantity, rootFactory));
108:                return prefs;
109:            }
110:
111:            // Added the rootFactory argument.  Seemed to need it to make the pref. CGW
112:            private Preference makeQuantityPreference(double amount,
113:                    PlanningFactory rootFactory) {
114:                AspectValue av = AspectValue.newAspectValue(
115:                        AspectType.QUANTITY, amount);
116:                ScoringFunction sf = ScoringFunction.createNearOrBelow(av, 0.1);
117:                Preference pref = rootFactory.newPreference(
118:                        AspectType.QUANTITY, sf);
119:                return pref;
120:            }
121:
122:            private Preference makeStartPreference(double startDate,
123:                    PlanningFactory rootFactory) {
124:                AspectValue startTime = AspectValue.newAspectValue(
125:                        AspectType.START_TIME, startDate);
126:                ScoringFunction sf = ScoringFunction.createNearOrAbove(
127:                        startTime, 0.0);
128:                Preference pref = rootFactory.newPreference(
129:                        AspectType.START_TIME, sf);
130:                return pref;
131:            }
132:
133:            /**
134:             * makeEndPreference -
135:             * separate earliest, best, and latest for TOPS. Picked 1 day out
136:             * of the blue (with help from Gordon
137:             */
138:            private Preference makeEndPreference(double endDate,
139:                    PlanningFactory rootFactory) {
140:
141:                AspectValue earliest = AspectValue.newAspectValue(
142:                        AspectType.END_TIME, endDate + EARLIEST_INCREMENT);
143:
144:                AspectValue best = AspectValue.newAspectValue(
145:                        AspectType.END_TIME, endDate + BEST_INCREMENT);
146:
147:                AspectValue latest = AspectValue.newAspectValue(
148:                        AspectType.END_TIME, endDate + LATEST_INCREMENT);
149:
150:                ScoringFunction sf = ScoringFunction.createVScoringFunction(
151:                        earliest, best, latest);
152:                Preference pref = rootFactory.newPreference(
153:                        AspectType.END_TIME, sf);
154:                return pref;
155:            }
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.