[e7de6cc] | 1 | #include "dgp0.hh" |
---|
| 2 | #include "global.hh" |
---|
| 3 | |
---|
| 4 | extern Grammar grammar; |
---|
| 5 | extern MGraph mgraph; |
---|
| 6 | extern SGraph sgraph; |
---|
| 7 | |
---|
| 8 | extern bool debug; |
---|
| 9 | |
---|
| 10 | list<int> nodelist; |
---|
| 11 | list<int>::iterator processed; |
---|
| 12 | |
---|
[3b02b04] | 13 | |
---|
| 14 | void print_sets(int n); |
---|
| 15 | |
---|
| 16 | |
---|
[e7de6cc] | 17 | //==================================================================================================== |
---|
| 18 | |
---|
| 19 | void set_initial_constraints(int node) |
---|
| 20 | { |
---|
| 21 | sgraph[node].prop.forbidden.reset(); |
---|
| 22 | sgraph[node].prop.required=grammar.is_obl(sgraph.cat(node)); |
---|
| 23 | sgraph[node].prop.attached.reset(); |
---|
| 24 | sgraph[node].prop.flags=grammar.initial_flags(sgraph.cat(node)); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | //---------------------------------------------------------------------------------------------------- |
---|
| 28 | |
---|
| 29 | bool changing_constraints(int head, Role role) |
---|
| 30 | { |
---|
| 31 | return grammar.is_sgl(role) || sgraph[head].prop.required[role]; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | //==================================================================================================== |
---|
| 35 | |
---|
| 36 | NodeProp compute_head_prop(NodeProp headprop, const Link& link, list<Boubble*> bs, FlagSet& depflags) |
---|
| 37 | { |
---|
| 38 | NodeProp ret=headprop; |
---|
| 39 | |
---|
| 40 | if(grammar.is_sgl(link.role)) |
---|
| 41 | { |
---|
| 42 | ret.forbidden.set(link.role); |
---|
| 43 | ret.attached.set(link.role); |
---|
| 44 | } |
---|
| 45 | ret.required.reset(link.role); |
---|
| 46 | |
---|
| 47 | ret.required |= (grammar.constr_include(link.role) & ~ret.attached); |
---|
| 48 | ret.forbidden |= grammar.constr_exclude(link.role); |
---|
| 49 | |
---|
[3b02b04] | 50 | ret.boubbles.merge(bs); //DOBRZE |
---|
[e7de6cc] | 51 | ret.flags |= ( depflags & grammar.pass_flags(link.role) ); |
---|
| 52 | |
---|
| 53 | if(link.props[Prop("INIT")]) ret.init_attached=true; |
---|
| 54 | if(link.props[Prop("FIN")]) ret.fin_attached=true; |
---|
| 55 | |
---|
| 56 | return ret; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | //---------------------------------------------------------------------------------------------------- |
---|
| 60 | |
---|
| 61 | NodeProp compute_dep_prop(NodeProp depprop, const Link& link, list<Boubble*> bs) |
---|
| 62 | { |
---|
| 63 | NodeProp ret=depprop; |
---|
[3b02b04] | 64 | ret.boubbles.merge(bs); //DOBRZE |
---|
[e7de6cc] | 65 | return ret; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | //==================================================================================================== |
---|
| 69 | |
---|
| 70 | int find_existing_node(int mnodeind, NodeProp p, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLV) |
---|
| 71 | { |
---|
| 72 | MNode& mnode = mgraph[mnodeind]; |
---|
[3b02b04] | 73 | int ret=-1; |
---|
[e7de6cc] | 74 | for(vector<int>::iterator ps=mnode.snodes.begin(); ps!=mnode.snodes.end(); ++ps) |
---|
[3b02b04] | 75 | { |
---|
| 76 | if(debug) fprintf(stderr,"#find existing node: checking %d ... \n", *ps); |
---|
| 77 | if(sgraph[*ps].prop==p) |
---|
| 78 | if(sgraph[*ps].LH==newheadLH && sgraph[*ps].LV==newheadLV) |
---|
| 79 | { |
---|
| 80 | ret = *ps; |
---|
| 81 | // fprintf(stderr,"FIND EXISTING NODE SUCCEEDED BEACAUSE OF LH/LV equality ()\n"); |
---|
| 82 | } |
---|
| 83 | else |
---|
| 84 | { |
---|
| 85 | // fprintf(stderr,"FIND EXISTING NODE FAILED BEACAUSE OF LH/LV inequality\n"); |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | if(debug) fprintf(stderr,"\n"); |
---|
| 90 | return ret; |
---|
[e7de6cc] | 91 | } |
---|
| 92 | |
---|
| 93 | //==================================================================================================== |
---|
| 94 | |
---|
| 95 | list<Boubble*> receive_boubbles(int node, Role role, Dir dir) |
---|
| 96 | { |
---|
| 97 | list<Boubble*> ret; |
---|
| 98 | for(list<Boubble*>::iterator b = sgraph[node].prop.boubbles.begin(); b!=sgraph[node].prop.boubbles.end(); b++) |
---|
| 99 | { |
---|
| 100 | Boubble* new_boubble = (*b)->step(role,dir); |
---|
| 101 | if(new_boubble) |
---|
| 102 | ret.push_back(new_boubble); |
---|
| 103 | } |
---|
[3b02b04] | 104 | |
---|
[e7de6cc] | 105 | return ret; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | //---------------------------------------------------------------------------------------------------- |
---|
| 109 | |
---|
| 110 | list<Boubble*> collect_head_boubbles(int head, int dep, Role role) |
---|
| 111 | { |
---|
| 112 | list<Boubble*> new_boubbles = grammar.trigger_boubbles(sgraph.cat(dep),role,UP); |
---|
| 113 | |
---|
| 114 | for(list<Boubble*>::iterator b = new_boubbles.begin(); b != new_boubbles.end(); b++) |
---|
| 115 | (*b)->src(dep); |
---|
| 116 | |
---|
| 117 | list<Boubble*> received_boubbles = receive_boubbles(dep,role,UP); |
---|
| 118 | |
---|
| 119 | new_boubbles.insert(new_boubbles.begin(),received_boubbles.begin(),received_boubbles.end()); |
---|
| 120 | |
---|
| 121 | return new_boubbles; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | //---------------------------------------------------------------------------------------------------- |
---|
| 125 | |
---|
| 126 | list<Boubble*> collect_dep_boubbles(int head, int dep, Role role) |
---|
| 127 | { |
---|
| 128 | list<Boubble*> new_boubbles = grammar.trigger_boubbles(sgraph.cat(head), role, DOWN); |
---|
| 129 | |
---|
| 130 | for(list<Boubble*>::iterator b = new_boubbles.begin(); b != new_boubbles.end(); b++) |
---|
| 131 | (*b)->src(head); |
---|
| 132 | |
---|
| 133 | list<Boubble*> received_boubbles = receive_boubbles(head,role,DOWN); |
---|
| 134 | |
---|
| 135 | new_boubbles.insert(new_boubbles.begin(),received_boubbles.begin(),received_boubbles.end()); |
---|
| 136 | |
---|
| 137 | return new_boubbles; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | //==================================================================================================== |
---|
| 141 | |
---|
[3b02b04] | 142 | void copy_links(int i, int j) |
---|
[e7de6cc] | 143 | { |
---|
[3b02b04] | 144 | sgraph[j].heads = sgraph[i].heads; |
---|
| 145 | sgraph[j].deps = sgraph[i].deps; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | void create_reverse_links(int n) |
---|
| 150 | { |
---|
| 151 | for(vector<Arc>::iterator a=sgraph[n].heads.begin(); a != sgraph[n].heads.end(); a++) |
---|
| 152 | sgraph[a->dst].deps.push_back(Arc(n,a->role,a->headanc,a->depanc)); |
---|
| 153 | |
---|
| 154 | for(vector<Arc>::iterator a=sgraph[n].deps.begin(); a != sgraph[n].deps.end(); a++) |
---|
| 155 | sgraph[a->dst].heads.push_back(Arc(n,a->role,a->headanc,a->depanc)); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | //==================================================================================================== |
---|
| 159 | |
---|
| 160 | int create_new_head_node_left(int h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV) |
---|
| 161 | { |
---|
| 162 | int newheadind = sgraph.clone(h,newheadprop); |
---|
| 163 | // list<int>::iterator nextit=h; ++nextit; |
---|
| 164 | // nodelist.insert(nextit,newheadind); |
---|
| 165 | nodelist.push_back(newheadind); |
---|
[e7de6cc] | 166 | sgraph[newheadind].LH=newheadLH; |
---|
| 167 | sgraph[newheadind].LD = newheadLD; |
---|
| 168 | sgraph[newheadind].in_LH=true; |
---|
| 169 | sgraph[newheadind].LV.reset(); |
---|
[3b02b04] | 170 | |
---|
| 171 | copy_links(h,newheadind); |
---|
| 172 | create_reverse_links(newheadind); |
---|
[e7de6cc] | 173 | |
---|
[3b02b04] | 174 | if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,h); |
---|
[b97a556] | 175 | // if(debug) print_sets(newheadind); |
---|
[e7de6cc] | 176 | return newheadind; |
---|
| 177 | } |
---|
| 178 | |
---|
[3b02b04] | 179 | int create_new_dep_node_left(int d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV) |
---|
[e7de6cc] | 180 | { |
---|
[3b02b04] | 181 | int newind = sgraph.clone(d,prop); |
---|
| 182 | // list<int>::iterator nextit=d; ++nextit; |
---|
| 183 | // nodelist.insert(nextit,newind); |
---|
| 184 | nodelist.push_back(newind); |
---|
[e7de6cc] | 185 | sgraph[newind].LH.reset(); |
---|
| 186 | sgraph[newind].LD=LD; |
---|
| 187 | sgraph[newind].in_LH=false; //??????? |
---|
| 188 | sgraph[newind].LV.reset(); |
---|
[3b02b04] | 189 | |
---|
| 190 | copy_links(d,newind); |
---|
| 191 | create_reverse_links(newind); |
---|
[e7de6cc] | 192 | |
---|
[3b02b04] | 193 | if(debug) sgraph.print_node_debug(stderr,"C ",newind,d); |
---|
[b97a556] | 194 | // if(debug) print_sets(newind); |
---|
[e7de6cc] | 195 | |
---|
| 196 | return newind; |
---|
| 197 | } |
---|
| 198 | |
---|
[3b02b04] | 199 | int create_new_head_node_right(int h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV) |
---|
[e7de6cc] | 200 | { |
---|
[3b02b04] | 201 | int newheadind = sgraph.clone(h,newheadprop); |
---|
| 202 | // list<int>::iterator nextit=h; ++nextit; |
---|
| 203 | // nodelist.insert(nextit,newheadind); |
---|
| 204 | nodelist.push_back(newheadind); |
---|
[e7de6cc] | 205 | sgraph[newheadind].LH=newheadLH; |
---|
| 206 | sgraph[newheadind].LD=newheadLD; |
---|
| 207 | sgraph[newheadind].in_LH=false; |
---|
| 208 | sgraph[newheadind].LV=newheadLV; |
---|
| 209 | |
---|
[3b02b04] | 210 | copy_links(h,newheadind); |
---|
| 211 | create_reverse_links(newheadind); |
---|
| 212 | |
---|
| 213 | if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,h); |
---|
[b97a556] | 214 | // if(debug) print_sets(newheadind); |
---|
[e7de6cc] | 215 | |
---|
| 216 | return newheadind; |
---|
| 217 | } |
---|
| 218 | |
---|
[3b02b04] | 219 | int create_new_dep_node_right(int d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV) |
---|
[e7de6cc] | 220 | { |
---|
[3b02b04] | 221 | int newind = sgraph.clone(d,prop); |
---|
| 222 | nodelist.push_back(newind); |
---|
[e7de6cc] | 223 | sgraph[newind].LH=LH; |
---|
| 224 | sgraph[newind].LD=LD; |
---|
| 225 | sgraph[newind].in_LH=true; //??????? |
---|
| 226 | sgraph[newind].LV.reset(); |
---|
| 227 | |
---|
[3b02b04] | 228 | copy_links(d,newind); |
---|
| 229 | create_reverse_links(newind); |
---|
| 230 | |
---|
| 231 | if(debug) sgraph.print_node_debug(stderr,"C ",newind,d); |
---|
[b97a556] | 232 | // if(debug) print_sets(newind); |
---|
[e7de6cc] | 233 | |
---|
| 234 | return newind; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | //==================================================================================================== |
---|
| 238 | |
---|
[3b02b04] | 239 | void connect_left(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles) |
---|
[e7de6cc] | 240 | { |
---|
| 241 | |
---|
[3b02b04] | 242 | NodeProp &oldheadprop = sgraph[h].prop; |
---|
| 243 | NodeProp &olddepprop = sgraph[d].prop; |
---|
[e7de6cc] | 244 | |
---|
| 245 | NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles,olddepprop.flags); |
---|
| 246 | |
---|
| 247 | int newheadind; |
---|
| 248 | if(oldheadprop==newheadprop) |
---|
[3b02b04] | 249 | newheadind = h; |
---|
[e7de6cc] | 250 | else |
---|
| 251 | { |
---|
[3b02b04] | 252 | bitset<MAXNODES> newheadLH = sgraph[h].LH; |
---|
| 253 | bitset<MAXNODES> newheadLV = sgraph[d].LV; |
---|
| 254 | bitset<MAXNODES> newheadLD = sgraph[h].LD; |
---|
| 255 | |
---|
| 256 | // vector<int> newedge; |
---|
[e7de6cc] | 257 | |
---|
[3b02b04] | 258 | newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV); |
---|
| 259 | if( newheadind >= 0) // W£¡CZONE |
---|
[e7de6cc] | 260 | sgraph[newheadind].LD |= newheadLD; |
---|
| 261 | else |
---|
[3b02b04] | 262 | { |
---|
| 263 | newheadind = create_new_head_node_left(h,newheadprop,newheadLH,newheadLD,newheadLV); |
---|
| 264 | sgraph[newheadind].edge.clear(); |
---|
| 265 | sgraph[newheadind].edge_contains_self = false; |
---|
| 266 | } |
---|
| 267 | |
---|
[e7de6cc] | 268 | } |
---|
| 269 | |
---|
| 270 | NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles); |
---|
| 271 | |
---|
| 272 | int newdepind; |
---|
| 273 | |
---|
| 274 | if(olddepprop==newdepprop) |
---|
[3b02b04] | 275 | newdepind = d; |
---|
[e7de6cc] | 276 | else |
---|
| 277 | { |
---|
[3b02b04] | 278 | bitset<MAXNODES> newdepLH = sgraph[d].LH; |
---|
| 279 | bitset<MAXNODES> newdepLV = sgraph[d].LV; |
---|
| 280 | bitset<MAXNODES> newdepLD = sgraph[d].LD; |
---|
[e7de6cc] | 281 | |
---|
[3b02b04] | 282 | newdepind = find_existing_node(sgraph[d].mnode, newdepprop, newdepLH, newdepLV); |
---|
| 283 | if( newdepind >= 0) // W£¡CZONE |
---|
[e7de6cc] | 284 | sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD |
---|
| 285 | else |
---|
[3b02b04] | 286 | { |
---|
| 287 | newdepind = create_new_dep_node_left(d,newdepprop,newdepLH,newdepLD,newdepLV); |
---|
| 288 | sgraph[newdepind].edge.clear(); |
---|
| 289 | //sgraph[newdepind].edge.push_back(newdepind); // TO |
---|
| 290 | sgraph[newdepind].edge_contains_self = true; // LUB TO |
---|
| 291 | } |
---|
[e7de6cc] | 292 | } |
---|
[3b02b04] | 293 | |
---|
[e7de6cc] | 294 | |
---|
[3b02b04] | 295 | sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,h,d)); |
---|
| 296 | sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,h,d)); |
---|
| 297 | sgraph[newheadind].edge.push_back(newdepind); |
---|
[e7de6cc] | 298 | |
---|
[3b02b04] | 299 | if(sgraph[d].saturated()) sgraph[newheadind].LV |= sgraph[d].LV; |
---|
[e7de6cc] | 300 | |
---|
[3b02b04] | 301 | sgraph[newheadind].LD.set(d); |
---|
| 302 | if(sgraph[d].saturated()) sgraph[newheadind].LD |= sgraph[d].LD; |
---|
[e7de6cc] | 303 | |
---|
[3b02b04] | 304 | if(debug) sgraph.print_arc(stderr,newheadind,d,l.role,0); |
---|
| 305 | if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,h); |
---|
[b97a556] | 306 | // if(debug) print_sets(newheadind); |
---|
[3b02b04] | 307 | if(debug) sgraph.print_node_debug(stderr,"U ",newdepind,d); |
---|
[b97a556] | 308 | // if(debug) print_sets(newdepind); |
---|
[e7de6cc] | 309 | } |
---|
| 310 | |
---|
| 311 | //---------------------------------------------------------------------------------------------------- |
---|
| 312 | |
---|
[3b02b04] | 313 | void connect_right(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles) |
---|
[e7de6cc] | 314 | { |
---|
[3b02b04] | 315 | NodeProp &oldheadprop = sgraph[h].prop; |
---|
[e7de6cc] | 316 | |
---|
[3b02b04] | 317 | NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles, sgraph[d].prop.flags); |
---|
[e7de6cc] | 318 | |
---|
| 319 | int newheadind; |
---|
| 320 | |
---|
| 321 | if(oldheadprop==newheadprop) |
---|
[3b02b04] | 322 | newheadind = h; |
---|
[e7de6cc] | 323 | else |
---|
| 324 | { |
---|
[3b02b04] | 325 | bitset<MAXNODES> newheadLH = sgraph[h].LH; |
---|
| 326 | bitset<MAXNODES> newheadLV = sgraph[h].LV; |
---|
| 327 | bitset<MAXNODES> newheadLD = sgraph[h].LD; |
---|
| 328 | |
---|
| 329 | newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV); |
---|
[e7de6cc] | 330 | |
---|
[3b02b04] | 331 | if(debug) fprintf(stderr,"#HEAD EXISTS %d\n",newheadind); |
---|
| 332 | |
---|
| 333 | if( newheadind >= 0) // W£¡CZONE |
---|
[e7de6cc] | 334 | sgraph[newheadind].LD |= newheadLD; // TYLKO DLA LD |
---|
| 335 | else |
---|
[3b02b04] | 336 | { |
---|
| 337 | newheadind = create_new_head_node_right(h,newheadprop,newheadLH,newheadLD,newheadLV); |
---|
| 338 | //if(!sgraph[h].edge.empty()) sgraph[newheadind].edge.push_back(newheadind); // TO |
---|
| 339 | sgraph[newheadind].edge_contains_self = sgraph[h].edge_contains_self; // LUB TO |
---|
| 340 | sgraph[newheadind].visible_as_neighbour = false; |
---|
| 341 | } |
---|
[e7de6cc] | 342 | } |
---|
| 343 | |
---|
[3b02b04] | 344 | NodeProp &olddepprop = sgraph[d].prop; |
---|
[e7de6cc] | 345 | NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles); |
---|
| 346 | |
---|
| 347 | int newdepind; |
---|
| 348 | |
---|
| 349 | if(olddepprop==newdepprop) |
---|
[3b02b04] | 350 | newdepind = d; |
---|
[e7de6cc] | 351 | else |
---|
| 352 | { |
---|
[3b02b04] | 353 | bitset<MAXNODES> newdepLH = sgraph[d].LH; |
---|
| 354 | bitset<MAXNODES> newdepLV = sgraph[d].LV; |
---|
| 355 | bitset<MAXNODES> newdepLD = sgraph[d].LD; |
---|
| 356 | |
---|
| 357 | newdepind = find_existing_node(sgraph[d].mnode, newdepprop, newdepLH, newdepLV); |
---|
| 358 | |
---|
| 359 | if(debug) fprintf(stderr,"#DEP EXISTS %d\n",newdepind); |
---|
[e7de6cc] | 360 | |
---|
[3b02b04] | 361 | if( newdepind >= 0) // W£¡CZONE |
---|
[e7de6cc] | 362 | sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD |
---|
| 363 | else |
---|
[3b02b04] | 364 | { |
---|
| 365 | newdepind = create_new_dep_node_right(d,newdepprop,newdepLH,newdepLD,newdepLV); |
---|
| 366 | sgraph[newdepind].edge.clear(); |
---|
| 367 | sgraph[newdepind].edge_contains_self = false; |
---|
| 368 | } |
---|
[e7de6cc] | 369 | } |
---|
| 370 | |
---|
| 371 | |
---|
[3b02b04] | 372 | sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,h,d)); |
---|
| 373 | sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,h,d)); |
---|
| 374 | //sgraph[newdepind].edge.push_back(newheadind); |
---|
[e7de6cc] | 375 | |
---|
| 376 | sgraph[newdepind].LH.set(newheadind); |
---|
| 377 | |
---|
| 378 | // sgraph[*d].prop.merge_boubbles(new_dep_boubbles); |
---|
| 379 | |
---|
| 380 | if(sgraph[newheadind].saturated()) sgraph[newdepind].LH |= sgraph[newheadind].LH; |
---|
| 381 | |
---|
| 382 | if(debug) sgraph.print_arc(stderr,newheadind,newdepind,l.role,1); |
---|
[3b02b04] | 383 | if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,h); |
---|
| 384 | if(debug) sgraph.print_node_debug(stderr,"U ",newdepind,d); |
---|
[e7de6cc] | 385 | |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | //==================================================================================================== |
---|
| 389 | |
---|
[a15e59b] | 390 | // sprawdza czy te, spo¶ród b±bli, które dotar³y do celu node |
---|
| 391 | // daj± wynik prawdziwy, dodatkowo - usuwa je z listy boubbles |
---|
| 392 | |
---|
| 393 | bool check_boubbles_at_target(list<Boubble*>& boubbles, int node) |
---|
[e7de6cc] | 394 | { |
---|
[a15e59b] | 395 | list<Boubble*>::iterator last; // ostatnio sprawdzany b±bel |
---|
| 396 | bool remove=false; // czy usun±æ ostatnio sprawdzany b±bel |
---|
| 397 | |
---|
| 398 | for(list<Boubble*>::iterator b = boubbles.begin(); b != boubbles.end(); b = remove ? boubbles.erase(b) : ++b ) |
---|
| 399 | if( (*b)->is_at_target() ) |
---|
| 400 | if( grammar.check_longrel(sgraph.cat((*b)->src()), sgraph.cat(node), (*b)->rel()) ) |
---|
| 401 | remove=true; |
---|
| 402 | else |
---|
| 403 | return false; |
---|
| 404 | else |
---|
| 405 | remove=false; |
---|
| 406 | |
---|
[e7de6cc] | 407 | return true; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | //==================================================================================================== |
---|
| 411 | |
---|
[3b02b04] | 412 | void try_connect_dependents(int j) |
---|
[e7de6cc] | 413 | { |
---|
[3b02b04] | 414 | // for(list<int>::iterator i(j); i!=nodelist.begin(); --i) |
---|
| 415 | // if(sgraph.visible(*i,*j) && sgraph.saturated(*i)) |
---|
| 416 | LViterator lvi(sgraph,j); |
---|
| 417 | int i; |
---|
| 418 | while((i=lvi.next()) >= 0) |
---|
| 419 | if(sgraph.saturated(i)) |
---|
| 420 | { |
---|
| 421 | if(debug) {fprintf(stderr,"## %d <-- %d ... ",i,j); } |
---|
| 422 | |
---|
| 423 | list<const Link*> ji_links = grammar.connectable2( sgraph.cat(j), sgraph.cat(i), sgraph[j].prop.flags, sgraph[i].prop.flags); // ref do Roles!!! |
---|
[e7de6cc] | 424 | list<const Link*>::iterator ri = ji_links.begin(); |
---|
| 425 | if(ri == ji_links.end()) { if(debug) fprintf(stderr,"no roles\n"); } |
---|
| 426 | else |
---|
| 427 | { |
---|
| 428 | for(; ri != ji_links.end(); ++ri ) |
---|
[3b02b04] | 429 | if(!grammar.check_constr2(sgraph[j].prop,sgraph[i].prop,0,**ri )) |
---|
[e7de6cc] | 430 | { if(debug) fprintf(stderr,"constraints failed\n"); } |
---|
| 431 | else |
---|
| 432 | { |
---|
[3b02b04] | 433 | list<Boubble*> new_head_boubbles = collect_head_boubbles(j,i,(*ri)->role); |
---|
| 434 | list<Boubble*> new_dep_boubbles = collect_dep_boubbles(j,i,(*ri)->role); |
---|
[e7de6cc] | 435 | |
---|
[3b02b04] | 436 | if( !(check_boubbles_at_target(new_head_boubbles,j) && check_boubbles_at_target(new_dep_boubbles,i)) ) |
---|
[e7de6cc] | 437 | { if(debug) fprintf(stderr,"boubbles failed\n"); } |
---|
| 438 | else |
---|
| 439 | { |
---|
| 440 | if(debug) fprintf(stderr,"success\n"); |
---|
| 441 | connect_left( j, i, **ri, new_head_boubbles, new_dep_boubbles); |
---|
| 442 | } |
---|
| 443 | } |
---|
| 444 | } |
---|
| 445 | } |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | |
---|
| 449 | //---------------------------------------------------------------------------------------------------- |
---|
| 450 | |
---|
[3b02b04] | 451 | void try_connect_heads(int j) |
---|
[e7de6cc] | 452 | { |
---|
[3b02b04] | 453 | // for(list<int>::iterator i(j); i!=nodelist.begin(); --i) |
---|
| 454 | // if(sgraph.visible(*i,*j) && sgraph.saturated(*j)) |
---|
| 455 | |
---|
| 456 | LViterator lvi(sgraph,j); |
---|
| 457 | int i; |
---|
| 458 | while((i=lvi.next()) >= 0) |
---|
| 459 | if(sgraph.saturated(j)) |
---|
[e7de6cc] | 460 | { |
---|
[3b02b04] | 461 | if(debug) fprintf(stderr, "## %d --> %d ... ",i,j); |
---|
[e7de6cc] | 462 | |
---|
[3b02b04] | 463 | list<const Link*> ij_links = grammar.connectable2( sgraph.cat(i), sgraph.cat(j), sgraph[i].prop.flags, sgraph[j].prop.flags ); |
---|
[e7de6cc] | 464 | list<const Link*>::iterator ri = ij_links.begin(); |
---|
| 465 | if(ri == ij_links.end()) { if(debug) fprintf(stderr,"no roles\n"); } |
---|
| 466 | else |
---|
| 467 | { |
---|
| 468 | for(; ri != ij_links.end(); ++ri ) |
---|
[3b02b04] | 469 | if( !grammar.check_constr2( sgraph[i].prop, sgraph[j].prop, 1, **ri ) ) |
---|
[e7de6cc] | 470 | { if(debug) fprintf(stderr,"constraints failed\n"); } |
---|
| 471 | else |
---|
| 472 | { |
---|
[3b02b04] | 473 | list<Boubble*> new_head_boubbles = collect_head_boubbles(i,j,(*ri)->role); |
---|
| 474 | list<Boubble*> new_dep_boubbles = collect_dep_boubbles(i,j,(*ri)->role); |
---|
[e7de6cc] | 475 | |
---|
[3b02b04] | 476 | if( !(check_boubbles_at_target(new_head_boubbles,i) && check_boubbles_at_target(new_dep_boubbles,j)) ) |
---|
[e7de6cc] | 477 | { if(debug) fprintf(stderr,"boubbles failed\n"); } |
---|
| 478 | else |
---|
| 479 | { |
---|
| 480 | if(debug) fprintf(stderr,"success\n"); |
---|
| 481 | connect_right( i, j, **ri, new_head_boubbles, new_dep_boubbles ); |
---|
| 482 | } |
---|
| 483 | } |
---|
| 484 | } |
---|
| 485 | } |
---|
| 486 | } |
---|
[3b02b04] | 487 | |
---|
| 488 | //==================================================================================================== |
---|
| 489 | |
---|
| 490 | void update_sets() |
---|
| 491 | { |
---|
| 492 | for(int n=0; n<sgraph.size(); ++n) |
---|
| 493 | { |
---|
| 494 | LViterator lvi(sgraph,n,false); |
---|
| 495 | LHiterator lhi(sgraph,n); |
---|
| 496 | LDiterator ldi(sgraph,n); |
---|
| 497 | int i; |
---|
| 498 | |
---|
| 499 | // printf("UPDATING LV[%d]:",n); |
---|
| 500 | while((i=lvi.next())>=0) |
---|
| 501 | { |
---|
| 502 | // printf(" %d",i); |
---|
| 503 | sgraph[n].LV.set(i); |
---|
| 504 | } |
---|
| 505 | // printf("\n"); |
---|
| 506 | |
---|
| 507 | while((i=lhi.next())>=0) sgraph[n].LH.set(i); |
---|
| 508 | while((i=ldi.next())>=0) sgraph[n].LD.set(i); |
---|
| 509 | } |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | //==================================================================================================== |
---|
| 513 | |
---|
| 514 | void print_sets(int n) |
---|
| 515 | { |
---|
| 516 | LViterator lvi(sgraph,n); |
---|
| 517 | LHiterator lhi(sgraph,n); |
---|
| 518 | LDiterator ldi(sgraph,n); |
---|
[e7de6cc] | 519 | |
---|
[3b02b04] | 520 | int i; |
---|
| 521 | printf("LV[%d]: ",n); |
---|
| 522 | while((i=lvi.next())>=0) |
---|
| 523 | { |
---|
| 524 | printf("%d ",i); |
---|
| 525 | sgraph[n].LV.set(i); |
---|
| 526 | } |
---|
| 527 | |
---|
| 528 | printf("LH[%d]: ",n); |
---|
| 529 | while((i=lhi.next())>=0) |
---|
| 530 | { |
---|
| 531 | printf("%d ",i); |
---|
| 532 | sgraph[n].LH.set(i); |
---|
| 533 | } |
---|
| 534 | printf("LD[%d]: ",n); |
---|
| 535 | while((i=ldi.next())>=0) |
---|
| 536 | { |
---|
| 537 | printf("%d ",i); |
---|
| 538 | sgraph[n].LD.set(i); |
---|
| 539 | } |
---|
| 540 | printf("\n"); |
---|
| 541 | } |
---|
| 542 | |
---|
[e7de6cc] | 543 | //==================================================================================================== |
---|
| 544 | |
---|
| 545 | void reverse_links() |
---|
| 546 | { |
---|
| 547 | list<int>::iterator i = nodelist.begin(); |
---|
| 548 | for(++i; i!=nodelist.end(); ++i) |
---|
| 549 | { |
---|
| 550 | for(vector<Arc>::iterator da=sgraph[*i].deps.begin()--; da!=sgraph[*i].deps.end(); ++da) |
---|
| 551 | sgraph[da->dst].heads.push_back(Arc(*i,da->role,da->headanc,da->depanc)); |
---|
| 552 | for(vector<Arc>::iterator ha=sgraph[*i].heads.begin(); ha!=sgraph[*i].heads.end(); ++ha) |
---|
| 553 | sgraph[ha->dst].deps.push_back(Arc(*i,ha->role,ha->headanc,ha->depanc)); |
---|
| 554 | } |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | //==================================================================================================== |
---|
| 558 | |
---|
| 559 | void dgp1() |
---|
| 560 | { |
---|
| 561 | |
---|
| 562 | nodelist.clear(); |
---|
| 563 | nodelist.push_back(0); // BOS |
---|
| 564 | processed=nodelist.begin(); |
---|
| 565 | |
---|
| 566 | for(int m=0; m<mgraph.size() ; ++m) |
---|
| 567 | { |
---|
| 568 | int basenode = sgraph.add_base_snode(m); // ma zwracaæ SNode* |
---|
| 569 | |
---|
| 570 | set_initial_constraints(basenode); |
---|
| 571 | nodelist.push_back(basenode); |
---|
| 572 | |
---|
[3b02b04] | 573 | if(debug) sgraph.print_node_debug(stderr,"B ",basenode,-1); // STDOUT!!! |
---|
| 574 | if(debug) print_sets(basenode); |
---|
[e7de6cc] | 575 | |
---|
| 576 | list<int>::iterator cursor=processed; |
---|
| 577 | while(++cursor != nodelist.end()) |
---|
| 578 | { |
---|
[3b02b04] | 579 | if(debug) sgraph.print_node_debug(stderr,"> ",*cursor,-1); |
---|
| 580 | try_connect_dependents(*cursor); |
---|
| 581 | try_connect_heads(*cursor); |
---|
[e7de6cc] | 582 | processed=cursor; |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | } |
---|
[3b02b04] | 586 | // reverse_links(); |
---|
| 587 | update_sets(); |
---|
[e7de6cc] | 588 | } |
---|