int main() {
  Genes machineGenes0{0,0,1};
  Genes bufferGenes0{0,0,1};
  Genes axleGenes0{0,1,1};
  UnitGene unitGenes0{machineGenes0, bufferGenes0, axleGenes0};

  Genes machineGenes1{0,1,0};
  Genes bufferGenes1{0,0,1};
  Genes axleGenes1{0,1,0};
  UnitGene unitGenes1{machineGenes1, bufferGenes1, axleGenes1};

  Genes machineGenes2{0,1,0};
  Genes bufferGenes2{0,0,1};
  Genes axleGenes2{0,1};
  UnitGene unitGenes2{machineGenes2, bufferGenes2, axleGenes2};

  Genes machineGenes3{0,1,0};
  Genes bufferGenes3{0,0,1};
  Genes axleGenes3{0,1,0};
  UnitGene unitGenes3{machineGenes3, bufferGenes3, axleGenes3};

  Individual individual{unitGenes0, unitGenes1, unitGenes2, unitGenes3};

  std::vector<std::vector<double>> missionData;
  void LoadMission(std::vector<std::vector<double>>& );
  LoadMission(missionData);

  std::shared_ptr<Combination> newCombination(new Combination(individual, missionData));
  newCombination->RunMission();
  return 0;
}
예제 #2
0
std::vector<std::list<Parameterization> > ParameterizedCommand::ExpandParameters(
    unsigned int startIndex, const std::vector<IParameter::Pointer>& parameters)
{
  typedef std::vector<std::list<Parameterization> > ReturnType;

  const unsigned int nextIndex = startIndex + 1;
  const bool noMoreParameters = (nextIndex >= parameters.size());

  const IParameter::Pointer parameter(parameters[startIndex]);
  ReturnType parameterizations;

  if (parameter->IsOptional())
  {
    parameterizations.push_back(std::list<Parameterization>());
  }

  IParameter::ParameterValues parameterValues(parameter->GetValues());
  for (IParameter::ParameterValues::iterator parameterValueItr =
      parameterValues.begin(); parameterValueItr != parameterValues.end(); ++parameterValueItr)
  {
    std::list<Parameterization> combination;
    combination.push_back(
        Parameterization(parameter, parameterValueItr->second));
    parameterizations.push_back(combination);
  }

  // Check if another iteration will produce any more names.
  if (noMoreParameters)
  {
    // This is it, so just return the current parameterizations.
    return parameterizations;
  }

  // Make recursive call
  ReturnType suffixes(ExpandParameters(nextIndex, parameters));
  if (suffixes.empty())
  {
    // This is it, so just return the current parameterizations.
    return parameterizations;
  }

  ReturnType returnValue;
  for (ReturnType::iterator suffixItr = suffixes.begin(); suffixItr
      != suffixes.end(); ++suffixItr)
  {
    for (ReturnType::iterator combinationItr = parameterizations.begin(); combinationItr
        != parameterizations.end(); ++combinationItr)
    {
      std::list<Parameterization> newCombination(*combinationItr);
      newCombination.insert(newCombination.end(), suffixItr->begin(),
          suffixItr->end());
      returnValue.push_back(newCombination);
    }
  }

  return returnValue;
}
double EvaluateIndividualFitness(Individual individual, std::vector<std::vector<double>>& missionData) {
 double fitness=0;
 /*int numberOfUnits = individual.size();
 for(int i=0;i<numberOfUnits;i++) {
	UnitGene unitGenes = individual[i];      // Tractor or Trailing Unit Genes 
  int numberOfGeneSets = unitGenes.size(); // Normally 2 for tractor unit & 3 for trailing unit
  for(int j=0;j<numberOfGeneSets;j++) {
    Genes genesSingleSet = unitGenes[j];
    int numberOfGenes = genesSingleSet.size();
    for(int k=0;k<numberOfGenes;k++)
     fitness+=genesSingleSet[k];
    }
  }//*/
  std::shared_ptr<Combination> newCombination(new Combination(individual, missionData));
  newCombination->RunMission();
  fitness = newCombination->missionProductivity;
  return fitness;
}
예제 #4
0
QList<QList<Parameterization> > ParameterizedCommand::ExpandParameters(
    unsigned int startIndex, const QList<IParameter::Pointer>& parameters)
{
  typedef QList<QList<Parameterization> > ReturnType;

  const int nextIndex = startIndex + 1;
  const bool noMoreParameters = (nextIndex >= parameters.size());

  const IParameter::Pointer parameter(parameters[startIndex]);
  ReturnType parameterizations;

  if (parameter->IsOptional())
  {
    parameterizations.push_back(QList<Parameterization>());
  }

  IParameterValues* values = NULL;
  try
  {
    values = parameter->GetValues();
  }
  catch (const ParameterValuesException& /*e*/)
  {
    if (noMoreParameters)
    {
      return parameterizations;
    }

    // Make recursive call
    return ExpandParameters(nextIndex, parameters);
  }

  const QHash<QString,QString> parameterValues = values->GetParameterValues();
  for (IParameter::ParameterValues::const_iterator parameterValueItr =
      parameterValues.begin(); parameterValueItr != parameterValues.end(); ++parameterValueItr)
  {
    QList<Parameterization> combination;
    combination.push_back(
        Parameterization(parameter, parameterValueItr.value()));
    parameterizations.push_back(combination);
  }

  // Check if another iteration will produce any more names.
  if (noMoreParameters)
  {
    // This is it, so just return the current parameterizations.
    return parameterizations;
  }

  // Make recursive call
  ReturnType suffixes(ExpandParameters(nextIndex, parameters));
  if (suffixes.empty())
  {
    // This is it, so just return the current parameterizations.
    return parameterizations;
  }

  ReturnType returnValue;
  for (ReturnType::iterator suffixItr = suffixes.begin(); suffixItr
      != suffixes.end(); ++suffixItr)
  {
    for (ReturnType::iterator combinationItr = parameterizations.begin(); combinationItr
        != parameterizations.end(); ++combinationItr)
    {
      QList<Parameterization> newCombination(*combinationItr);
      newCombination.append(*suffixItr);
      returnValue.push_back(newCombination);
    }
  }

  return returnValue;
}