Source Code Cross Referenced for AllocatorHelper.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:         * <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.glm.util;
028:
029:        import java.util.Enumeration;
030:        import java.util.Vector;
031:
032:        import org.cougaar.core.blackboard.CollectionSubscription;
033:        import org.cougaar.core.blackboard.IncrementalSubscription;
034:        import org.cougaar.planning.ldm.PlanningFactory;
035:        import org.cougaar.planning.ldm.asset.AbstractAsset;
036:        import org.cougaar.planning.ldm.plan.AllocationResult;
037:        import org.cougaar.planning.ldm.plan.AspectScorePoint;
038:        import org.cougaar.planning.ldm.plan.PlanElement;
039:        import org.cougaar.planning.ldm.plan.Preference;
040:        import org.cougaar.planning.ldm.plan.PrepositionalPhrase;
041:        import org.cougaar.planning.ldm.plan.ScoringFunction;
042:        import org.cougaar.planning.ldm.plan.Task;
043:
044:        /**
045:         * Helper class for building Allocator Plugins.
046:         */
047:        public class AllocatorHelper extends
048:                org.cougaar.planning.plugin.util.AllocatorHelper {
049:
050:            /**
051:             * UpdatePV looks for differences between the reported and 
052:             * estimated allocation results. If they are
053:             * different then the estimated value is set to the reported
054:             * value in both the cases.
055:             */
056:            public static void updatePV(PlanElement pe,
057:                    CollectionSubscription sub) {
058:
059:                if (pe.getReportedResult() != null) {
060:                    //compare the result objects.
061:                    // If they are NOT ==, re-set the estimated result.
062:                    // For now ignore whether their compositions are equal.
063:                    AllocationResult repar = pe.getReportedResult();
064:                    AllocationResult estar = pe.getEstimatedResult();
065:                    if ((estar == null) || (!(repar == estar))) {
066:                        pe.setEstimatedResult(repar);
067:                        sub.getSubscriber().publishChange(pe);
068:                    }
069:                }
070:            }
071:
072:            /** Takes a subscription, gets the changed list and updates the changedList.*/
073:            public static void updateAllocationResult(
074:                    IncrementalSubscription sub) {
075:
076:                Enumeration changedPEs = sub.getChangedList();
077:                while (changedPEs.hasMoreElements()) {
078:                    PlanElement pe = (PlanElement) changedPEs.nextElement();
079:                    if (pe.getReportedResult() != null) {
080:                        //compare entire pv arrays
081:                        AllocationResult repar = pe.getReportedResult();
082:                        AllocationResult estar = pe.getEstimatedResult();
083:                        if ((estar == null) || (!repar.isEqual(estar))) {
084:                            pe.setEstimatedResult(repar);
085:                            sub.getSubscriber().publishChange(pe);
086:                        }
087:                    }
088:                }
089:            }
090:
091:            /**
092:             * Checks if the Task is of specified OFTYPE.
093:             */
094:            public static boolean isOfType(Task t, String p, String typeid) {
095:                Enumeration prepPhrases = ((Task) t).getPrepositionalPhrases();
096:                PrepositionalPhrase pPhrase;
097:                String prep;
098:                AbstractAsset aa = null;
099:                String mytypeid = null;
100:
101:                while (prepPhrases.hasMoreElements()) {
102:                    pPhrase = (PrepositionalPhrase) prepPhrases.nextElement();
103:                    prep = pPhrase.getPreposition();
104:                    if (prep.equals(p)) {
105:                        Object indirectobj = pPhrase.getIndirectObject();
106:                        if (indirectobj instanceof  AbstractAsset) {
107:                            aa = (AbstractAsset) indirectobj;
108:                            mytypeid = aa.getTypeIdentificationPG()
109:                                    .getTypeIdentification();
110:                            if (mytypeid.equals(typeid))
111:                                return true;
112:                        }
113:                    }
114:                }
115:                return false;
116:            }
117:
118:            public static AllocationResult createEstimatedAllocationResult(
119:                    Task t, PlanningFactory ldmf) {
120:                Enumeration preferences = t.getPreferences();
121:                if (preferences != null && preferences.hasMoreElements()) {
122:                    // do something really simple for now.
123:                    Vector aspects = new Vector();
124:                    Vector results = new Vector();
125:                    while (preferences.hasMoreElements()) {
126:                        Preference pref = (Preference) preferences
127:                                .nextElement();
128:                        int at = pref.getAspectType();
129:                        aspects.addElement(new Integer(at));
130:                        ScoringFunction sf = pref.getScoringFunction();
131:                        // allocate as if you can do it at the "Best" point
132:                        double myresult = ((AspectScorePoint) sf.getBest())
133:                                .getValue();
134:                        results.addElement(new Double(myresult));
135:                    }
136:                    int[] aspectarray = new int[aspects.size()];
137:                    double[] resultsarray = new double[results.size()];
138:                    for (int i = 0; i < aspectarray.length; i++)
139:                        aspectarray[i] = (int) ((Integer) aspects.elementAt(i))
140:                                .intValue();
141:                    for (int j = 0; j < resultsarray.length; j++)
142:                        resultsarray[j] = (double) ((Double) results
143:                                .elementAt(j)).doubleValue();
144:
145:                    AllocationResult myestimate = ldmf.newAllocationResult(0.0,
146:                            true, aspectarray, resultsarray);
147:                    return myestimate;
148:                }
149:                // if there were no preferences...return a null estimate for the allocation result (for now)
150:                return null;
151:            }
152:
153:            /*
154:              public static void allocateToIndirectObjects ( Workflow wf, PlanningFactory ldmf, Subscriber mySubscriber ) {
155:            Asset a = null;
156:            Enumeration tasks = wf.getTasks();
157:            while ( tasks.hasMoreElements()) {
158:                Task t = (Task) tasks.nextElement();
159:                AllocationResult estimatedresult = createEstimatedAllocationResult(t, ldmf);
160:                Enumeration pp = t.getPrepositionalPhrases();
161:                while (pp.hasMoreElements()) {
162:            	PrepositionalPhrase p = (PrepositionalPhrase) pp.nextElement();
163:            	if (p.getPreposition().equals(Preposition.FOR)) {
164:            	    Object indir = p.getIndirectObject();
165:            	    if ( indir instanceof Organization) {
166:            		a = (Asset) indir;
167:            		Allocation alloc = ldmf.createAllocation(ldmf.getRealityPlan(), t, a, estimatedresult, Role.BOGUS);
168:            		mySubscriber.publishAdd(alloc);
169:            	    }
170:            	}
171:                }
172:            }
173:              }
174:             */
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.