0

Hi I started a thread earlier back and I thought my problem had been solved but now new errors have popped up

Here are the errors I'm getting:
bfs.cc: In function 'void greedyMatch()':
bfs.cc:9: error: expected primary-expression before 'for'
bfs.cc:9: error: expected `)' before 'for'
bfs.cc:9: error: 'bfs_ee' was not declared in this scope
bfs.cc:9: error: 'bfs_stopA' was not declared in this scope
bfs.cc:9: error: expected `;' before ')' token
bfs_run.cc:83: error: expected `}' at end of input

The file bfs.cc is as follows:

#include <math.h>

void greedyMatch()
{
  Xnode *u;
  Ynode *v;
  arc *e;

  forallXNodes(u,G) {
    assert(!u->isMatched());
    forallOutArcs(e,u) {
#ifdef STATS
      stats.searchArcCnt++;
#endif
      v = e->head();

      if (!v->isMatched()) {
#ifdef STATS
        stats.mVal++;
        stats.greedCnt++;
        stats.flowArcCnt++;
#endif
        v->match(u);
        u->match(v);
        break;
      }
    }
  }
}

void augment(Ynode *last)
{
  Ynode *v, *v1;
  Xnode *w;
  arc *e;

  v = last;
  do
    {
      w = v->getCurrent();
#ifdef STATS
      stats.flowArcCnt++;
      stats.searchArcCnt++;
#endif
      v->match(w);
      if (w->isMatched())
        {
          v1 = w->getMatchNode();
          assert(v != v1);
          w->match(v);
          v = v1;
        }
      else
        {
          w->match(v);
          break;
        }
    }
  while (1);
#ifdef STATS
  stats.mVal++;
#endif
}

void bfsBIM(simpleQueue &Q, simpleQueue &S)
{
  Xnode *u, *w;
  Ynode *v;
  arc *e;
  bool foundPath;

  forallYNodes(v,G)
    {
      v->initialize();
#ifdef STATS
      stats.searchArcCnt++;
#endif
    }
  forallXNodes(u,G)
    {
      u->initialize();
      u->setReached(false);
#ifdef STATS
      stats.searchArcCnt++;
#endif
    }

  if (param.greedy) greedyMatch();

  forallXNodes(u,G)
    {
#ifdef STATS
      stats.searchArcCnt++;
#endif
      if (u->isMatched() || u->isReached()) continue;

      // start BFS from u
      foundPath = false;
      u->setReached(true);
      Q.enqueue(u);
      S.enqueue(u);
      do
        {
          u = Q.dequeue();
          forallOutArcs(e,u)
            {
#ifdef STATS
              stats.searchArcCnt++;
#endif
              v = e->head();
              if (v == G.getSource()) continue;
              if (v->isMatched())
                {
                  w = v->getMatchNode();
                  if (w->isReached()) continue; // includes w == u
                  assert(w != u);
                  v->setCurrent(u);
                  w->setReached(true);
                  Q.enqueue(w);
                  S.enqueue(w);
                }
              else
                {
                  foundPath = true;
                  v->setCurrent(u);
                  augment(v);
                  break;
                }
            }
        } while (!foundPath && !Q.isEmpty());

      // get ready to start new search
      Q.reinitialize();
      if (!foundPath)
        S.reinitialize(); //reached vertices remaine marked
      else
        {
          // clean up
          while (!S.isEmpty())
            {
              u = S.pop();
              assert(u->isMatched());
              u->setReached(false);
            }
        }
    }
}

The forallXnodes has been #defined in another file.This new file is visible in bfs.cc due to dependencies created by the make file .

#define forallXNodes(u,G) \ 
     (for( arc *bfs_ee=(G.getSource())->firstOutArc(),arc *bfs_stopA=\
     (G.getSource())->lastOutArc(),u=bfs_ee->head();bfs_ee<=bfs_stopA;u =\
     (++bfs_ee)->head()))

Any help shall be appreciated.......
I am using GNU g++ compiler.

Thanks,guys.

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Taywin
0

I strongly suggest trying to narrow the code down to the smallest piece that will give you that compiler error. From what you've posted, I can't tell that Xnode, Ynode, and arc are defined anywhere that the compiler should know about.

Why are you using this ghastly define? Why not make it a normal function?

Dave

1

Too many parentheses, says Ed. ;) Look at the expansion of the macro and you will see something like the following.

(for (<init>; <condition>; <increment>))
{
    <body>
}

Control flow statements are not expressions that can be wrapped in parentheses.

1

You can see what the macro expands to with

g++ -E filename.cpp>testfile

but again, why not just write the function? Have you really noticed a speed difference?

Dave

0

Hmm... Do you still need function prototype to be declared on the top of the file too??? Can't really remember...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.