bool DroidObjectImplementation::isCombatDroid() {
	for( int i=0; i<modules.size(); i++){
		BaseDroidModuleComponent* module = modules.get(i);
		if(module->isCombatModule()) {
			return true;
		}
	}
	// inante comabt ability, regardless of module installed
	if (getSpecies() == PROBOT || getSpecies() == DZ70)
		return true;

	return false;
}
    void GeneticPopulation::adjustFitness() {
        speciate();

        for (int a = 0; a < (int) species.size(); a++) {
            species[a]->resetIndividuals();
        }

        for (int a = 0; a < generations[generations.size() - 1/*onGeneration*/]->getIndividualCount(); a++) {
            shared_ptr<GeneticIndividual> individual = generations[generations.size() - 1/*onGeneration*/]->getIndividual(a);

            getSpecies(individual->getSpeciesID())->addIndividual(individual);
        }

        for (int a = 0; a < (int) species.size(); a++) {
            if (species[a]->getIndividualCount() == 0) {
                //                extinctSpecies.push_back(species[a]);
                species.erase(species.begin() + a);
                a--;
            }
        }

        for (int a = 0; a < (int) species.size(); a++) {
            species[a]->setMultiplier();
            species[a]->setFitness();
            species[a]->incrementAge();
        }

        //This function sorts the individuals by fitness
        generations[generations.size() - 1/*onGeneration*/]->sortByFitness();
    }
Exemplo n.º 3
0
/* converting to l1 any hasOnlySubstanceUnits attributes should be removed */
void
Model::removeHasOnlySubstanceUnits()
{
  for (unsigned int i = 0; i < getNumSpecies(); i++)
  {
    getSpecies(i)->setHasOnlySubstanceUnits(false);
  }
}
Exemplo n.º 4
0
void testCreatePet() {
	Pet *p = createPet(1, "Bird", "Papagal", 200);
	assert(getId(p)==1);
	assert(strcmp(getType(p),"Bird")==0);
	assert(strcmp(getSpecies(p),"Papagal")==0);
	assert(getPrice(p)==200);
	distrugePet(p);
}
Exemplo n.º 5
0
/* adds species referred to in a KineticLaw to the ListOfModifiers
 * this will only be applicable when up converting an L1 model
 */
void 
Model::addModifiers ()
{
  //
  // Level 2/3 has a listOfModifiers associated with a Reaction
  // which are not listed in a L1 Model.
  // For each symbol in the Reaction's KineticLaw,
  // that symbol is a modifier iff:
  //
  //   1. It is defined as a Species in the Model
  //   2. It is not a Reactant or Product in this Reaction.
  //
  // Thus modifiers must be added where appropriate.
  //
  const char *id;

  unsigned int size;
  unsigned int n, l;

  const ASTNode *node;
  List          *names;
  KineticLaw* kl;

  for (n = 0; n < getNumReactions(); n++)
  {
    kl = getReaction(n)->getKineticLaw();

    if (kl == NULL || kl->isSetMath() == false) continue;
   
    node  = kl->getMath();
    names = node->getListOfNodes((ASTNodePredicate) ASTNode_isName);
    size  = names->getSize();

    for (l = 0; l < size; l++)
    {
      node = (ASTNode *) names->get(l);
      id   = node->getName();

      // 1. It is an AST_NAME (not AST_NAME_TIME), and
      if (node->getType() != AST_NAME) continue;

      // 2. It refers to a Species in this Model, and
      if (id == NULL || getSpecies(id) == NULL) continue;

      // 3. It is not a Reactant, Product, or (already) a Modifier
      if (getReaction(n)->getReactant(id) != NULL) continue;
      if (getReaction(n)->getProduct (id) != NULL) continue;
      if (getReaction(n)->getModifier(id) != NULL) continue;

      getReaction(n)->createModifier()->setSpecies(id);
    }

    delete names;
  }
}
Exemplo n.º 6
0
/* converting to l1 any metaid attributes should be removed */
void
Model::removeMetaId()
{
  unsigned int n, i;

  unsetMetaId();
  
  for (n = 0; n < getNumUnitDefinitions(); n++)
  {
    getUnitDefinition(n)->unsetMetaId();
    for (i = 0; i < getUnitDefinition(n)->getNumUnits(); i++)
    {
      getUnitDefinition(n)->getUnit(i)->unsetMetaId();
    }
  }

  for (n = 0; n < getNumCompartments(); n++)
  {
    getCompartment(n)->unsetMetaId();
  }

  for (n = 0; n < getNumSpecies(); n++)
  {
    getSpecies(n)->unsetMetaId();
  }

  for (n = 0; n < getNumParameters(); n++)
  {
    getParameter(n)->unsetMetaId();
  }

  for (n = 0; n < getNumRules(); n++)
  {
    getRule(n)->unsetMetaId();
  }

  for (n = 0; n < getNumReactions(); n++)
  {
    getReaction(n)->unsetMetaId();
    for (i = 0; i < getReaction(n)->getNumReactants(); i++)
    {
      getReaction(n)->getReactant(i)->unsetMetaId();
    }
    for (i = 0; i < getReaction(n)->getNumProducts(); i++)
    {
      getReaction(n)->getProduct(i)->unsetMetaId();
    }
    if (getReaction(n)->isSetKineticLaw())
    {
      getReaction(n)->getKineticLaw()->unsetMetaId();
    }
  }
}
Exemplo n.º 7
0
//Compare "Species" of 2 Organisms
bool Organism::compareSpecies(Organism other) const {
	unsigned int otherSpecies = other.getSpecies();
	unsigned int Species = getSpecies();

	//Add comparison of hash values here
	if ((std::max(Species, otherSpecies) - 
		std::min(Species, otherSpecies)) > DELTA) {
		return false;
	}

	else {
		return true;
	}
}
    void GeneticPopulation::produceNextGeneration() {


        cout << "In produce next generation loop...\n";
        //This clears the link history so future links with the same toNode and fromNode will have different IDs
        Globals::getSingleton()->clearNodeHistory();
        Globals::getSingleton()->clearLinkHistory();

        int numParents = int(generations[generations.size() - 1/*onGeneration*/]->getIndividualCount());

        //check that no org has fitness <= zero
        for (int a = 0; a < numParents; a++) {
            PRINT(generations[generations.size() - 1/*onGeneration*/]->getIndividual(a)->getFitness());

            if (generations[generations.size() - 1/*onGeneration*/]->getIndividual(a)->getFitness() < 1e-6) {
                throw CREATE_LOCATEDEXCEPTION_INFO("ERROR: Fitness must be a positive number!\n");
            }
        }


        double totalFitness = 0;

        //get sum of adjusted fitness for all species together
        for (int a = 0; a < (int) species.size(); a++) {
            totalFitness += species[a]->getAdjustedFitness();
        }
        int totalOffspring = 0;
        //give each species a fitness proportional to its adjusted fitness
        for (int a = 0; a < (int) species.size(); a++) {
            double adjustedFitness = species[a]->getAdjustedFitness();
            int offspring = int(adjustedFitness / totalFitness * numParents);
            totalOffspring += offspring;
            species[a]->setOffspringCount(offspring);
        }
        //cout << "Pausing\n";
        //int result = system("PAUSE");
        //(void) result;

        //Some offspring were truncated.  Give these N offspring to the species that had the best N individuals
        while (totalOffspring < numParents) {
            for (int a = 0; totalOffspring < numParents && a < generations[generations.size() - 1/*onGeneration*/]->getIndividualCount(); a++) {
                shared_ptr<GeneticIndividual> ind = generations[generations.size() - 1/*onGeneration*/]->getIndividual(a);
                shared_ptr<GeneticSpecies> gs = getSpecies(ind->getSpeciesID());
                gs->setOffspringCount(gs->getOffspringCount() + 1);
                totalOffspring++;

                /*
                //Try to give 2 offspring to the very best individual if it only has one offspring.
                //This fixes the problem where the best indiviudal sits in his own species
                //and duplicates every generation.
                if(a==0&&gs->getOffspringCount()==1&&totalOffspring<numParents)
                {
                gs->setOffspringCount(gs->getOffspringCount()+1);
                totalOffspring++;
                }*/

            }
        }

        //report stats on species
        for (int a = 0; a < (int) species.size(); a++) {
            cout << "Species ID: " << species[a]->getID() << " Age: " << species[a]->getAge() << " last improv. age: " << species[a]->getAgeOfLastImprovement() << " Fitness: " << species[a]->getFitness() << "*" << species[a]->getMultiplier() << "=" << species[a]->getAdjustedFitness() << " Size: " << int(species[a]->getIndividualCount()) << " Offspring: " << int(species[a]->getOffspringCount()) << endl;
        }

        //jmc: This is the new generation container
        vector<shared_ptr<GeneticIndividual> > babies;

        double totalIndividualFitness = 0;

        //jmc: clear the flag of whether they have reproduced (I think that is what that flag does.)
        for (int a = 0; a < (int) species.size(); a++) {
            species[a]->setReproduced(false);
        }

        int smallestSpeciesSizeWithElitism = int(Globals::getSingleton()->getParameterValue("SmallestSpeciesSizeWithElitism"));
        static double mutateSpeciesChampionProbability = Globals::getSingleton()->getParameterValue("MutateSpeciesChampionProbability");

        double ForceCopyGenerationChampionParamVal = Globals::getSingleton()->getParameterValue("ForceCopyGenerationChampion");
        bool forceCopyGenerationChampion = (ForceCopyGenerationChampionParamVal > Globals::getSingleton()->getRandom().getRandomDouble()); //getRandom between but not including 0 and 1 (Avida RNG and NEAT)


        for (int a = 0; a < generations[generations.size() - 1/*onGeneration*/]->getIndividualCount(); a++) //Go through and add the species champions (including ties for champ, which jmc added)
 {
            shared_ptr<GeneticIndividual> ind = generations[generations.size() - 1/*onGeneration*/]->getIndividual(a);
            shared_ptr<GeneticSpecies> species = getSpecies(ind->getSpeciesID());
            //            if (!species->isReproduced())  //original code assumed it would only store the champ of each species, so if this flag works. but it doesn't work to preserve ties for champ.
            if (!species->isReproduced() //jmc: if the species has not been checked yet to determine the fitness of its champ
                    || ind->getFitness() == species->getBestIndividual()->getFitness()) //or if the fitness of this org equals the species champ
            {
                species->setReproduced(true);

                //This is the first and best organism of this species to be added, so it's the species champion
                //of this generation
                if (ind->getFitness() > species->getBestIndividual()->getFitness()) {
                    //We have a new all-time species champion!
                    species->setBestIndividual(ind);
                    cout << "Species " << species->getID() << " has a new champ with fitness " << species->getBestIndividual()->getFitness() << endl;
                }

                if ((a == 0 && forceCopyGenerationChampion) || (species->getOffspringCount() >= smallestSpeciesSizeWithElitism)) {
                    //Copy species champion.
                    bool mutateChampion;
                    if (Globals::getSingleton()->getRandom().getRandomDouble() < mutateSpeciesChampionProbability)
                        mutateChampion = true;
                    else {
                        mutateChampion = false;
                    }
                    babies.push_back(shared_ptr<GeneticIndividual>(new GeneticIndividual(ind, mutateChampion, babies.size())));
                    species->decrementOffspringCount();
                }

                if (a == 0) {
                    species->updateAgeOfLastImprovement();
                }
            }
            totalIndividualFitness += ind->getFitness();
        }

        double averageFitness = totalIndividualFitness / generations[generations.size() - 1/*onGeneration*/]->getIndividualCount();
        cout << "Generation " << int(onGeneration) << ": " << "overall_average = " << averageFitness << endl;

#ifdef PRINT_GENETIC_PERTUBATION_INFO
        //print the gen number to this file
        ofstream mutationEffects_file;
        mutationEffects_file.open("mutationEffects.txt", ios::app);
        mutationEffects_file << "\nGeneration " << int(onGeneration + 1) << ": " << endl; //plus 1 cause we print this line to the file before this gens data
        mutationEffects_file.close();

        ofstream mutationAndCrossoverEffects_file;
        mutationAndCrossoverEffects_file.open("mutationAndCrossoverEffects.txt", ios::app);
        mutationAndCrossoverEffects_file << "\nGeneration " << int(onGeneration + 1) << ": " << endl; //plus 1 cause we print this line to the file before this gens data
        mutationAndCrossoverEffects_file.close();

        ofstream crossoverEffects_file;
        crossoverEffects_file.open("crossoverEffects.txt", ios::app);
        crossoverEffects_file << "\nGeneration " << int(onGeneration + 1) << ": " << endl; //plus 1 cause we print this line to the file before this gens data
        crossoverEffects_file.close();
#endif


        cout << "Champion fitness: " << generations[generations.size() - 1/*onGeneration*/]->getIndividual(0)->getFitness() << endl;

        if (generations[generations.size() - 1/*onGeneration*/]->getIndividual(0)->getUserData()) {
            cout << "Champion data: " << generations[generations.size() - 1/*onGeneration*/]->getIndividual(0)->getUserData()->summaryToString() << endl;
        }
        cout << "# of Species: " << int(species.size()) << endl;
        cout << "compat threshold: " << Globals::getSingleton()->getParameterValue("CompatibilityThreshold") << endl;

        for (int a = 0; a < (int) species.size(); a++) {
            //cout << "jmc: Making babies for species" << a << endl;
            species[a]->makeBabies(babies);
        }
        //cout << "jmc: done making babies\n";
        if ((int) babies.size() != generations[generations.size() - 1/*onGeneration*/]->getIndividualCount()) {
            cout << "Population size changed! (or there may have been a bad (or negative, or zero) fitness value for an organism?)\n";
            throw CREATE_LOCATEDEXCEPTION_INFO("Population size changed!");
        }

        cout << "Making new generation\n";
        shared_ptr<GeneticGeneration> newGeneration(generations[generations.size() - 1/*onGeneration*/]->produceNextGeneration(babies, onGeneration + 1));
        //cout << "Done Making new generation!\n";

        /*for(int a=0;a<4;a++)
        {
        for(int b=0;b<4;b++)
        {
        cout << babies[a]->getCompatibility(babies[b]) << '\t';
        }

        cout << endl;
        }*/

        generations.push_back(newGeneration);
        onGeneration++;
    }
Exemplo n.º 9
0
void
Model::removeDuplicateTopLevelAnnotations()
{
  unsigned int i, n;
  this->removeDuplicateAnnotations();

  if (getNumFunctionDefinitions() > 0)
  {
    getListOfFunctionDefinitions()->removeDuplicateAnnotations();
    for (i = 0; i < getNumFunctionDefinitions(); i++)
    {
      getFunctionDefinition(i)->removeDuplicateAnnotations();
    }
  }
  if (getNumUnitDefinitions() > 0)
  {
    getListOfUnitDefinitions()->removeDuplicateAnnotations();
    for (i = 0; i < getNumUnitDefinitions(); i++)
    {
      getUnitDefinition(i)->removeDuplicateAnnotations();
      getUnitDefinition(i)->getListOfUnits()->removeDuplicateAnnotations();
      for (n = 0; n < getUnitDefinition(i)->getNumUnits(); n++)
      {
        getUnitDefinition(i)->getUnit(n)->removeDuplicateAnnotations();
      }
    }
  }
  if (getNumCompartmentTypes() > 0)
  {
    getListOfCompartmentTypes()->removeDuplicateAnnotations();
    for (i = 0; i < getNumCompartmentTypes(); i++)
    {
      getCompartmentType(i)->removeDuplicateAnnotations();
    }
  }
  if (getNumSpeciesTypes() > 0)
  {
    getListOfSpeciesTypes()->removeDuplicateAnnotations();
    for (i = 0; i < getNumSpeciesTypes(); i++)
    {
      getSpeciesType(i)->removeDuplicateAnnotations();
    }
  }
  if (getNumCompartments() > 0)
  {
    getListOfCompartments()->removeDuplicateAnnotations();
    for (i = 0; i < getNumCompartments(); i++)
    {
      getCompartment(i)->removeDuplicateAnnotations();
    }
  }
  if (getNumSpecies() > 0)
  {
    getListOfSpecies()->removeDuplicateAnnotations();
    for (i = 0; i < getNumSpecies(); i++)
    {
      getSpecies(i)->removeDuplicateAnnotations();
    }
  }
  if (getNumParameters() > 0)
  {
    getListOfParameters()->removeDuplicateAnnotations();
    for (i = 0; i < getNumParameters(); i++)
    {
      getParameter(i)->removeDuplicateAnnotations();
    }
  }
  if (getNumInitialAssignments() > 0)
  {
    getListOfInitialAssignments()->removeDuplicateAnnotations();
    for (i = 0; i < getNumInitialAssignments(); i++)
    {
      getInitialAssignment(i)->removeDuplicateAnnotations();
    }
  }
  if (getNumConstraints() > 0)
  {
    getListOfConstraints()->removeDuplicateAnnotations();
    for (i = 0; i < getNumConstraints(); i++)
    {
      getConstraint(i)->removeDuplicateAnnotations();
    }
  }
  if (getNumRules() > 0)
  {
    getListOfRules()->removeDuplicateAnnotations();
    for (i = 0; i < getNumRules(); i++)
    {
      getRule(i)->removeDuplicateAnnotations();
    }
  }
  if (getNumReactions() > 0)
  {
    getListOfReactions()->removeDuplicateAnnotations();
    for (i = 0; i < getNumReactions(); i++)
    {
      Reaction * r = getReaction(i);
      r->removeDuplicateAnnotations();
      if (r->getNumReactants() > 0)
      {
        r->getListOfReactants()->removeDuplicateAnnotations();
        for (n = 0; n < r->getNumReactants(); n++)
        {
          r->getReactant(n)->removeDuplicateAnnotations();
        }
      }
      if (r->getNumProducts() > 0)
      {
        r->getListOfProducts()->removeDuplicateAnnotations();
        for (n = 0; n < r->getNumProducts(); n++)
        {
          r->getProduct(n)->removeDuplicateAnnotations();
        }
      }
      if (r->getNumModifiers() > 0)
      {
        r->getListOfModifiers()->removeDuplicateAnnotations();
        for (n = 0; n < r->getNumModifiers(); n++)
        {
          r->getModifier(n)->removeDuplicateAnnotations();
        }
      }
      if (r->isSetKineticLaw())
      {
        r->getKineticLaw()->removeDuplicateAnnotations();
        if (r->getKineticLaw()->getNumParameters() > 0)
        {
          r->getKineticLaw()->getListOfParameters()
                            ->removeDuplicateAnnotations();
          for (n = 0; n < r->getKineticLaw()->getNumParameters(); n++)
          {
            r->getKineticLaw()->getParameter(n)->removeDuplicateAnnotations();
          }
        }
      }
    }
  }
  if (getNumEvents() > 0)
  {
    getListOfEvents()->removeDuplicateAnnotations();
    for (i = 0; i < getNumEvents(); i++)
    {
      getEvent(i)->removeDuplicateAnnotations();
      if (getEvent(i)->getNumEventAssignments() > 0)
      {
        getEvent(i)->getListOfEventAssignments()->removeDuplicateAnnotations();
        for (n = 0; n < getEvent(i)->getNumEventAssignments(); n++)
        {
          getEvent(i)->getEventAssignment(n)->removeDuplicateAnnotations();
        }
      }
    }
  }
}
Exemplo n.º 10
0
void
Model::removeSBOTermsNotInL2V2(bool strict)
{
  unsigned int n, i;

  if (strict == true)
  {
    for (n = 0; n < getNumUnitDefinitions(); n++)
    {
      getUnitDefinition(n)->unsetSBOTerm();
      for (i = 0; i < getUnitDefinition(n)->getNumUnits(); i++)
      {
        getUnitDefinition(n)->getUnit(i)->unsetSBOTerm();
      }
    }

    for (n = 0; n < getNumCompartments(); n++)
    {
      getCompartment(n)->unsetSBOTerm();
    }

    for (n = 0; n < getNumSpecies(); n++)
    {
      getSpecies(n)->unsetSBOTerm();
    }

    for (n = 0; n < getNumCompartmentTypes(); n++)
    {
      getCompartmentType(n)->unsetSBOTerm();
    }

    for (n = 0; n < getNumSpeciesTypes(); n++)
    {
      getSpeciesType(n)->unsetSBOTerm();
    }


    for (n = 0; n < getNumReactions(); n++)
    {
      for (i = 0; i < getReaction(n)->getNumReactants(); i++)
      {
        if (getReaction(n)->getReactant(i)->isSetStoichiometryMath())
        {
          getReaction(n)->getReactant(i)->getStoichiometryMath()->unsetSBOTerm();
        }
      }
      for (i = 0; i < getReaction(n)->getNumProducts(); i++)
      {
        if (getReaction(n)->getProduct(i)->isSetStoichiometryMath())
        {
          getReaction(n)->getProduct(i)->getStoichiometryMath()->unsetSBOTerm();
        }
      }
    }

    for (n = 0; n < getNumEvents(); n++)
    {
      if (getEvent(n)->isSetTrigger())
      {
        getEvent(n)->getTrigger()->unsetSBOTerm();
      }
      if (getEvent(n)->isSetDelay())
      {
        getEvent(n)->getDelay()->unsetSBOTerm();
      }
    }
  }
}
Exemplo n.º 11
0
void
Model::removeSBOTerms(bool strict)
{
  unsigned int n, i;

  if (strict == true)
  {
    unsetSBOTerm();
    
    for (n = 0; n < getNumUnitDefinitions(); n++)
    {
      getUnitDefinition(n)->unsetSBOTerm();
      for (i = 0; i < getUnitDefinition(n)->getNumUnits(); i++)
      {
        getUnitDefinition(n)->getUnit(i)->unsetSBOTerm();
      }
    }

    for (n = 0; n < getNumCompartments(); n++)
    {
      getCompartment(n)->unsetSBOTerm();
    }

    for (n = 0; n < getNumSpecies(); n++)
    {
      getSpecies(n)->unsetSBOTerm();
    }

    for (n = 0; n < getNumParameters(); n++)
    {
      getParameter(n)->unsetSBOTerm();
    }

    for (n = 0; n < getNumRules(); n++)
    {
      getRule(n)->unsetSBOTerm();
    }

    for (n = 0; n < getNumReactions(); n++)
    {
      getReaction(n)->unsetSBOTerm();
      for (i = 0; i < getReaction(n)->getNumReactants(); i++)
      {
        getReaction(n)->getReactant(i)->unsetSBOTerm();
        if (getReaction(n)->getReactant(i)->isSetStoichiometryMath())
        {
          getReaction(n)->getReactant(i)->getStoichiometryMath()->unsetSBOTerm();
        }
      }
      for (i = 0; i < getReaction(n)->getNumProducts(); i++)
      {
        getReaction(n)->getProduct(i)->unsetSBOTerm();
        if (getReaction(n)->getProduct(i)->isSetStoichiometryMath())
        {
          getReaction(n)->getProduct(i)->getStoichiometryMath()->unsetSBOTerm();
        }
      }
      for (i = 0; i < getReaction(n)->getNumModifiers(); i++)
      {
        getReaction(n)->getModifier(i)->unsetSBOTerm();
      }
      if (getReaction(n)->isSetKineticLaw())
      {
        getReaction(n)->getKineticLaw()->unsetSBOTerm();
      }
    }

    for (n = 0; n < getNumFunctionDefinitions(); n++)
    {
      getFunctionDefinition(n)->unsetSBOTerm();
    }

    for (n = 0; n < getNumEvents(); n++)
    {
      getEvent(n)->unsetSBOTerm();
      for (i = 0; i < getEvent(n)->getNumEventAssignments(); i++)
      {
        getEvent(n)->getEventAssignment(i)->unsetSBOTerm();
      }
      if (getEvent(n)->isSetTrigger())
      {
        getEvent(n)->getTrigger()->unsetSBOTerm();
      }
      if (getEvent(n)->isSetDelay())
      {
        getEvent(n)->getDelay()->unsetSBOTerm();
      }
    }
  }
}
Exemplo n.º 12
0
/* in L1 and L2 there were built in values for key units
 * such as 'volume', 'length', 'area', 'substance' and 'time'
 * In L3 these have been removed - thus if a model uses one of these
 * it needs a unitDefinition to define it
 */
void
Model::addDefinitionsForDefaultUnits()
{
  /* create a list of unit values */
  IdList unitsUsed;
  unsigned int n;
  bool implicitVolume = false;
  bool implicitArea = false;
  bool implicitLength = false;
  bool implicitSubstance = false;

  for (n = 0; n < getNumCompartments(); n++)
  {
    if (getCompartment(n)->isSetUnits())
    {
      unitsUsed.append(getCompartment(n)->getUnits());
    }
    else
    {
      if (getCompartment(n)->getSpatialDimensions() == 3)
      {
        implicitVolume = true;
        getCompartment(n)->setUnits("volume");
      }
      else if (getCompartment(n)->getSpatialDimensions() == 2)
      {
        implicitArea = true;
        getCompartment(n)->setUnits("area");
      }
      else if (getCompartment(n)->getSpatialDimensions() == 1)
      {
        implicitLength = true;
        getCompartment(n)->setUnits("length");
      }
    }
  }

  for (n = 0; n < getNumSpecies(); n++)
  {
    if (getSpecies(n)->isSetSubstanceUnits())
    {
      unitsUsed.append(getSpecies(n)->getSubstanceUnits());
    }
    else
    {
      implicitSubstance = true;
      getSpecies(n)->setSubstanceUnits("substance");
    }
 
    if (getSpecies(n)->isSetSpatialSizeUnits())
      unitsUsed.append(getSpecies(n)->getSpatialSizeUnits());
  }

  for (n = 0; n < getNumParameters(); n++)
  {
    if (getParameter(n)->isSetUnits())
      unitsUsed.append(getParameter(n)->getUnits());
  }

  if (getUnitDefinition("volume") == NULL)
  {
    if (unitsUsed.contains("volume") || implicitVolume)
    {
      UnitDefinition * ud = createUnitDefinition();
      ud->setId("volume");
      Unit * u = ud->createUnit();
      u->setKind(UnitKind_forName("litre"));
      u->setScale(0);
      u->setExponent(1.0);
      u->setMultiplier(1.0);
      setVolumeUnits("volume");
    }
    else
    {
      setVolumeUnits("litre");
    }
  }
  else
  {
    setVolumeUnits("volume");
  }


  if (getUnitDefinition("substance") == NULL)
  {
    if (unitsUsed.contains("substance") || implicitSubstance)
    {
      UnitDefinition * ud = createUnitDefinition();
      ud->setId("substance");
      Unit * u = ud->createUnit();
      u->setKind(UnitKind_forName("mole"));
      u->setScale(0);
      u->setExponent(1.0);
      u->setMultiplier(1.0);
      setSubstanceUnits("substance");
      setExtentUnits("substance");
    }
    else
    {
      setSubstanceUnits("mole");
      setExtentUnits("mole");
    }
  }
  else
  {
    setSubstanceUnits("substance");
    setExtentUnits("substance");
  }

  if (getUnitDefinition("area") == NULL)
  {
    UnitDefinition * ud = createUnitDefinition();
    ud->setId("area");
    Unit * u = ud->createUnit();
    u->setKind(UnitKind_forName("metre"));
    u->setScale(0);
    u->setExponent(2.0);
    u->setMultiplier(1.0);
    setAreaUnits("area");
  }
  else
  {
    setAreaUnits("area");
  }

  if (getUnitDefinition("length") == NULL)
  {
    if (unitsUsed.contains("length") || implicitLength)
    {
      UnitDefinition * ud = createUnitDefinition();
      ud->setId("length");
      Unit * u = ud->createUnit();
      u->setKind(UnitKind_forName("metre"));
      u->setScale(0);
      u->setExponent(1.0);
      u->setMultiplier(1.0);
      setLengthUnits("length");
    }
    else
    {
      setLengthUnits("metre");
    }
  }
  else
  {
    setLengthUnits("length");
  }

  if (getUnitDefinition("time") == NULL)
  {
    setTimeUnits("second");
  }
  else
  {
    setTimeUnits("time");
  }

}
Exemplo n.º 13
0
void
Model::assignRequiredValues()
{
  // when converting to L3 some attributes which have default values in L1/L2
  // but are required in L3 are not present or set
  unsigned int i, n;

  if (getNumUnitDefinitions() > 0)
  {
    for (i = 0; i < getNumUnitDefinitions(); i++)
    {
      for (n = 0; n < getUnitDefinition(i)->getNumUnits(); n++)
      {
        Unit *u = getUnitDefinition(i)->getUnit(n);
        if (!u->isSetExponent())
          u->setExponent(1.0);
        if (!u->isSetScale())
          u->setScale(0);
        if (!u->isSetMultiplier())
          u->setMultiplier(1.0);
      }
    }
  }
  
  if (getNumCompartments() > 0)
  {
    for (i = 0; i < getNumCompartments(); i++)
    {
      Compartment *c = getCompartment(i);
      c->setConstant(c->getConstant());
    }
  }
  if (getNumSpecies() > 0)
  {
    for (i = 0; i < getNumSpecies(); i++)
    {
      Species * s = getSpecies(i);
      s->setBoundaryCondition(s->getBoundaryCondition());
      s->setHasOnlySubstanceUnits(s->getHasOnlySubstanceUnits());
      s->setConstant(s->getConstant());
    }
  }
  if (getNumParameters() > 0)
  {
    for (i = 0; i < getNumParameters(); i++)
    {
      Parameter * p = getParameter(i);
      p->setConstant(p->getConstant());
    }
  }
  if (getNumReactions() > 0)
  {
    for (i = 0; i < getNumReactions(); i++)
    {
      Reaction * r = getReaction(i);
      r->setFast(r->getFast());
      r->setReversible(r->getReversible());
      if (r->getNumReactants() > 0)
      {
        for (n = 0; n < r->getNumReactants(); n++)
        {
          SpeciesReference *sr = r->getReactant(n);
          if (sr->isSetStoichiometryMath())
          {
            sr->setConstant(false);
          }
          else
          {
            sr->setConstant(true);
          }
        }
      }
      if (r->getNumProducts() > 0)
      {
        for (n = 0; n < r->getNumProducts(); n++)
        {
          SpeciesReference *sr = r->getProduct(n);
          if (sr->isSetStoichiometryMath())
          {
            sr->setConstant(false);
          }
          else
          {
            sr->setConstant(true);
          }
        }
      }
    }
  }
  if (getNumEvents() > 0)
  {
    for (i = 0; i < getNumEvents(); i++)
    {
      Event * e = getEvent(i);
      e->setUseValuesFromTriggerTime(e->getUseValuesFromTriggerTime());

      if (e->isSetTrigger())
      {
        Trigger *t = e->getTrigger();
        t->setPersistent(true);
        t->setInitialValue(true);
      }
    }
  }

}
bool DroidObjectImplementation::isPowerDroid(){
	if(getSpecies() == 0)
		return getObjectTemplate()->getFullTemplateString().contains( "eg_6_power_droid" );
	else
		return POWER_DROID == getSpecies();
}
Exemplo n.º 15
0
//Maximum Energy the Organism may store
unsigned int Organism::maxEnergy() const {
	//Note: may want to update/tweak this in the future (add multiplier)
	return getSpecies();
}
Exemplo n.º 16
0
//This function is called each time it is your turn.
//Return true to end your turn, return false to ask the server for updated information.
bool AI::run()
{
  //loop through all of the tiles
  for(int i = 0;i < tiles.size();i++)
  {
    //if this tile is one of my coves and does not have a fish on it
    if(tiles[i].owner() == playerID() &&
       getFishIndex(tiles[i].x(), tiles[i].y()) == -1)
    {
       if(getSpecies(SEA_STAR).spawn(tiles[i].x(),tiles[i].y()))
          std::cout<<"I am fish"<<std::endl;
       /*
      //loop through all of the species
      for(int p = 0;p<species.size(); p++)
      {
        //if the current species is in season
        if(species[p].season() == currentSeason())
        {
          //if I have enough food to spawn the fish in and there is not
          //an egg on that tile already
          if(players[playerID()].spawnFood() >= species[p].cost() &&
             tiles[i].hasEgg() == false)
          {
            //spawn the fish on that tile
            species[p].spawn(tiles[i].x(), tiles[i].y());
          }
        }
      }*/
    }
  }

  //loop through all of the fish
  for(int i = 0;i < fishes.size();i++)
  {
    //if this is my fish
    if(fishes[i].owner() == playerID())
    {
      int x = fishes[i].x();
      int y = fishes[i].y();
      if(fishes[i].x() >= 1)
      {
        //if the tile to the left has trash and the current fish can
        //carry at least one more trash
        if(getTile(x - 1, y).trashAmount() > 0 &&
           fishes[i].carryingWeight() + 1 <= fishes[i].carryCap())
        {
          //if the fish has enought health to pick up trash
          if(1 * trashDamage() < fishes[i].currentHealth())
          {
            //pick up trash to the left of the fish
            fishes[i].pickUp(x - 1, y, 1);
          }
        }
      }
      //if the fish carrying any trash
      if(fishes[i].carryingWeight() > 0)
      {
        //if the fish in the enemy's side
        if((fishes[i].x() < mapWidth()/2 - boundLength() - 1 && enemyAI_ID == 0) ||
           (fishes[i].x() > mapWidth()/2 + boundLength() + 1 && enemyAI_ID == 1))
        {
          if(fishes[i].y() != 0)
          {
            //if the tile above the fish is not a cove and has no fish
            if(getTile(x, y - 1).owner() == 2 && getFishIndex(x, y + 1) == -1)
            {
              //drop all of the trash the fish is carrying
              fishes[i].drop(x, y - 1, fishes[i].carryingWeight());
            }
          }
          else if(fishes[i].y() != mapHeight() - 1)
          {
            //if the tile below the fish is not a cove and has no fish
            if(getTile(x,y + 1).owner() == 2 && getFishIndex(x,y + 1) == -1)
            {
              //drop all of the trash the fish is carrying
              fishes[i].drop(x, y + 1, fishes[i].carryingWeight());
            }
          }
        }
      }
      if(fishes[i].x() >= 1)
      {
        //if the tile to the left is not an enemy cove and there is no trash
        if(getTile(x - 1,y).owner() != enemyAI_ID &&
           getTile(x - 1,y).trashAmount() == 0)
        {
          //if the tile to the left does not have a fish and does not have an
          //egg
          if(getFishIndex(x - 1, y) == -1 &&
             getTile(x - 1, y).hasEgg() == false)
          {
            //move to the left
            fishes[i].move(x - 1, y);
          }
        }
        //get the fish to the left
        int target = getFishIndex(x - 1, y);
        //if there is a fish to the left and the fish has attacks left
        if(target != -1 && fishes[i].attacksLeft() > 0)
        {
          //if the fish is not a cleaner shrimp
          if(fishes[i].species() != CLEANER_SHRIMP)
          {
            //if the fish to the left is an enemy fish
            if(fishes[target].owner() == enemyAI_ID)
            {
               //attack the fish
               fishes[i].attack(fishes[target]);
            }
          }
          else
          {
             //this is if the fish is a cleaner shrimp

             //if the fish to the left is a friendly fish
             if(fishes[target].owner() != enemyAI_ID)
             {
                //heal the fish
                fishes[i].attack(fishes[target]);
             }
          }
        }
      }
    }
  }
  return true;
}