Exemplo n.º 1
0
Pathway PathwayHelper::create(CityPtr city, TilePos startPos, TilePos stopPos,
                              WayType type/*=roadOnly */, Size arrivedArea )
{
    switch( type )
    {
    case allTerrain:
    {
        const Tilemap& tmap = city->getTilemap();
        Pathway ret;
        Pathfinder::getInstance().getPath( tmap.at( startPos ), tmap.at( stopPos ), ret, 0, arrivedArea );

        return ret;
    }
    break;

    case roadFirst:
    {
        const Tilemap& tmap = city->getTilemap();
        Pathway ret;
        Pathfinder::getInstance().getPath( tmap.at( startPos ), tmap.at( stopPos ), ret, 0, arrivedArea );

        return ret;
    }
    break;

    default:
        break;
    }

    return Pathway();
}
Exemplo n.º 2
0
EFMGenerator::EFMGenerator(Network* net) {
  allPathways = Pathways();
  candidatePathways = Pathways();

  for(int i = 0; i < net->reactionCount; i++) {
	Pathway path = Pathway(net->s[i], i);
	allPathways.addPathway(path);
  }

  reactCount = net->reactionCount;
  metabCount = net->metaboliteCount;
  exterCount = net->externalMetaboliteCount;
  metabs = metabCount;

  metabsInPlay = (bool*) malloc(metabs * sizeof(bool));
  //std::fill_n(metabsInPlay, metabs, false);

  for(int i = 0; i < metabs; i++) {
	metabsInPlay[i] = true;
  }

  for(int i = 0; i < net->externalMetaboliteCount; i++) {
	metabsInPlay[net->externalMetabolite[i]] = false;
  } //Sets external metabolites to not be in play.
  
}
Exemplo n.º 3
0
inline Pathway Statistic::_Walkers::freeTile( TilePos target, TilePos currentPos, const int range ) const
{
  for( int currentRange=1; currentRange <= range; currentRange++ )
  {
    TilePos offset( currentRange, currentRange );
    gfx::TilesArray tiles = _parent.map.perimetr( currentPos - offset, currentPos + offset );
    tiles = tiles.walkables( true );

    float crntDistance = target.distanceFrom( currentPos );
    for( auto tile : tiles )
    {
      SmartList<T> eslist = _parent.rcity.walkers( tile->pos() ).select<T>();

      if( !eslist.empty() )
        continue;

      if( target.distanceFrom( tile->pos() ) > crntDistance )
        continue;

      Pathway pathway = PathwayHelper::create( currentPos, tile->pos(), PathwayHelper::allTerrain );
      if( pathway.isValid() )
      {
        return pathway;
      }
    }
  }

  return Pathway();
}
Exemplo n.º 4
0
void EFMGenerator::generateCombinations(int target) {
  //This is going to do both it and removeIOetc's job, because splitting
  //up these functions would require substantial duplication of work.

  //Remember to decrement metabs somewhere that it makes sense!

  Pathway** allps = allPathways.getPathwayArray();
  int pathCount = allPathways.getSize();
  Pathway** ins = (Pathway**) malloc(pathCount * sizeof(Pathway*));
  Pathway** outs = (Pathway**) malloc(pathCount* sizeof(Pathway*));
	//Doubly pessimistic allocation, but whatev's.
  int insCount = 0;
  int outsCount = 0;

  for(int i = 0; i < pathCount; i++) {
	double* coeffs = allps[i]->getCoefficients();
	
	if (coeffs[target] == 0) {break;}
	else if (coeffs[target] < 0) {
	  outs[outsCount] = allps[i];
	  outsCount++;
	} else if (coeffs[target] > 0) {
	  ins[insCount] = allps[i];
	  insCount++;
	} else {printf("Sanity check!"); exit(1);}
  }

  //Here's the generateCombinations part.

  for(int i = 0; i < insCount; i++) {
	for(int j = 0; j < outsCount; j++) {
	  candidatePathways.addPathway(Pathway(*(ins[i]), *(outs[j]), target));
	}
  }

  //And here's removeIOetc.

  for(int i = 0; i < insCount; i++) {
	allPathways.removePathway(ins[i]);
  }
  for(int i = 0; i < outsCount; i++) {
	allPathways.removePathway(outs[i]);
  }

  metabs--;  //Somehow this would be done better in Haskell.
}
Exemplo n.º 5
0
Pathway PathwayHelper::randomWay(CityPtr city, TilePos startPos, int walkRadius)
{
    int loopCounter = 0; //loop limiter
    do
    {
        const Tilemap& tmap = city->getTilemap();

        TilePos destPos( std::rand() % walkRadius - walkRadius / 2, std::rand() % walkRadius - walkRadius / 2 );
        destPos = (startPos+destPos).fit( TilePos( 0, 0 ), TilePos( tmap.getSize()-1, tmap.getSize()-1 ) );

        if( tmap.at( destPos ).isWalkable( true) )
        {
            Pathway pathway = create( city, startPos, destPos, PathwayHelper::allTerrain );

            if( pathway.isValid() )
            {
                return pathway;
            }
        }
    }
    while( ++loopCounter < 20 );

    return Pathway();
}