int main()
{
    input();
    initCost();
    getCost();
    getAnswer();
    output();
    return 0;
}
Example #2
0
  void
    NavFn::setupNavFn(bool keepit)
    {
      // reset values in propagation arrays
      for (int i=0; i<ns; i++)
      {
        potarr[i] = POT_HIGH;
        if (!keepit) costarr[i] = COST_NEUTRAL;
        gradx[i] = grady[i] = 0.0;
      }

      // outer bounds of cost array
      COSTTYPE *pc;
      pc = costarr;
      for (int i=0; i<nx; i++)
        *pc++ = COST_OBS;
      pc = costarr + (ny-1)*nx;
      for (int i=0; i<nx; i++)
        *pc++ = COST_OBS;
      pc = costarr;
      for (int i=0; i<ny; i++, pc+=nx)
        *pc = COST_OBS;
      pc = costarr + nx - 1;
      for (int i=0; i<ny; i++, pc+=nx)
        *pc = COST_OBS;

      // priority buffers
      curT = COST_OBS;
      curP = pb1; 
      curPe = 0;
      nextP = pb2;
      nextPe = 0;
      overP = pb3;
      overPe = 0;
      memset(pending, 0, ns*sizeof(bool));

      // set goal
      int k = goal[0] + goal[1]*nx;
      initCost(k,0);

      // find # of obstacle cells
      pc = costarr;
      int ntot = 0;
      for (int i=0; i<ns; i++, pc++)
      {
        if (*pc >= COST_OBS)
          ntot++;			// number of cells that are obstacles
      }
      nobs = ntot;
    }
Example #3
0
int main()
{
    int i, j, wt, k, n, top;
    int stack[MAX];
    n = 7;
    for(i = 0; i < n; i++)
    {
        stack[i] = -1;
    }
    initCost();
    floyd(n);
    for(i = 0; i < n; i++)
    {
        for(j = 0; j < n; j++)
        {
            wt = weight[i][j];
            if( i != j && wt != MAXCOST)
            {
                printf("DIST(V%d,V%d)=%d\n", i+1, j+1, wt);
                //采用栈来输出最短路径所经过的顶点
                k = j;
                if(path[i][k] != 0)
                {
                    top = -1;
                    while(path[i][k] != 0)
                    {
                        stack[++top] = path[i][k];
                        k = path[i][k];
                    }
                    printf("V%d --> ", i+1);
                    while(top != -1)
                    {
                        printf("V%d", stack[top--]+1);
                        if(top != -1)
                            printf(" --> ");
                    }
                    printf(" --> V%d\n", j+1);
                }
                else
                {
                    printf("V%d --> V%d\n", i+1, j+1);
                }
            }
        }
    }
    return 0;
}
Example #4
0
int main()
{
    int i, j, n, v0, v;
    n = 7;
    initCost();
    printf("Input v0(-1 for quit): ");
    scanf("%d", &v0);
    v = v0 - 1;
    while(v != -2)
    {
        for(i = 0; i < n; i++)
            path[i] = -1;
        dijkstra(n, v);
        for(i = 0; i < n; i++)
        {
            if(i != v)
            {
                if(miniDistance[i] < MAXCOST)
                {
                    printf("DIST[%d, %d]=%d\n", v0, i+1, miniDistance[i]);
                    //输出最短路径所经过的顶点
                    printf("    V%d --> ", v0);
                    for(j = 0; path[j] != i; j++)
                    {
                        printf("V%d", path[j]+1);
                        if(path[j+1] != i)
                            printf(" --> ");
                    }
                    if(path[0] == i)
                        printf("V%d", i+1);
                    else
                        printf(" --> V%d", i+1);
                    printf("\n");
                }
                else
                {
                    printf("DIST[%d, %d]=NONE!\n", v0, i+1, miniDistance[i]);
                }
            }
        }
        printf("\nInput v0(-1 for quit): ");
        scanf("%d", &v0);
        v = v0 - 1;
    }
}
Example #5
0
bool
MPTreeMgr::readInput( const char * node , const char * pl , const char * net )
{
   Node * pNd1 , * pNd2;
   int arg1 , arg2 , move;

	cout << " >  readInput() : start reading input data\n";
	if ( !readNode     ( node )   )      return false;
	if ( !readPosition ( pl   )   )      return false;
	if ( !readNet      ( net  )   )      return false;
   buildInitMPTree();
   
   while ( !packMPTree() ) {
      pNd1 = pNd2 = NULL;
      arg1 = arg2 = -1;
      move = rand() % 4;
      perturbMPTree( &pNd1 , &pNd2 , &arg1 , &arg2 , move );
   }
   
   initCost();
	return true;
}