/*******************************************************************************
 * Copyright (c) 2015-2016 ONERA.
 * Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
 * Tous droits réservés.
 *
 * Ce programme et les éléments qui l'accompagnent sont mis à disposition
 * aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
 * au droit français et respectant les principes de diffusion des logiciels libres.
 * Vous pouvez utiliser, modifier et/ou redistribuer ce programme
 * sous les conditions de la licence CeCILL-C (http://www.cecill.info).

 * This software is property of ONERA (the French Aerospace Lab).
 * All rights reserved.
 *
 * This program and the accompanying materials are made available under
 * the terms of the CeCILL-C license under French law and
 * abiding by the rules of distribution of free software.
 * You can  use, modify and/ or redistribute the software under the terms of
 * the CeCILL-C license (http://www.cecill.info).
 *
 * Contributeurs/contributors:
 *     Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
 *
 *******************************************************************************/

namespace epoch {
  namespace altarica {
    template <typename Tfunctor>
    void AltaricaGenerator::generateTransitions(const State& s, const Tfunctor& functor) {
      std::vector<epoch::altarica::MetaEvent*> * ev = amodel_->getEnabledMetaEventsAll(s.as_);
      if (ev->size() != 0)
        for (std::vector<epoch::altarica::MetaEvent*>::iterator i = ev->begin(); i!=ev->end(); ++i) {
          epoch::altarica::AltaricaState * ns = amodel_->getNextState(s.as_, *i);
          Transition& transition = functor(std::auto_ptr<AltaricaGenerator::State>(new AltaricaGenerator::State(ns)));
          transition.m_Probability = (*i)->getProba();
          transition.m_Reward = (*i)->getReward();
          delete *i;
        }
      else {
        epoch::altarica::AltaricaState * ns = amodel_->getNextState(s.as_, NULL);         
        Transition& transition = functor(std::auto_ptr<AltaricaGenerator::State>(new AltaricaGenerator::State(ns)));
        if (amodel_->discrete())
          transition.m_Probability = 1.0;
        else
          transition.m_Probability = 0.0;
        
        transition.m_Reward = 0.0;
        
      }
	
      s.as_->releaseFlowVars();
      delete ev;			
    }
  } // namespace altarica
} // namespace epoch

