- Timestamp:
- 12/17/14 12:13:11 (10 years ago)
- Branches:
- master
- Children:
- 854bece
- Parents:
- d484a32
- git-author:
- Tomasz Obrebski <obrebski@…> (12/17/14 12:10:45)
- git-committer:
- Tomasz Obrebski <obrebski@…> (12/17/14 12:13:11)
- Location:
- src/dgp
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/dgp/dgp1.cc
rd484a32 racbabee 2 2 using namespace std; 3 3 4 #include "dgp 0.hh"4 #include "dgp1.hh" 5 5 #include "global.hh" 6 6 … … 71 71 //==================================================================================================== 72 72 73 int find_existing_node(int mnodeind, NodeProp p, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLV) 74 { 75 MNode& mnode = mgraph[mnodeind]; 76 int ret=-1; 77 for(vector<int>::iterator ps=mnode.snodes.begin(); ps!=mnode.snodes.end(); ++ps) 78 { 79 if(debug) fprintf(stderr,"#find existing node: checking %d ... \n", *ps); 80 if(sgraph[*ps].prop==p) 81 if(sgraph[*ps].LH==newheadLH && sgraph[*ps].LV==newheadLV) 82 { 83 ret = *ps; 84 if(debug) fprintf(stderr,"#\tsucceeded because of LH/LV equality ()\n"); 85 } 86 else 87 { 88 if(debug) fprintf(stderr,"#\tfailed beacause of LH/LV inequality\n"); 89 } 90 } 91 92 if(debug) fprintf(stderr,"\n"); 93 return ret; 73 int find_existing_node(int mnode, NodeProp p, Edge e) 74 { 75 for(vector<int>::iterator i = mgraph[mnode].snodes.begin(); i!=mgraph[mnode].snodes.end(); ++i) 76 if(sgraph[*i].prop==p && sgraph[*i].edge==e) 77 { 78 if(debug) fprintf(stderr,"\t\treusing %d\n",*i); 79 return *i; 80 } 81 return -1; 94 82 } 95 83 … … 161 149 //==================================================================================================== 162 150 163 int create_new_ head_node_left(int anc, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV)164 { 165 int newheadind = sgraph.clone(anc,prop );151 int create_new_node(int anc, NodeProp& prop, Edge edge) 152 { 153 int newheadind = sgraph.clone(anc,prop,edge); 166 154 nodelist.push_back(newheadind); 167 sgraph[newheadind].LH = LH;168 sgraph[newheadind].LD = LD;169 sgraph[newheadind].in_LH = true;170 sgraph[newheadind].LV.reset();171 172 155 copy_links(anc,newheadind); 173 156 create_reverse_links(newheadind); 174 175 if(debug) sgraph.print_node_debug(stderr,"add new",newheadind,anc); 157 if(debug) sgraph.print_node_debug(stderr,"clone",newheadind,anc); 176 158 // if(debug) print_sets(newheadind); 177 159 return newheadind; 178 160 } 179 161 180 int create_new_dep_node_left(int anc, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV)181 {182 int newind = sgraph.clone(anc,prop);183 nodelist.push_back(newind);184 sgraph[newind].LH.reset();185 sgraph[newind].LD=LD;186 sgraph[newind].in_LH=false; //???????187 sgraph[newind].LV.reset();188 189 copy_links(anc,newind);190 create_reverse_links(newind);191 192 if(debug) sgraph.print_node_debug(stderr,"add new",newind,anc);193 // if(debug) print_sets(newind);194 195 return newind;196 }197 198 int create_new_head_node_right(int anc, NodeProp& prop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV)199 {200 int newheadind = sgraph.clone(anc,prop);201 nodelist.push_back(newheadind);202 sgraph[newheadind].LH=newheadLH;203 sgraph[newheadind].LD=newheadLD;204 sgraph[newheadind].in_LH=false;205 sgraph[newheadind].LV=newheadLV;206 207 copy_links(anc,newheadind);208 create_reverse_links(newheadind);209 210 if(debug) sgraph.print_node_debug(stderr,"add new",newheadind,anc);211 // if(debug) print_sets(newheadind);212 213 return newheadind;214 }215 216 int create_new_dep_node_right(int anc, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV)217 {218 int newind = sgraph.clone(anc,prop);219 nodelist.push_back(newind);220 sgraph[newind].LH=LH;221 sgraph[newind].LD=LD;222 sgraph[newind].in_LH=true; //???????223 sgraph[newind].LV.reset();224 225 copy_links(anc,newind);226 create_reverse_links(newind);227 228 if(debug) sgraph.print_node_debug(stderr,"ADD NEW",newind,anc);229 // if(debug) print_sets(newind);230 231 return newind;232 }233 234 162 //==================================================================================================== 235 163 … … 237 165 { 238 166 239 NodeProp &oldheadprop = sgraph[h].prop; 240 NodeProp &olddepprop = sgraph[d].prop; 241 242 NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles,olddepprop.flags); 243 244 int newheadind; 245 if(oldheadprop==newheadprop) 246 newheadind = h; 247 else 248 { 249 bitset<MAXNODES> newheadLH = sgraph[h].LH; 250 bitset<MAXNODES> newheadLV = sgraph[d].LV; 251 bitset<MAXNODES> newheadLD = sgraph[h].LD; 252 253 newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV); 254 if( newheadind >= 0) // W£¡CZONE 255 sgraph[newheadind].LD |= newheadLD; 256 else 167 NodeProp &old_head_prop = sgraph[h].prop; 168 NodeProp &old_dep_prop = sgraph[d].prop; 169 NodeProp new_head_prop = compute_head_prop(old_head_prop,l,new_head_boubbles,old_dep_prop.flags); 170 NodeProp new_dep_prop = compute_dep_prop(old_dep_prop,l,new_dep_boubbles); 171 172 Edge new_dep_edge(sgraph[d].edge); 173 int newd = find_existing_node(sgraph[d].mnode, new_dep_prop, new_dep_edge); 174 if( newd < 0 ) 175 newd = create_new_node(d,new_dep_prop,new_dep_edge); 176 177 Edge new_head_edge(sgraph[newd].edge,newd); 178 int newh = find_existing_node(sgraph[h].mnode, new_head_prop, new_head_edge); 179 if( newh < 0 ) 180 newh = create_new_node(h,new_head_prop,new_head_edge); 181 182 sgraph[newh].deps.push_back(Arc(newd,l.role,h,d)); 183 sgraph[newd].heads.push_back(Arc(newh,l.role,h,d)); 184 185 if(debug) 186 { 187 sgraph.print_arc(stderr,"link",newh,d,l.role,0); 188 sgraph.print_node_debug(stderr,"",newh,h); 189 sgraph.print_node_debug(stderr,"",newd,d); 190 } 191 } 192 193 //---------------------------------------------------------------------------------------------------- 194 195 void connect_right(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles) 196 { 197 NodeProp &old_head_prop = sgraph[h].prop; 198 NodeProp &old_dep_prop = sgraph[d].prop; 199 NodeProp new_head_prop = compute_head_prop(old_head_prop,l,new_head_boubbles,old_dep_prop.flags); 200 NodeProp new_dep_prop = compute_dep_prop(old_dep_prop,l,new_dep_boubbles); 201 202 Edge new_head_edge(sgraph[h].edge); 203 int newh = find_existing_node(sgraph[h].mnode, new_head_prop, new_head_edge); 204 if( newh < 0 ) 257 205 { 258 newheadind = create_new_head_node_left(h,newheadprop,newheadLH,newheadLD,newheadLV); 259 sgraph[newheadind].edge.clear(); 260 sgraph[newheadind].edge_contains_self = false; 206 newh = create_new_node(h,new_head_prop,new_head_edge); 207 sgraph[newh].visible_as_neighbour = false; 261 208 } 262 263 } 264 265 NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles); 266 267 int newdepind; 268 269 if(olddepprop==newdepprop) 270 newdepind = d; 271 else 272 { 273 bitset<MAXNODES> newdepLH = sgraph[d].LH; 274 bitset<MAXNODES> newdepLV = sgraph[d].LV; 275 bitset<MAXNODES> newdepLD = sgraph[d].LD; 276 277 newdepind = find_existing_node(sgraph[d].mnode, newdepprop, newdepLH, newdepLV); 278 if( newdepind >= 0) // W£¡CZONE 279 sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD 280 else 281 { 282 newdepind = create_new_dep_node_left(d,newdepprop,newdepLH,newdepLD,newdepLV); 283 sgraph[newdepind].edge.clear(); 284 //sgraph[newdepind].edge.push_back(newdepind); // TO 285 sgraph[newdepind].edge_contains_self = true; // LUB TO 286 } 287 } 288 289 290 sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,h,d)); 291 sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,h,d)); 292 sgraph[newheadind].edge.push_back(newdepind); 293 294 if(sgraph[d].saturated()) sgraph[newheadind].LV |= sgraph[d].LV; 295 296 sgraph[newheadind].LD.set(d); 297 if(sgraph[d].saturated()) sgraph[newheadind].LD |= sgraph[d].LD; 298 299 if(debug) sgraph.print_arc(stderr,"new link",newheadind,d,l.role,0); 300 if(debug) sgraph.print_node_debug(stderr,"update",newheadind,h); 301 // if(debug) print_sets(newheadind); 302 if(debug) sgraph.print_node_debug(stderr,"update",newdepind,d); 303 // if(debug) print_sets(newdepind); 304 } 305 306 //---------------------------------------------------------------------------------------------------- 307 308 void connect_right(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles) 309 { 310 NodeProp &oldheadprop = sgraph[h].prop; 311 312 NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles, sgraph[d].prop.flags); 313 314 int newheadind; 315 316 if(oldheadprop==newheadprop) 317 newheadind = h; 318 else 319 { 320 bitset<MAXNODES> newheadLH = sgraph[h].LH; 321 bitset<MAXNODES> newheadLV = sgraph[h].LV; 322 bitset<MAXNODES> newheadLD = sgraph[h].LD; 323 324 newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV); 325 326 if(debug) fprintf(stderr,"#HEAD EXISTS %d\n",newheadind); 327 328 if( newheadind >= 0) // W£¡CZONE 329 sgraph[newheadind].LD |= newheadLD; // TYLKO DLA LD 330 else 331 { 332 newheadind = create_new_head_node_right(h,newheadprop,newheadLH,newheadLD,newheadLV); 333 //if(!sgraph[h].edge.empty()) sgraph[newheadind].edge.push_back(newheadind); // TO 334 sgraph[newheadind].edge_contains_self = sgraph[h].edge_contains_self; // LUB TO 335 sgraph[newheadind].visible_as_neighbour = false; 336 } 337 } 338 339 NodeProp &olddepprop = sgraph[d].prop; 340 NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles); 341 342 int newdepind; 343 344 if(olddepprop==newdepprop) 345 newdepind = d; 346 else 347 { 348 bitset<MAXNODES> newdepLH = sgraph[d].LH; 349 bitset<MAXNODES> newdepLV = sgraph[d].LV; 350 bitset<MAXNODES> newdepLD = sgraph[d].LD; 351 352 newdepind = find_existing_node(sgraph[d].mnode, newdepprop, newdepLH, newdepLV); 353 354 if(debug) fprintf(stderr,"#DEP EXISTS %d\n",newdepind); 355 356 if( newdepind >= 0) // W£¡CZONE 357 sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD 358 else 359 { 360 newdepind = create_new_dep_node_right(d,newdepprop,newdepLH,newdepLD,newdepLV); 361 sgraph[newdepind].edge.clear(); 362 sgraph[newdepind].edge_contains_self = false; 363 } 364 } 365 366 367 sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,h,d)); 368 sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,h,d)); 369 //sgraph[newdepind].edge.push_back(newheadind); 370 371 sgraph[newdepind].LH.set(newheadind); 372 373 // sgraph[*d].prop.merge_boubbles(new_dep_boubbles); 374 375 if(sgraph[newheadind].saturated()) sgraph[newdepind].LH |= sgraph[newheadind].LH; 376 377 if(debug) sgraph.print_arc(stderr,"new link",newheadind,newdepind,l.role,1); 378 if(debug) sgraph.print_node_debug(stderr,"update",newheadind,h); 379 if(debug) sgraph.print_node_debug(stderr,"update",newdepind,d); 380 381 } 382 383 //==================================================================================================== 384 385 // bool check_meeting_boubles(list<Boubble*>& hboubbles, list<Boubble*>& dboubbles) 386 // { 387 // bool hremove=false; // czy usun±æ ostatnio sprawdzany b±bel 388 // bool dremove=false; // czy usun±æ ostatnio sprawdzany b±bel 389 390 // for(list<Boubble*>::iterator hb = hboubbles.begin(); hb != hboubbles.end(); hb = hremove ? hboubbles.erase(hb) : ++hb ) 391 // { 392 // hremove=false; 393 // for(list<Boubble*>::iterator db = dboubbles.begin(); db != dboubbles.end(); db = dremove ? dboubbles.erase(db) : ++db ) 394 // { 395 // dremove=false; 396 // if( (*hb)->rel()==(*db)->rel() && (*hb)->dir()==DOWN && (*db)->dir()==UP && (*hb)->reverse()!=(*db)->reverse() ) 397 // { 398 // int srcnode,dstnode; 399 // if( (*hb)->reverse()==false ) 400 // srcnode = (*hb)->src(), dstnode = (*db)->src(); 401 // else 402 // srcnode = (*db)->src(), dstnode = (*hb)->src(); 403 // if( grammar.check_longrel(sgraph.cat(srcnode), sgraph.cat(dstnode), (*hb)->rel()) ) 404 // { 405 // hremove=dremove=true; 406 // if(debug) fprintf(stderr,"BOUBBLES MET!!!\n"); 407 // } 408 // else 409 // { 410 // if(debug) fprintf(stderr,"BOUBBLES' MEETING FAILED!!!\n"); 411 // return false; 412 // } 413 // } 414 // } 415 // } 416 // return true; 417 // } 209 210 Edge new_dep_edge; 211 int newd = find_existing_node(sgraph[d].mnode, new_dep_prop, new_dep_edge); 212 if( newd < 0) 213 newd = create_new_node(d,new_dep_prop,new_dep_edge); 214 215 216 sgraph[newd].heads.push_back(Arc(newh,l.role,h,d)); 217 sgraph[newh].deps.push_back(Arc(newd,l.role,h,d)); 218 219 if(debug) 220 { 221 sgraph.print_arc(stderr,"link",newh,newd,l.role,1); 222 sgraph.print_node_debug(stderr,"",newh,h); 223 sgraph.print_node_debug(stderr,"",newd,d); 224 } 225 226 } 418 227 419 228 //==================================================================================================== … … 424 233 bool dremove=false; // czy usun±æ ostatnio sprawdzany b±bel 425 234 235 // cerr << "CHECKING MEETING BUBBLES" << endl; 236 426 237 for(list<Boubble*>::iterator hb = boubbles.begin(); hb != boubbles.end(); hb = hremove ? boubbles.erase(hb) : ++hb ) 427 238 { 428 cout << endl << "hb:" << **hb ;429 239 hremove=false; 430 240 for(list<Boubble*>::iterator db = hb; db != boubbles.end(); db = dremove ? boubbles.erase(db) : ++db ) 431 241 { 432 cout<< " db:" << **db;242 // cerr << " db:" << **db; 433 243 dremove=false; 434 244 if( (*hb)->rel()==(*db)->rel() && (*hb)->reverse()!=(*db)->reverse() ) 435 245 { 436 cout << "Z";246 // cerr << "Z"; 437 247 int srcnode,dstnode; 438 248 if( (*hb)->reverse()==false ) … … 442 252 if( grammar.check_longrel(sgraph.cat(srcnode), sgraph.cat(dstnode), (*hb)->rel()) ) 443 253 { 444 cout<< " REMOVE ";254 // cerr << " REMOVE "; 445 255 hremove=dremove=true; 446 256 if(debug) fprintf(stderr,"BOUBBLES MET!!!\n"); … … 448 258 else 449 259 { 450 cout<< " FAIL ";260 // cerr << " FAIL "; 451 261 if(debug) fprintf(stderr,"BOUBBLES' MEETING FAILED!!!\n"); 452 262 return false; … … 471 281 if( grammar.check_longrel(sgraph.cat((*b)->src()), sgraph.cat(node), (*b)->rel()) ) 472 282 { 473 cout<< endl << "REMOVE ChBatT " << **b << endl;283 // cerr << endl << "REMOVE ChBatT " << **b << endl; 474 284 remove=true; 475 285 } … … 489 299 int i; 490 300 while((i=lvi.next()) >= 0) 491 {492 //if(debug) sgraph.print_node_debug(stderr,"D-CUR>",i,-1);493 494 301 if(sgraph.saturated(i)) 495 302 { 496 if(debug) {fprintf(stderr," %d <--",i); }303 if(debug) {fprintf(stderr,"\t%d <-- %d",i,j); } 497 304 498 305 list<const Link*> ji_links = grammar.connectable2( sgraph.cat(j), sgraph.cat(i), sgraph[j].prop.flags, sgraph[i].prop.flags); // ref do Roles!!! … … 517 324 if(debug) fprintf(stderr," ...SUCCESS!\n"); 518 325 connect_left( j, i, **ri, new_head_boubbles, new_dep_boubbles); 519 lvi.update_edge(sgraph,i);326 // lvi.update_edge(sgraph,i); 520 327 } 521 328 else … … 526 333 } 527 334 else 528 if(debug) {fprintf(stderr,"%d <-- unsaturated\n",i); } 529 } 530 335 if(debug) {fprintf(stderr,"\t%d <-- %d\t%d unsaturated\n",i,j,i); } 531 336 } 532 337 //---------------------------------------------------------------------------------------------------- … … 537 342 int i; 538 343 while((i=lvi.next()) >= 0) 539 { 540 // if(debug) sgraph.print_node_debug(stderr,"H-CUR> ",i,-1); 541 if(sgraph.saturated(j)) 542 { 543 if(debug) fprintf(stderr, "%d -->",i); 544 545 list<const Link*> ij_links = grammar.connectable2( sgraph.cat(i), sgraph.cat(j), sgraph[i].prop.flags, sgraph[j].prop.flags ); 546 list<const Link*>::iterator ri = ij_links.begin(); 547 if(ri == ij_links.end()) { if(debug) fprintf(stderr," no roles\n"); } 548 else 549 { 550 for(; ri != ij_links.end(); ++ri ) 551 { 552 if(debug) fprintf(stderr," %s",(*ri)->role.str()); 553 if( !grammar.check_constr2( sgraph[i].prop, sgraph[j].prop, 1, **ri ) ) 554 { if(debug) fprintf(stderr," ...constraints failed\n"); } 555 else 556 { 557 list<Boubble*> new_head_boubbles = collect_head_boubbles(i,j,(*ri)->role); 558 list<Boubble*> new_dep_boubbles = collect_dep_boubbles(i,j,(*ri)->role); 559 560 if( check_meeting_boubles(new_head_boubbles) && 561 check_meeting_boubles(new_dep_boubbles) && 562 check_boubbles_at_target(new_head_boubbles,i) && 563 check_boubbles_at_target(new_dep_boubbles,j) ) 564 { 565 if(debug) fprintf(stderr," ...SUCCESS!\n"); 566 connect_right( i, j, **ri, new_head_boubbles, new_dep_boubbles ); 567 } 568 else 569 { if(debug) fprintf(stderr," ...bubbles failed\n",i); } 570 } 571 } 572 } 573 } 574 else 575 if(debug) {fprintf(stderr,"%d <-- unsaturated\n",j); } 576 } 344 if(sgraph.saturated(j)) 345 { 346 if(debug) fprintf(stderr, "\t%d --> %d",i,j); 347 348 list<const Link*> ij_links = grammar.connectable2( sgraph.cat(i), sgraph.cat(j), sgraph[i].prop.flags, sgraph[j].prop.flags ); 349 list<const Link*>::iterator ri = ij_links.begin(); 350 if(ri == ij_links.end()) { if(debug) fprintf(stderr," no roles\n"); } 351 else 352 { 353 for(; ri != ij_links.end(); ++ri ) 354 { 355 if(debug) fprintf(stderr," %s",(*ri)->role.str()); 356 if( !grammar.check_constr2( sgraph[i].prop, sgraph[j].prop, 1, **ri ) ) 357 { if(debug) fprintf(stderr," ...constraints failed\n"); } 358 else 359 { 360 list<Boubble*> new_head_boubbles = collect_head_boubbles(i,j,(*ri)->role); 361 list<Boubble*> new_dep_boubbles = collect_dep_boubbles(i,j,(*ri)->role); 362 363 if( check_meeting_boubles(new_head_boubbles) && 364 check_meeting_boubles(new_dep_boubbles) && 365 check_boubbles_at_target(new_head_boubbles,i) && 366 check_boubbles_at_target(new_dep_boubbles,j) ) 367 { 368 if(debug) fprintf(stderr," ...SUCCESS!\n"); 369 connect_right( i, j, **ri, new_head_boubbles, new_dep_boubbles ); 370 } 371 else 372 { if(debug) fprintf(stderr," ...bubbles failed\n",i); } 373 } 374 } 375 } 376 } 377 else 378 if(debug) {fprintf(stderr,"\t* <-- %d unsaturated\n",j); } 577 379 } 578 380 … … 662 464 nodelist.push_back(basenode); 663 465 664 if(debug) sgraph.print_node_debug(stderr," add base",basenode,-1); // STDOUT!!!466 if(debug) sgraph.print_node_debug(stderr,"node",basenode,-1); // STDOUT!!! 665 467 // if(debug) print_sets(basenode); 666 468 … … 668 470 while(++cursor != nodelist.end()) 669 471 { 670 if(debug) sgraph.print_node_debug(stderr," MAIN-CUR>",*cursor,-1);472 if(debug) sgraph.print_node_debug(stderr,"CUR>",*cursor,-1); 671 473 try_connect_dependents(*cursor); 672 474 try_connect_heads(*cursor); -
src/dgp/dgp1.hh
re7de6cc racbabee 1 #ifndef _DGP 0_HH2 #define _DGP 0_HH1 #ifndef _DGP1_HH 2 #define _DGP1_HH 3 3 4 4 #include "grammar.hh" -
src/dgp/sgraph.cc
rd484a32 racbabee 1 #include "global.hh"2 1 #include "sgraph.hh" 3 2 #include "grammar.hh" … … 16 15 newnode.mnode=mnodeind; 17 16 18 for(vector<int>::iterator pm=mgraph[newnode.mnode].pred.begin(); pm!=mgraph[newnode.mnode].pred.end(); ++pm)19 for(vector<int>::iterator ps=mgraph[*pm].snodes.begin(); ps!=mgraph[*pm].snodes.end(); ++ps)20 if(nodes[*ps].in_LH)21 {22 newnode.LV.set(*ps);23 if(nodes[*ps].saturated()) newnode.LV |= nodes[*ps].LH;24 }17 // for(vector<int>::iterator pm=mgraph[newnode.mnode].pred.begin(); pm!=mgraph[newnode.mnode].pred.end(); ++pm) 18 // for(vector<int>::iterator ps=mgraph[*pm].snodes.begin(); ps!=mgraph[*pm].snodes.end(); ++ps) 19 // if(nodes[*ps].in_LH) 20 // { 21 // newnode.LV.set(*ps); 22 // if(nodes[*ps].saturated()) newnode.LV |= nodes[*ps].LH; 23 // } 25 24 26 25 mgraph[newnode.mnode].snodes.push_back(lastnodeind()); 27 26 28 newnode.in_LH=true;27 // newnode.in_LH=true; 29 28 30 newnode.edge.push_back(lastnodeind());29 // newnode.edge.push_back(lastnodeind()); 31 30 32 newnode.edge _contains_self = true;31 newnode.edge.insert_self(); 33 32 34 33 return lastnodeind(); … … 55 54 //==================================================================================================== 56 55 57 int SGraph::clone(int ancind, NodeProp newprop )56 int SGraph::clone(int ancind, NodeProp newprop, Edge edge) 58 57 { 59 58 SNode &newnode=makenewnode(); 60 59 SNode &ancnode = nodes[ancind]; 61 60 62 newnode.prop=newprop; 63 newnode.mnode=ancnode.mnode; 61 newnode.prop = newprop; 62 newnode.edge = edge; 63 newnode.mnode = ancnode.mnode; 64 64 mgraph[newnode.mnode].snodes.push_back(lastnodeind()); 65 65 … … 90 90 { 91 91 if(dir==0) 92 fprintf(f,"%s %s:%d <-- %d\n", msg, role.str(), dep, head);92 fprintf(f,"%s\t%d <-- %d\t%s\n", msg, dep, head, role.str()); 93 93 else 94 fprintf(f,"%s %s:%d --> %d\n", msg, role.str(), head, dep);94 fprintf(f,"%s\t%d --> %d\t%s\n", msg, head, dep, role.str()); 95 95 } 96 96 … … 172 172 { 173 173 char *buf0 = buf; 174 buf+=sprintf(buf,"%- 10s",pref);174 buf+=sprintf(buf,"%-8s",pref); 175 175 buf+=sprintf(buf,"%d.%s",n,form(n)); 176 176 buf+=sprintf(buf,";"); 177 177 buf+=sprintf(buf,"%s ",cat(n).str()); 178 178 while(buf-buf0<40) buf+=sprintf(buf," "); 179 buf+=sprint_node(buf,n,anc,HEADS|DEPS| SETS|CONSTRAINTS);179 buf+=sprint_node(buf,n,anc,HEADS|DEPS|CONSTRAINTS); 180 180 181 181 buf+=sprintf(buf,"/"); 182 for(vector<int>::iterator e = nodes[n].edge.begin(); e != nodes[n].edge.end(); e++ ) 182 if(nodes[n].edge.self()) 183 buf += sprintf(buf,"* "); 184 for(list<int>::iterator e = nodes[n].edge.others().begin(); e != nodes[n].edge.others().end(); e++ ) 183 185 buf += sprintf(buf,"%d ", *e); 184 186 -
src/dgp/sgraph.hh
rd484a32 racbabee 13 13 #include "thesymbols.hh" 14 14 #include "boubble.hh" 15 15 #include "global.hh" 16 16 17 17 using namespace std; … … 116 116 } 117 117 118 //---------------------------------------------------------------------------------------------------- 119 120 inline 121 NodeProp::~NodeProp() 122 { 123 clear_boubbles(); 124 } 125 //---------------------------------------------------------------------------------------------------- 126 127 inline 128 NodeProp::NodeProp() 129 { 130 clear(); 131 } 132 133 //---------------------------------------------------------------------------------------------------- 134 135 inline 136 NodeProp::NodeProp(const NodeProp& p) 137 { 138 copy(p); 139 } 140 141 //---------------------------------------------------------------------------------------------------- 142 143 inline 144 NodeProp& NodeProp::operator=(const NodeProp& p) 145 { 146 clear(); 147 copy(p); 148 return *this; 149 } 150 151 //---------------------------------------------------------------------------------------------------- 152 153 inline 154 void NodeProp::clear() 118 inline NodeProp::~NodeProp() { clear_boubbles(); } 119 inline NodeProp::NodeProp() { clear(); } 120 inline NodeProp::NodeProp(const NodeProp& p) { copy(p); } 121 inline NodeProp& NodeProp::operator=(const NodeProp& p) { clear(); copy(p); return *this; } 122 inline void NodeProp::clear() 155 123 { 156 124 required.reset(); … … 163 131 164 132 //==================================================================================================== 133 // CLASS Edge 134 //==================================================================================================== 135 136 class Edge 137 { 138 public: 139 Edge() : _self(false) { } 140 Edge(const Edge& e, int map_self) { assign(e,map_self); } 141 142 bool self() const { return _self; } 143 list<int>& others() { return _others; } 144 145 void insert_self(bool b=true) { _self=b; } 146 void insert(int n) { list<int>::iterator i=others().begin(); while(i!=others().end() && *i<n) ++i; others().insert(i,n);} 147 void insert(list<int> l) { for(list<int>::const_iterator i=l.begin(); i!=l.end(); i++) insert(*i); } 148 149 void assign(const Edge& e, int map_self=-1) { _others = e._others; if(e.self()) { _self = false; insert(map_self); } } 150 const bool operator==(const Edge& e) const { return _self == e._self && _others == e._others; } 151 152 private: 153 bool _self; 154 list<int> _others; 155 }; 156 157 //==================================================================================================== 165 158 // CLASS SNode 166 159 //==================================================================================================== … … 175 168 NodeProp prop; 176 169 177 vector<int> edge; 178 bool edge_contains_self; 170 Edge edge; 179 171 bool visible_as_neighbour; 180 172 … … 189 181 void clear(); 190 182 bool saturated(); 183 184 // void edge_clear() { edge.clear(); edge_contains_self=false;} 185 // void edge_set(int i) { edge.clear(); edge_contains_self=false; edge.push_back(i); } 186 // void edge_set(vector<int>& v) { edge.assign(v.begin(),v.end()); edge_contains_self=false; } 187 // void edge_set_self(bool b=true) { edge.clear(); edge_contains_self=b; } 188 // void edge_add(int i) { edge.push_back(i); } 189 // void edge_add(vector<int>& v) { edge.insert(edge.end(),v.begin(),v.end()); } 190 // void edge_add_self(bool b=true) { edge_contains_self=b; } 191 191 }; 192 192 … … 216 216 void clear() { nodes.clear(); } 217 217 int add_base_snode(int mnodeind); 218 int clone(int ancind, NodeProp newprop );218 int clone(int ancind, NodeProp newprop, Edge edge); 219 219 void update_left(int headind, int depind); 220 220 void update_right(int headind, int depind); … … 299 299 300 300 private: 301 301 int snode; 302 302 SGraph& sgraph; 303 303 MGraph& mgraph; … … 312 312 }; 313 313 314 inline LViterator::LViterator(SGraph& sg, int n, bool s=true) : s graph(sg), mgraph(sg.mgraph), strict(s)315 { 316 if(sg[n].edge _contains_self) // TO DODAÆ PO PRZEJŠCIU NA EDGE_CONTAINS_SELF314 inline LViterator::LViterator(SGraph& sg, int n, bool s=true) : snode(n), sgraph(sg), mgraph(sg.mgraph), strict(s) 315 { 316 if(sg[n].edge.self()) 317 317 { 318 318 push_ld(n); … … 320 320 } 321 321 322 for(vector<int>::iterator i=sg[n].edge.begin(); i!=sg[n].edge.end(); ++i) 323 { 324 if(*i != n) 325 { 326 push_ld(*i); 327 push_ln(*i); 328 } 329 330 } 331 } 332 333 inline void LViterator::update_edge(SGraph& sg, int n) 334 { 335 for(vector<int>::iterator i=sg[n].edge.begin(); i!=sg[n].edge.end(); ++i) 322 for(list<int>::iterator i=sg[n].edge.others().begin(); i!=sg[n].edge.others().end(); ++i) 336 323 { 337 324 push_ld(*i); 338 325 push_ln(*i); 326 327 } 328 } 329 330 inline void LViterator::update_edge(SGraph& sg, int n) 331 { 332 if(sg[n].edge.self()) 333 { 334 push_ld(n); 335 push_ln(n); 336 } 337 338 for(list<int>::iterator i=sg[n].edge.others().begin(); i!=sg[n].edge.others().end(); ++i) 339 { 340 push_ld(*i); 341 push_ln(*i); 339 342 } 340 343 } … … 345 348 { 346 349 if(waydown.empty()) 347 return -1; // 350 { 351 if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,-1); 352 return -1; // 353 } 348 354 else 349 355 { … … 353 359 push_ln(k); 354 360 if(wayup.empty()) 355 return -1; // k NIE MA POPRZEDNIKÓW, NIE MO¯E TE¯ ZATEM MIEÆ LEWOSTRONNYCH PODRZÊDNIKÓW 361 { 362 if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,-1); 363 return -1; // k NIE MA POPRZEDNIKÓW, NIE MO¯E TE¯ ZATEM MIEÆ LEWOSTRONNYCH PODRZÊDNIKÓW 364 } 356 365 else 357 366 { … … 359 368 wayup.pop(); 360 369 push_lh(i); 370 if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,i); 361 371 return i; 362 372 } … … 364 374 365 375 } 376 else 377 { 378 int i = wayup.top(); 379 wayup.pop(); 380 push_lh(i); 381 if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,i); 382 return i; 383 }; 384 } 385 386 inline void LViterator::push_ld(int i) 387 { 388 vector<Arc>& arcs = sgraph[i].deps; 389 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 390 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 391 { 392 push(waydown,a->dst); 393 if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LD waydown %d\n",snode,a->dst); 394 } 395 } 396 397 inline void LViterator::push_lh(int i) 398 { 399 vector<Arc>& arcs = sgraph[i].heads; 400 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 401 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 402 { 403 push(wayup,a->dst); 404 if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LH wayup %d\n",snode,a->dst); 405 } 406 } 407 408 inline void LViterator::push_ln(int i) 409 { 410 vector<int>& mpredecessors = mgraph[sgraph[i].mnode].pred; 411 for(vector<int>::iterator mp = mpredecessors.begin(); mp != mpredecessors.end(); ++mp) // poprzedniki w mgraph 412 { 413 vector<int>& spredecessors = mgraph[*mp].snodes; 414 for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) 415 if(sgraph[*sp].visible_as_neighbour || !strict) 416 { 417 push(wayup,*sp); 418 if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LN wayup %d\n",snode, *sp); 419 } 420 } 421 } 422 423 424 //---------------------------------------------------------------------------------------------------- 425 //---------------------------------------------------------------------------------------------------- 426 427 class LNiterator 428 { 429 public: 430 LNiterator(SGraph& sg, int n); 431 432 int next(); 433 434 private: 435 int snode; 436 SGraph& sgraph; 437 MGraph& mgraph; 438 stack<int> wayup; 439 440 void push_ln(int i); 441 }; 442 443 inline LNiterator::LNiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), snode(n) 444 { 445 push_ln(n); 446 } 447 448 inline int LNiterator::next() 449 { 450 if(wayup.empty()) 451 { 452 if(debug) fprintf(stderr,"\t\tLNiterator(%d)\treturn %d\n",snode,-1); 453 return -1; 454 } 455 else 456 { 457 int i = wayup.top(); 458 wayup.pop(); 459 if(debug) fprintf(stderr,"\t\tLNiterator(%d)\treturn %d\n",snode,i); 460 return i; 461 }; 462 } 463 464 inline void LNiterator::push_ln(int i) 465 { 466 vector<int>& mpredecessors = mgraph[sgraph[i].mnode].pred; 467 for(vector<int>::iterator mp = mpredecessors.begin(); mp != mpredecessors.end(); ++mp) // poprzedniki w mgraph 468 { 469 vector<int>& spredecessors = mgraph[*mp].snodes; 470 for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) 471 { 472 wayup.push(*sp); 473 if(debug) fprintf(stderr,"\t\tLNiterator(%d)\tPUSH %d\n",snode,-1); 474 } 475 } 476 } 477 478 479 //---------------------------------------------------------------------------------------------------- 480 //---------------------------------------------------------------------------------------------------- 481 482 class LHiterator 483 { 484 public: 485 LHiterator(SGraph& sg, int n); 486 487 int next(); 488 489 private: 490 int snode; 491 SGraph& sgraph; 492 MGraph& mgraph; 493 stack<int> wayup; 494 495 void push_lh(int i); 496 }; 497 498 inline LHiterator::LHiterator(SGraph& sg, int n) : snode(n), sgraph(sg), mgraph(sg.mgraph) 499 { 500 push_lh(n); 501 } 502 503 inline int LHiterator::next() 504 { 505 if(wayup.empty()) 506 return -1; 366 507 else 367 508 { … … 373 514 } 374 515 375 inline void LViterator::push_ld(int i) 376 { 377 vector<Arc>& arcs = sgraph[i].deps; 378 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 379 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 380 push(waydown,a->dst); 381 } 382 383 inline void LViterator::push_lh(int i) 516 inline void LHiterator::push_lh(int i) 384 517 { 385 518 vector<Arc>& arcs = sgraph[i].heads; 386 519 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 387 520 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 388 push(wayup,a->dst); 389 } 390 391 inline void LViterator::push_ln(int i) 392 { 393 vector<int>& mpredecessors = mgraph[sgraph[i].mnode].pred; 394 for(vector<int>::iterator mp = mpredecessors.begin(); mp != mpredecessors.end(); ++mp) // poprzedniki w mgraph 395 { 396 vector<int>& spredecessors = mgraph[*mp].snodes; 397 for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) 398 if(sgraph[*sp].visible_as_neighbour || !strict) 399 push(wayup,*sp); 400 } 401 } 402 403 404 //---------------------------------------------------------------------------------------------------- 405 //---------------------------------------------------------------------------------------------------- 406 407 class LNiterator 521 { 522 wayup.push(a->dst); 523 if(debug) fprintf(stderr,"\t\tLHiterator(%d)\tPUSH %d\n",snode,-1); 524 } 525 } 526 527 //---------------------------------------------------------------------------------------------------- 528 //---------------------------------------------------------------------------------------------------- 529 530 class LDiterator 408 531 { 409 532 public: 410 L Niterator(SGraph& sg, int n);533 LDiterator(SGraph& sg, int n); 411 534 412 535 int next(); 413 536 414 537 private: 415 538 int snode; 416 539 SGraph& sgraph; 417 540 MGraph& mgraph; 418 int thenode;419 stack<int> wayup;420 421 void push_ln(int i);422 };423 424 inline LNiterator::LNiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), thenode(n)425 {426 push_ln(n);427 }428 429 inline int LNiterator::next()430 {431 if(wayup.empty())432 return -1;433 else434 {435 int i = wayup.top();436 wayup.pop();437 return i;438 };439 }440 441 inline void LNiterator::push_ln(int i)442 {443 vector<int>& mpredecessors = mgraph[sgraph[i].mnode].pred;444 for(vector<int>::iterator mp = mpredecessors.begin(); mp != mpredecessors.end(); ++mp) // poprzedniki w mgraph445 {446 vector<int>& spredecessors = mgraph[*mp].snodes;447 for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp )448 wayup.push(*sp);449 }450 }451 452 453 //----------------------------------------------------------------------------------------------------454 //----------------------------------------------------------------------------------------------------455 456 class LHiterator457 {458 public:459 LHiterator(SGraph& sg, int n);460 461 int next();462 463 private:464 465 SGraph& sgraph;466 MGraph& mgraph;467 stack<int> wayup;468 469 void push_lh(int i);470 };471 472 inline LHiterator::LHiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph)473 {474 push_lh(n);475 }476 477 inline int LHiterator::next()478 {479 if(wayup.empty())480 return -1;481 else482 {483 int i = wayup.top();484 wayup.pop();485 push_lh(i);486 return i;487 };488 }489 490 inline void LHiterator::push_lh(int i)491 {492 vector<Arc>& arcs = sgraph[i].heads;493 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a)494 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos)495 wayup.push(a->dst);496 }497 498 //----------------------------------------------------------------------------------------------------499 //----------------------------------------------------------------------------------------------------500 501 class LDiterator502 {503 public:504 LDiterator(SGraph& sg, int n);505 506 int next();507 508 private:509 510 SGraph& sgraph;511 MGraph& mgraph;512 int thenode;513 541 stack<int> waydown; 514 542 … … 516 544 }; 517 545 518 inline LDiterator::LDiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), thenode(n)546 inline LDiterator::LDiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), snode(n) 519 547 { 520 548 push_ld(n); … … 538 566 vector<Arc>& arcs = sgraph[i].deps; 539 567 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 540 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[thenode].mnode].pos) 541 waydown.push(a->dst); 542 } 543 544 568 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[snode].mnode].pos) 569 { 570 waydown.push(a->dst); 571 if(debug) fprintf(stderr,"\t\tLDiterator(%d)\tPUSH %d\n",snode,-1); 572 } 573 } 545 574 546 575 #endif
Note: See TracChangeset
for help on using the changeset viewer.