~libowen96/workcraft/trunk-son-entire

« back to all changes in this revision

Viewing changes to SONPlugin/src/org/workcraft/plugins/son/algorithm/EntireEstimationAlg.java

  • Committer: libowen96
  • Date: 2016-02-06 00:43:17 UTC
  • Revision ID: libowen96@hotmail.com-20160206004317-nny2happ5oa1w4cb
add backword entire DFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
                LinkedList<Time> visited = new LinkedList<Time>();
75
75
                visited.add(superIni);
76
76
                
 
77
                
77
78
                //assign specified value from connections to nodes
78
79
                for(SONConnection con : net.getSONConnections()){
79
80
                        if(con.getSemantics() == Semantics.PNLINE){
98
99
                        return;
99
100
                }
100
101
                
101
 
                //move estimated time to connections
 
102
                Condition superFinal = null;
 
103
                //super final
 
104
                if(twoDir){
 
105
                        superFinal = net.createCondition(null, null);
 
106
                        scenario.add(net.getNodeReference(superFinal));
 
107
                        
 
108
                        for(PlaceNode p : finalM){
 
109
                                try {
 
110
                                        SONConnection con = net.connect(p, superFinal, Semantics.PNLINE);
 
111
                                        scenario.add(net.getNodeReference(con));
 
112
                                } catch (InvalidConnectionException e) {
 
113
                                        e.printStackTrace();
 
114
                                }
 
115
                        }
 
116
                        
 
117
                        Interval start = null;
 
118
                        
 
119
                        try {
 
120
                                start = getEstimatedStartTime(superFinal);
 
121
                        }
 
122
                        catch (TimeEstimationException e){
 
123
                                net.remove(superFinal);
 
124
                                throw new TimeEstimationException("");
 
125
                        } catch (TimeOutOfBoundsException e){
 
126
                                net.remove(superFinal);
 
127
                                e.printStackTrace();
 
128
                                return;
 
129
                        }
 
130
                        
 
131
                        superFinal.setEndTime(start);
 
132
                        
 
133
                        try {
 
134
                                backwardDFSEntire(visited, scenario.getNodes(net), initial, finalM);
 
135
                        } catch (TimeOutOfBoundsException e) {
 
136
                                net.remove(superFinal);
 
137
                                e.printStackTrace();
 
138
                                return;
 
139
                        }
 
140
                }
 
141
                
 
142
                //assign estimated time value from nodes to connections
102
143
                for(SONConnection con : net.getSONConnections()){
103
144
                        if(con.getSemantics() == Semantics.PNLINE){
104
 
                                if(!con.getTime().isSpecified()){
105
 
                                        Node first = con.getFirst();
106
 
                                        if(first instanceof Time){
 
145
                                Node first = con.getFirst();
 
146
                                if(first instanceof Time){
 
147
                                if(narrow){
 
148
                                        con.setTime(((Time)first).getEndTime());
 
149
                                        con.setTimeLabelColor(color);
 
150
                                }
 
151
                                else{
 
152
                                        if((!con.getTime().isSpecified())){
107
153
                                                con.setTime(((Time)first).getEndTime());
108
154
                                                con.setTimeLabelColor(color);
 
155
                                                }
109
156
                                        }
110
157
                                }
111
158
                        }
122
169
                }       
123
170
                //remove super initial          
124
171
                net.remove(superIni);
 
172
                if(twoDir){
 
173
                        net.remove(superFinal);
 
174
                }
125
175
        }
126
176
        
 
177
    private void backwardDFSEntire(LinkedList<Time> visited, Collection<Node> nodes, Collection<PlaceNode> initial, Collection<PlaceNode> finalM) throws TimeOutOfBoundsException, TimeInconsistencyException  {
 
178
        Time last = visited.getLast();
 
179
        LinkedList<Time> neighbours = getCausalPreset(last, nodes);
 
180
        
 
181
        for(Time t : neighbours){
 
182
                if(!visited.contains(t)){
 
183
                        if(!t.getEndTime().isSpecified()){
 
184
                                t.setEndTime(last.getStartTime());
 
185
                                if(finalM.contains(t)){
 
186
                                        ((Condition)t).setEndTimeColor(color);
 
187
                                }
 
188
                        }else{
 
189
                                if(!t.getEndTime().isOverlapping(last.getStartTime()))
 
190
                                        throw new TimeInconsistencyException("Time inconsistency: "+net.getNodeReference(t));
 
191
                                if(narrow){
 
192
                                        t.setEndTime(Interval.getOverlapping(t.getEndTime(), last.getEndTime()));
 
193
                                }
 
194
                        }
 
195
                        if(!t.getDuration().isSpecified()){
 
196
                                t.setDuration(defaultDuration);
 
197
                                if(t instanceof PlaceNode){
 
198
                                        ((PlaceNode)t).setDurationColor(color);
 
199
                                }else if(t instanceof Block){
 
200
                                        ((Block)t).setDurationColor(color);
 
201
                                }
 
202
                        }
 
203
                        if(!t.getStartTime().isSpecified()){
 
204
                                Interval time = granularity.plusTD(t.getEndTime(), t.getDuration());
 
205
                                t.setStartTime(time);
 
206
                                if(initial.contains(t)){
 
207
                                        ((Condition)t).setStartTimeColor(color);
 
208
                                }
 
209
                        }else{
 
210
                                ArrayList<String> check= consistency.nodeConsistency(t, t.getStartTime(), t.getEndTime(), t.getDuration(), g);
 
211
                                if(!check.isEmpty())
 
212
                                        throw new TimeInconsistencyException("Time inconsistency: "+net.getNodeReference(t));
 
213
                                if(narrow){
 
214
                                        t.setStartTime(Interval.getOverlapping(t.getEndTime(), last.getEndTime()));
 
215
                                }
 
216
                        }
 
217
                        
 
218
                        visited.add(t);
 
219
                        backwardDFSEntire(visited, nodes, initial, finalM);
 
220
                }
 
221
        }
 
222
    }
 
223
    
127
224
    private void forwardDFSEntire(LinkedList<Time> visited, Collection<Node> nodes, Collection<PlaceNode> initial, Collection<PlaceNode> finalM) throws TimeOutOfBoundsException, TimeInconsistencyException  {
128
225
        Time last = visited.getLast();
129
226
        LinkedList<Time> neighbours = getCausalPostset(last, nodes);
136
233
                                        ((Condition)t).setStartTimeColor(color);
137
234
                                }
138
235
                        }else{
139
 
                                if(!t.getStartTime().equals(last.getEndTime()))
 
236
                                if(!t.getStartTime().isOverlapping(last.getEndTime()))
140
237
                                        throw new TimeInconsistencyException("Time inconsistency: "+net.getNodeReference(t));
141
238
                                if(narrow){
142
 
                                        System.out.println("narrow");
143
239
                                        t.setStartTime(Interval.getOverlapping(t.getStartTime(), last.getStartTime()));
144
240
                                }
145
241
                        }