source: src/dgp/dgp1.cc @ 519eaf5

Last change on this file since 519eaf5 was 519eaf5, checked in by Tomasz Obrebski <obrebski@…>, 10 years ago

Bug fixes: bubbles,props

  • Property mode set to 100644
File size: 20.4 KB
Line 
1#include <iostream>
2using namespace std;
3
4#include "dgp0.hh"
5#include "global.hh"
6
7extern Grammar grammar;
8extern MGraph mgraph;
9extern SGraph sgraph;
10
11extern bool debug;
12
13list<int> nodelist;
14list<int>::iterator processed;
15
16
17void print_sets(int n);
18
19
20//====================================================================================================
21
22void set_initial_constraints(int node)
23{
24  sgraph[node].prop.forbidden.reset();
25  sgraph[node].prop.required=grammar.is_obl(sgraph.cat(node));
26  sgraph[node].prop.attached.reset();
27  sgraph[node].prop.flags=grammar.initial_flags(sgraph.cat(node));
28}
29
30//----------------------------------------------------------------------------------------------------
31
32bool changing_constraints(int head, Role role)
33{
34  return grammar.is_sgl(role) || sgraph[head].prop.required[role];
35}
36
37//====================================================================================================
38
39NodeProp compute_head_prop(NodeProp headprop, const Link& link, list<Boubble*> bs, FlagSet& depflags)
40{
41  NodeProp ret=headprop;
42
43  if(grammar.is_sgl(link.role))
44    {
45      ret.forbidden.set(link.role);
46      ret.attached.set(link.role);
47    }
48  ret.required.reset(link.role);
49
50  ret.required |= (grammar.constr_include(link.role) & ~ret.attached);
51  ret.forbidden |= grammar.constr_exclude(link.role);
52
53  ret.boubbles.merge(bs); //DOBRZE
54  ret.flags |= ( depflags & grammar.pass_flags(link.role) );
55
56  if(link.props[Prop("INIT")]) ret.init_attached=true;
57  if(link.props[Prop("FIN")]) ret.fin_attached=true;
58
59  return ret;
60}
61
62//----------------------------------------------------------------------------------------------------
63
64NodeProp compute_dep_prop(NodeProp depprop, const Link& link, list<Boubble*> bs)
65{
66  NodeProp ret=depprop;
67  ret.boubbles.merge(bs); //DOBRZE
68  return ret;
69}
70
71//====================================================================================================
72
73int 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            fprintf(stderr,"#\tsucceeded because of LH/LV equality ()\n");
85          }
86        else
87          {
88            fprintf(stderr,"#\tfailed beacause of LH/LV inequality\n");
89          }
90    }
91
92  if(debug) fprintf(stderr,"\n");
93  return ret;
94}
95
96//====================================================================================================
97
98list<Boubble*> receive_boubbles(int node, Role role, Dir dir)
99{
100  list<Boubble*> ret;
101  for(list<Boubble*>::iterator b = sgraph[node].prop.boubbles.begin(); b!=sgraph[node].prop.boubbles.end(); b++)
102    {
103      Boubble* new_boubble = (*b)->step(role,dir);
104      if(new_boubble)
105        ret.push_back(new_boubble);
106    }
107
108  return ret;
109}
110
111//----------------------------------------------------------------------------------------------------
112
113list<Boubble*> collect_head_boubbles(int head, int dep, Role role)
114{
115  list<Boubble*> new_boubbles = grammar.trigger_boubbles(sgraph.cat(dep),role,UP);
116 
117  for(list<Boubble*>::iterator b = new_boubbles.begin(); b != new_boubbles.end(); b++)
118    (*b)->src(dep);
119
120  list<Boubble*> received_boubbles = receive_boubbles(dep,role,UP);
121
122  new_boubbles.insert(new_boubbles.begin(),received_boubbles.begin(),received_boubbles.end());
123
124  return new_boubbles;
125}
126
127//----------------------------------------------------------------------------------------------------
128
129list<Boubble*> collect_dep_boubbles(int head, int dep, Role role)
130{
131  list<Boubble*> new_boubbles = grammar.trigger_boubbles(sgraph.cat(head), role, DOWN);
132 
133  for(list<Boubble*>::iterator b = new_boubbles.begin(); b != new_boubbles.end(); b++)
134    (*b)->src(head);
135
136  list<Boubble*> received_boubbles = receive_boubbles(head,role,DOWN);
137
138  new_boubbles.insert(new_boubbles.begin(),received_boubbles.begin(),received_boubbles.end());
139
140  return new_boubbles;
141}
142
143//====================================================================================================
144
145void copy_links(int i, int j)
146{
147  sgraph[j].heads = sgraph[i].heads;
148  sgraph[j].deps = sgraph[i].deps;
149}
150
151
152void create_reverse_links(int n)
153{
154  for(vector<Arc>::iterator a=sgraph[n].heads.begin(); a != sgraph[n].heads.end(); a++)
155    sgraph[a->dst].deps.push_back(Arc(n,a->role,a->headanc,a->depanc));
156
157  for(vector<Arc>::iterator a=sgraph[n].deps.begin(); a != sgraph[n].deps.end(); a++)
158    sgraph[a->dst].heads.push_back(Arc(n,a->role,a->headanc,a->depanc));
159}
160
161//====================================================================================================
162
163int 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);
166  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  copy_links(anc,newheadind);
173  create_reverse_links(newheadind);
174 
175  if(debug) sgraph.print_node_debug(stderr,"add new",newheadind,anc);
176  // if(debug) print_sets(newheadind);
177  return newheadind;
178}
179
180int 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
198int 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
216int 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//====================================================================================================
235
236void connect_left(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles)
237{
238
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
257      {
258        newheadind = create_new_head_node_left(h,newheadprop,newheadLH,newheadLD,newheadLV);
259        sgraph[newheadind].edge.clear();
260        sgraph[newheadind].edge_contains_self = false;
261      }
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
308void 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// }
418
419//====================================================================================================
420
421bool check_meeting_boubles(list<Boubble*>& boubbles)
422{
423  bool hremove=false;             // czy usun±æ ostatnio sprawdzany b±bel
424  bool dremove=false;             // czy usun±æ ostatnio sprawdzany b±bel
425
426  for(list<Boubble*>::iterator hb = boubbles.begin(); hb != boubbles.end(); hb = hremove ? boubbles.erase(hb) : ++hb )
427    {
428      cout << endl << "hb:" << **hb ;
429      hremove=false;
430      for(list<Boubble*>::iterator db = hb; db != boubbles.end(); db = dremove ? boubbles.erase(db) : ++db )
431        {
432          cout << " db:" << **db;
433          dremove=false;
434          if( (*hb)->rel()==(*db)->rel() && (*hb)->reverse()!=(*db)->reverse() )
435            {
436              cout << "Z";
437              int srcnode,dstnode;
438              if( (*hb)->reverse()==false )
439                srcnode = (*hb)->src(), dstnode = (*db)->src();
440              else
441                srcnode = (*db)->src(), dstnode = (*hb)->src();
442              if( grammar.check_longrel(sgraph.cat(srcnode), sgraph.cat(dstnode), (*hb)->rel()) )
443                {
444                  cout << " REMOVE ";
445                  hremove=dremove=true;
446                  if(debug) fprintf(stderr,"BOUBBLES MET!!!\n");
447                }
448              else
449                {
450                  cout << " FAIL ";
451                  if(debug) fprintf(stderr,"BOUBBLES' MEETING FAILED!!!\n");
452                  return false;
453                }
454            }
455        }
456    }
457  return true;
458}
459
460//====================================================================================================
461
462// sprawdza czy te, spo¶ród b±bli, które dotar³y do celu node
463// daj± wynik prawdziwy, dodatkowo - usuwa je z listy boubbles
464
465bool check_boubbles_at_target(list<Boubble*>& boubbles, int node)
466{
467  bool remove=false;             // czy usun±æ ostatnio sprawdzany b±bel
468
469  for(list<Boubble*>::iterator b = boubbles.begin(); b != boubbles.end(); b = remove ? boubbles.erase(b) : ++b )
470    if( (*b)->is_at_target() )
471      if( grammar.check_longrel(sgraph.cat((*b)->src()), sgraph.cat(node), (*b)->rel()) )
472        {
473          cout << endl << "REMOVE ChBatT " << **b << endl;
474          remove=true;
475        }
476      else
477        return false;
478    else
479      remove=false;
480     
481  return true;
482}
483
484//====================================================================================================
485
486void try_connect_dependents(int j)
487{
488  LViterator lvi(sgraph,j);
489  int i;
490  while((i=lvi.next()) >= 0)
491    {
492      //if(debug) sgraph.print_node_debug(stderr,"D-CUR>",i,-1);
493
494      if(sgraph.saturated(i))
495        {
496          if(debug) {fprintf(stderr,"%d <--",i); }
497         
498          list<const Link*> ji_links = grammar.connectable2( sgraph.cat(j), sgraph.cat(i), sgraph[j].prop.flags, sgraph[i].prop.flags); // ref do Roles!!!
499          list<const Link*>::iterator ri = ji_links.begin();
500          if(ri == ji_links.end()) { if(debug) fprintf(stderr,"     no roles\n"); }
501          else
502            {
503              for(; ri != ji_links.end(); ++ri )
504                {
505                  if(debug) fprintf(stderr,"     %s",(*ri)->role.str());
506                  if(!grammar.check_constr2(sgraph[j].prop,sgraph[i].prop,0,**ri ))
507                    { if(debug) fprintf(stderr," ...constraints failed\n"); }
508                  else
509                    {
510                      list<Boubble*> new_head_boubbles = collect_head_boubbles(j,i,(*ri)->role);
511                      list<Boubble*> new_dep_boubbles = collect_dep_boubbles(j,i,(*ri)->role);
512                      if( check_meeting_boubles(new_head_boubbles) &&
513                          check_meeting_boubles(new_dep_boubbles) &&
514                          check_boubbles_at_target(new_head_boubbles,j) &&
515                          check_boubbles_at_target(new_dep_boubbles,i) )
516                        {
517                          if(debug) fprintf(stderr," ...SUCCESS!\n");
518                          connect_left( j, i, **ri, new_head_boubbles, new_dep_boubbles);
519                        }
520                      else
521                        { if(debug) fprintf(stderr," ...boubbles failed\n"); }
522                    }
523                }
524            }
525        }
526      else
527          if(debug) {fprintf(stderr,"%d <--     unsaturated\n",i); }
528    }
529 
530}
531//----------------------------------------------------------------------------------------------------
532
533void try_connect_heads(int j)
534{
535  LViterator lvi(sgraph,j);
536  int i;
537  while((i=lvi.next()) >= 0)
538    {
539      // if(debug) sgraph.print_node_debug(stderr,"H-CUR> ",i,-1);
540      if(sgraph.saturated(j))
541        {
542          if(debug) fprintf(stderr, "%d -->",i);
543         
544          list<const Link*> ij_links = grammar.connectable2( sgraph.cat(i), sgraph.cat(j), sgraph[i].prop.flags, sgraph[j].prop.flags );
545          list<const Link*>::iterator ri = ij_links.begin();
546          if(ri == ij_links.end()) { if(debug) fprintf(stderr,"     no roles\n"); }
547          else
548            {
549              for(; ri != ij_links.end(); ++ri )
550                {
551                  if(debug) fprintf(stderr,"     %s",(*ri)->role.str());
552                  if( !grammar.check_constr2( sgraph[i].prop, sgraph[j].prop, 1, **ri ) )
553                    { if(debug) fprintf(stderr," ...constraints failed\n"); }
554                  else
555                    {
556                      list<Boubble*> new_head_boubbles = collect_head_boubbles(i,j,(*ri)->role);
557                      list<Boubble*> new_dep_boubbles = collect_dep_boubbles(i,j,(*ri)->role);
558                     
559                      if( check_meeting_boubles(new_head_boubbles) &&
560                          check_meeting_boubles(new_dep_boubbles) &&
561                          check_boubbles_at_target(new_head_boubbles,i) &&
562                          check_boubbles_at_target(new_dep_boubbles,j) )
563                        {
564                          if(debug) fprintf(stderr," ...SUCCESS!\n");
565                          connect_right( i, j, **ri, new_head_boubbles, new_dep_boubbles );
566                        }
567                      else
568                        { if(debug) fprintf(stderr," ...bubbles failed\n",i); }
569                    }
570                }
571            }
572        }
573      else
574          if(debug) {fprintf(stderr,"%d <--     unsaturated\n",j); }
575    }
576}
577
578//====================================================================================================
579
580void update_sets()
581{
582  for(int n=0; n<sgraph.size(); ++n)
583    {
584      LViterator lvi(sgraph,n,false);
585      LHiterator lhi(sgraph,n);
586      LDiterator ldi(sgraph,n);
587      int i;
588
589      // printf("UPDATING LV[%d]:",n);
590      while((i=lvi.next())>=0)
591        {
592          // printf(" %d",i);
593          sgraph[n].LV.set(i);
594        }
595      // printf("\n");
596
597      while((i=lhi.next())>=0) sgraph[n].LH.set(i);
598      while((i=ldi.next())>=0) sgraph[n].LD.set(i);
599    }
600}
601
602//====================================================================================================
603
604void print_sets(int n)
605{
606  LViterator lvi(sgraph,n);
607  LHiterator lhi(sgraph,n);
608  LDiterator ldi(sgraph,n);
609 
610  int i; 
611  printf("LV[%d]: ",n);
612  while((i=lvi.next())>=0)
613        {
614          printf("%d ",i);
615          sgraph[n].LV.set(i);
616        }
617
618  printf("LH[%d]: ",n);
619  while((i=lhi.next())>=0)
620    {
621      printf("%d ",i);
622      sgraph[n].LH.set(i);
623    }
624  printf("LD[%d]: ",n);
625  while((i=ldi.next())>=0)
626    {
627      printf("%d ",i);
628      sgraph[n].LD.set(i);
629    }
630  printf("\n");
631}
632
633//====================================================================================================
634
635void reverse_links()
636{
637  list<int>::iterator i = nodelist.begin();
638  for(++i; i!=nodelist.end(); ++i)
639    {
640      for(vector<Arc>::iterator da=sgraph[*i].deps.begin()--; da!=sgraph[*i].deps.end(); ++da)
641        sgraph[da->dst].heads.push_back(Arc(*i,da->role,da->headanc,da->depanc));
642      for(vector<Arc>::iterator ha=sgraph[*i].heads.begin(); ha!=sgraph[*i].heads.end(); ++ha)
643        sgraph[ha->dst].deps.push_back(Arc(*i,ha->role,ha->headanc,ha->depanc));
644    }
645}
646
647//====================================================================================================
648
649void dgp1()
650{
651
652  nodelist.clear();
653  nodelist.push_back(0); // BOS
654  processed=nodelist.begin();
655
656  for(int m=0; m<mgraph.size() ; ++m)
657  {
658    int basenode = sgraph.add_base_snode(m); // ma zwracaæ SNode*
659
660    set_initial_constraints(basenode);
661    nodelist.push_back(basenode);
662
663    if(debug) sgraph.print_node_debug(stderr,"add base",basenode,-1); // STDOUT!!!
664    // if(debug) print_sets(basenode);
665
666    list<int>::iterator cursor=processed;
667    while(++cursor != nodelist.end())
668    {
669      if(debug) sgraph.print_node_debug(stderr,"MAIN-CUR> ",*cursor,-1);
670      try_connect_dependents(*cursor);
671      try_connect_heads(*cursor);
672      processed=cursor;
673    }
674
675  }
676   // reverse_links();
677  update_sets();
678}
Note: See TracBrowser for help on using the repository browser.