예제 #1
0
 boost::optional<DataPoint> Analysis_Impl::getDataPoint(
     const std::vector<Measure>& measures) const
 {
   OptionalDataPoint result;
   std::vector<QVariant> variableValues = problem().getVariableValues(measures);
   if (variableValues.size() == measures.size()) {
     // problem was able to match all measures
     DataPointVector intermediate = getDataPoints(variableValues);
     OS_ASSERT(intermediate.size() < 2u);
     if (intermediate.size() == 1u) {
       result = intermediate[0];
     }
   }
   return result;
 }
예제 #2
0
 boost::optional<DataPoint> Analysis_Impl::getDataPoint(
     const std::vector<DiscretePerturbation>& perturbations) const
 {
   OptionalDataPoint result;
   std::vector<QVariant> variableValues = problem().getVariableValues(perturbations);
   if (variableValues.size() == perturbations.size()) {
     // problem was able to match all perturbations
     DataPointVector intermediate = getDataPoints(variableValues);
     BOOST_ASSERT(intermediate.size() < 2u);
     if (intermediate.size() == 1u) {
       result = intermediate[0];
     }
   }
   return result;
 }
예제 #3
0
 bool Analysis_Impl::addDataPoint(const DataPoint& dataPoint) {
   if (m_dataPointsAreInvalid) {
     LOG(Info,"Current data points are invalid. Call removeAllDataPoints before adding new ones.");
     return false;
   }
   if (!(dataPoint.problem().uuid() == problem().uuid())) {
     LOG(Error,"Cannot add given DataPoint to Analysis '" << name() <<
         "', because it is not associated with Problem '" << problem().name() << "'.");
     return false;
   }
   DataPointVector existingDataPoints = getDataPoints(dataPoint.variableValues());
   if (existingDataPoints.size() > 0) {
     BOOST_ASSERT(existingDataPoints.size() == 1); // dataPoint must be fully specified to be valid
     LOG(Info,"DataPoint not added to Analysis '" << name() << "', because it already exists.");
     return false;
   }
   m_dataPoints.push_back(dataPoint);
   connectChild(m_dataPoints.back(),true);
   onChange(AnalysisObject_Impl::Benign);
   return true;
 }
예제 #4
0
  boost::optional<DataPoint> DakotaAlgorithm_Impl::createNextDataPoint(
      Analysis& analysis,const DakotaParametersFile& params)
  {
    OS_ASSERT(analysis.algorithm().get() == getPublicObject<DakotaAlgorithm>());

    // TODO: Update iteration counter.
    OptionalDataPoint result = analysis.problem().createDataPoint(params,
                                                                  getPublicObject<DakotaAlgorithm>());
    if (result) {
      bool added = analysis.addDataPoint(*result);
      if (!added) {
        // get equivalent point already in analysis
        DataPointVector candidates = analysis.getDataPoints(result->variableValues());
        OS_ASSERT(candidates.size() == 1u);
        result = candidates[0];
      }
      std::stringstream ss;
      ss << name() << "_" << m_iter;
      result->addTag(ss.str());
    }
    return result;
  }
  int DesignOfExperiments_Impl::createNextIteration(Analysis& analysis) {
    int result(0);

    // to make sure problem type check has already occurred. this is stated usage in header.
    OS_ASSERT(analysis.algorithm().get() == getPublicObject<DesignOfExperiments>());
    // nothing else is supported yet
    DesignOfExperimentsOptions options = designOfExperimentsOptions();
    OS_ASSERT(options.designType() == DesignOfExperimentsType::FullFactorial);

    if (isComplete()) {
      LOG(Info,"Algorithm is already marked as complete. Returning without creating new points.");
      return result;
    }

    if (options.maxIter() && options.maxIter().get() < 1) {
      LOG(Info,"Maximum iterations set to less than one. No DataPoints will be added to Analysis '"
          << analysis.name() << "', and the Algorithm will be marked complete.");
      markComplete();
      return result;
    }

    OptionalInt mxSim = options.maxSims();
    DataPointVector dataPoints = analysis.getDataPoints("DOE");
    int totPoints = dataPoints.size();
    if (mxSim && (totPoints >= *mxSim)) {
      LOG(Info,"Analysis '" << analysis.name() << "' already contains " << totPoints
          << " DataPoints added by the DesignOfExperiments algorithm, which meets or exceeds the "
          << "maximum number specified in this algorithm's options object, " << *mxSim << ". "
          << "No data points will be added and the Algorithm will be marked complete.");
      markComplete();
      return result;
    } 

    m_iter = 1;

    // determine all combinations
    std::vector< std::vector<QVariant> > variableValues;
    for (const Variable& variable : analysis.problem().variables()) {
      // variable must be DiscreteVariable, otherwise !isCompatibleProblemType(analysis.problem())
      DiscreteVariable discreteVariable = variable.cast<DiscreteVariable>();
      IntVector dvValues = discreteVariable.validValues(true);
      std::vector< std::vector<QVariant> > currentValues = variableValues;
      for (IntVector::const_iterator it = dvValues.begin(), itEnd = dvValues.end();
           it != itEnd; ++it)
      {
        std::vector< std::vector<QVariant> > nextSet = currentValues;
        if (currentValues.empty()) {
          variableValues.push_back(std::vector<QVariant>(1u,QVariant(*it)));
        }
        else {
          for (std::vector<QVariant>& point : nextSet) {
            point.push_back(QVariant(*it));
          }
          if (it == dvValues.begin()) {
            variableValues = nextSet;
          }
          else {
            variableValues.insert(variableValues.end(),nextSet.begin(),nextSet.end());
          }
        }
      }
    }

    // create data points and add to analysis
    for (const std::vector<QVariant>& value : variableValues) {
      DataPoint dataPoint = analysis.problem().createDataPoint(value).get();
      dataPoint.addTag("DOE");
      bool added = analysis.addDataPoint(dataPoint);
      if (added) {
        ++result;
        ++totPoints;
        if (mxSim && (totPoints == mxSim.get())) {
          break;
        }
      }
    }

    if (result == 0) {
      LOG(Trace,"No new points were added, so marking this DesignOfExperiments complete.");
      markComplete();
    }

    return result;
  }