コード例 #1
0
ファイル: augmentPath.c プロジェクト: Jobbernowle/Graphs
int augmentPath(t_graph* resNet, int v, int t, int flow)
{
  int n,min;
  if(resNet!=NULL && !resNet->vertices[v].visited)
    {
      if(v==t)
	return flow;
      resNet->vertices[v].visited=TRUE;
      for(n=nextNeighbor(resNet,v,-1);n<resNet->v;n=nextNeighbor(resNet,v,n))
	{
	  if(!resNet->vertices[n].visited)
	    {
	      if(resNet->am[v][n]<flow)
		min=resNet->am[v][n];
	      else
		min=flow;
	    }
	      if((min=augmentPath(resNet,n,t,min))>0)
	    {
	      if(resNet->am[v][n]!=INF)
		resNet->am[v][n] -= min;
	      if(resNet->am[n][v]!=INF)
		resNet->am[n][v] += min;
	      return min;
	    }
	}
      return 0;
    }
}
コード例 #2
0
int jumpPointTools::jump(const map& a_map, const std::pair<int, Direction> a_neighbor, std::pair<int, Direction>& a_jumpPoint, const int a_targetPosition, const int* a_oneStepMove) 
{
  // if it's an obstacle
  if (!a_map[a_neighbor.first])
    {
      return -1;
    }
  if (a_neighbor.first == a_targetPosition)
    {
      a_jumpPoint = a_neighbor;
      return 1;
    }
  // really have no use for this except need it to call the function
  std::vector<std::pair<int, Direction> > dummy;
  if (findForcedNeighbors(a_map, a_neighbor.first, a_neighbor.second, dummy, a_oneStepMove))
    {
      a_jumpPoint = a_neighbor;
      return 1;
    }
  // if this came from a diagonal guy check the 2 straight directions
  Direction decompose [2];
  if (dirHelper.decomposeDiagonal(a_neighbor.second,decompose))
    {
      for (int j = 0; j < 2; j++)
	{
	  std::pair<int, Direction> nextNeighbor(a_neighbor.first + a_oneStepMove[decompose[j]], decompose[j]);
	  if (jump(a_map, nextNeighbor, a_jumpPoint, a_targetPosition, a_oneStepMove) == 1)
	    {
	      a_jumpPoint = a_neighbor;
	      return 1;
	    }
	}
    }

  // the next guy to check traversing in this direction
  std::pair<int, Direction> nextNeighbor(a_neighbor.first + a_oneStepMove[a_neighbor.second], a_neighbor.second);

  return jump(a_map, nextNeighbor, a_jumpPoint, a_targetPosition, a_oneStepMove);

}
コード例 #3
0
int jumpPointTools::jump(const map& a_map, const std::pair<int, Direction> a_neighbor, std::tuple<int, Direction, bool>& a_jumpPoint, const int* a_oneStepMove) 
{
  // if it's an obstacle, then the previous guy is a sterile jump point
  if (!a_map[a_neighbor.first])
    {
      int previousPosition = a_neighbor.first - a_oneStepMove[a_neighbor.second];
      a_jumpPoint = std::make_tuple(previousPosition, a_neighbor.second, false);
      return -1;
    }
  // really have no use for this except need it to call the function
  std::vector<std::pair<int, Direction> > dummy;
  if (findForcedNeighbors(a_map, a_neighbor.first, a_neighbor.second, dummy, a_oneStepMove))
    {
      a_jumpPoint = std::make_tuple(a_neighbor.first, a_neighbor.second, true);
      return 1;
    }
  // if this came from a diagonal guy check the 2 straight directions
  Direction decompose [2];
  if (dirHelper.decomposeDiagonal(a_neighbor.second,decompose))
    {
      for (int j = 0; j < 2; j++)
	{
	  std::pair<int, Direction> nextNeighbor(a_neighbor.first + a_oneStepMove[decompose[j]], decompose[j]);
	  if (jump(a_map, nextNeighbor, a_jumpPoint, a_oneStepMove) == 1)
	    {
	      a_jumpPoint = std::make_tuple(a_neighbor.first, a_neighbor.second, true);
	      return 1;
	    }
	}
    }

  // the next guy to check traversing in this direction
  std::pair<int, Direction> nextNeighbor(a_neighbor.first + a_oneStepMove[a_neighbor.second], a_neighbor.second);

  return jump(a_map, nextNeighbor, a_jumpPoint, a_oneStepMove);
}