Source Code Cross Referenced for Satisfier.java in  » Scripting » Nice » mlsub » typing » lowlevel » 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 » Scripting » Nice » mlsub.typing.lowlevel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package mlsub.typing.lowlevel;
002:
003:        /**
004:         * A repository for static methods used during satisfiability test
005:         *
006:         * @author Alexandre Frey
007:         * @version $Revision: 1.5 $, $Date: 2005/04/01 12:12:05 $
008:         **/
009:        final class Satisfier {
010:            // not instantiable
011:            private Satisfier() {
012:            }
013:
014:            static int[] compileStrategy(BitMatrix C, BitMatrix Ct, int m, int n) {
015:                int[] strategy = new int[n - m];
016:                C.topologicalSort(m, strategy);
017:                return strategy;
018:            }
019:
020:            private static boolean satisfiable = false;
021:
022:            private static class Satisfiable extends Exception {
023:            }
024:
025:            private static Satisfiable sat = new Satisfiable();
026:
027:            private static void enumerate(int[] strategy, DomainVector domains,
028:                    BitMatrix C, BitMatrix Ct, BitMatrix R, BitMatrix Rt,
029:                    int m, int n, BitVector observers,
030:                    LowlevelSolutionHandler handler)
031:                    throws LowlevelUnsatisfiable, Satisfiable {
032:                domains.gfp(R, Rt, C, Ct, strategy);
033:                boolean isObserver = true;
034:                // try first the observers
035:                int x = domains.chooseDomain(observers);
036:                if (x < 0) {
037:                    isObserver = false;
038:                    // no more uninstantiated observers
039:                    x = domains.chooseDomain();
040:                    if (x < 0) {
041:                        // no more domains at all, the constraint has been satisfied
042:                        handler.handle(domains);
043:
044:                        // backtrack
045:                        throw sat;
046:                    }
047:                }
048:                Domain dx = new Domain(domains.getDomain(x));
049:                for (int a = dx.getLowestSetBit(); a >= 0; a = dx.getNextBit(a)) {
050:                    DomainVector domainsCopy = new DomainVector(domains);
051:                    try {
052:                        domainsCopy.getDomain(x).instantiate(a);
053:                        enumerate(strategy, domainsCopy, C, Ct, R, Rt, m, n,
054:                                observers, handler);
055:                    } catch (LowlevelUnsatisfiable e) {
056:                        // try another value
057:                    } catch (Satisfiable e) {
058:                        if (!isObserver) {
059:                            // ok, we found a solution and reported it
060:                            // no need to try another value for the non-observer x
061:                            throw e;
062:                        } else {
063:                            // try another value for the observer
064:                        }
065:                    }
066:                }
067:                throw LowlevelUnsatisfiable.instance;
068:            }
069:
070:            private static void enumerate(int[] strategy, DomainVector domains,
071:                    BitMatrix C, BitMatrix Ct, BitMatrix R, BitMatrix Rt,
072:                    int m, int n, LowlevelSolutionHandler handler)
073:                    throws LowlevelUnsatisfiable, Satisfiable {
074:                domains.gfp(R, Rt, C, Ct, strategy);
075:
076:                int x = domains.chooseDomain();
077:                if (x < 0) {
078:                    // no more domains to be instantiated: a solution has been found
079:                    satisfiable = true;
080:                    if (handler == null) {
081:                        throw sat;
082:                    }
083:                    handler.handle(domains);
084:                    throw LowlevelUnsatisfiable.instance;
085:                }
086:                Domain dx = new Domain(domains.getDomain(x));
087:                // iterate through the elements of dx
088:                for (int a = dx.getLowestSetBit(); a >= 0; a = dx.getNextBit(a)) {
089:                    DomainVector domainsCopy = new DomainVector(domains);
090:                    try {
091:                        domainsCopy.getDomain(x).instantiate(a);
092:                        enumerate(strategy, domainsCopy, C, Ct, R, Rt, m, n,
093:                                handler);
094:
095:                        // XXX: reachable ?
096:                        throw sat;
097:                    } catch (LowlevelUnsatisfiable _) {
098:                        // try another value
099:                    }
100:                }
101:                throw LowlevelUnsatisfiable.instance;
102:            }
103:
104:            static void enumerateSolutions(int[] strategy,
105:                    DomainVector domains, BitMatrix C, BitMatrix Ct,
106:                    BitMatrix R, BitMatrix Rt, int m, int n,
107:                    LowlevelSolutionHandler handler)
108:                    throws LowlevelUnsatisfiable {
109:                try {
110:                    satisfiable = false;
111:                    domains.initGfpCardinals();
112:                    enumerate(strategy, domains, C, Ct, R, Rt, m, n, handler);
113:                } catch (Satisfiable e) {
114:                } catch (LowlevelUnsatisfiable e) {
115:                    if (!satisfiable) {
116:                        throw e;
117:                    } else {
118:                        /* the exception was thrown to request for more solutions
119:                         * but there aren't any more
120:                         */
121:                    }
122:                }
123:            }
124:
125:            static void enumerateSolutions(int[] strategy,
126:                    DomainVector domains, BitMatrix C, BitMatrix Ct,
127:                    BitMatrix R, BitMatrix Rt, int m, int n,
128:                    BitVector observers, LowlevelSolutionHandler handler) {
129:                try {
130:                    domains.initGfpCardinals();
131:                    enumerate(strategy, domains, C, Ct, R, Rt, m, n, observers,
132:                            handler);
133:                } catch (Satisfiable e) {
134:                } catch (LowlevelUnsatisfiable e) {
135:                }
136:            }
137:
138:            static void satisfy(int[] strategy, DomainVector domains,
139:                    BitMatrix C, BitMatrix Ct, BitMatrix R, BitMatrix Rt,
140:                    int m, int n) throws LowlevelUnsatisfiable {
141:                try {
142:                    domains.initGfpCardinals();
143:                    enumerate(strategy, domains, C, Ct, R, Rt, m, n, null);
144:                } catch (Satisfiable e) {
145:                }
146:            }
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.