mirror of
http://172.16.200.102/MOISE/Timed-Altarica-To-Fiacre-Translator.git
synced 2026-03-14 08:57:42 +01:00
Initial commit.
This commit is contained in:
21
src/grammars/CMakeLists.txt
Normal file
21
src/grammars/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
# This file is part of EPOCH.
|
||||
# File: CMakeLists.txt
|
||||
# Author: Florent Teichteil-Königsbuch
|
||||
# Contact: florent.teichteil@onera.fr
|
||||
#
|
||||
# EPOCH is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# EPOCH is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with EPOCH. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
ADD_SUBDIRECTORY (altarica)
|
||||
#ADD_SUBDIRECTORY (prism)
|
||||
|
||||
52
src/grammars/altarica/AltaricaException.cc
Normal file
52
src/grammars/altarica/AltaricaException.cc
Normal file
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#include "AltaricaException.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
// Class Exception
|
||||
|
||||
AltaricaException::AltaricaException(std::string const & error_message, std::string const & throwing_function)
|
||||
: error_message_(error_message)
|
||||
{
|
||||
if (!throwing_function.empty())
|
||||
function_backtrace_ = std::string(" from '") + throwing_function + "':\n";
|
||||
}
|
||||
|
||||
|
||||
AltaricaException::~AltaricaException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const char * AltaricaException::what() const throw()
|
||||
{
|
||||
what_message_ = function_backtrace_ + " " + error_message_;
|
||||
return what_message_.c_str();
|
||||
}
|
||||
|
||||
|
||||
60
src/grammars/altarica/AltaricaException.hh
Normal file
60
src/grammars/altarica/AltaricaException.hh
Normal file
@@ -0,0 +1,60 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifndef ALTARICA_EXCEPTION_H_
|
||||
#define ALTARICA_EXCEPTION_H_
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaException : public std::exception
|
||||
{
|
||||
protected :
|
||||
std::string error_message_;
|
||||
std::string function_backtrace_;
|
||||
mutable std::string what_message_;
|
||||
|
||||
public :
|
||||
AltaricaException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~AltaricaException() throw();
|
||||
|
||||
virtual const char * what() const throw();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /*EXCEPTION_H_*/
|
||||
90
src/grammars/altarica/AltaricaGenerator.cc
Normal file
90
src/grammars/altarica/AltaricaGenerator.cc
Normal file
@@ -0,0 +1,90 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MetaEvent.hh"
|
||||
#include "AltaricaGenerator.hh"
|
||||
#include "altarica_driver.hh"
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
AltaricaGenerator::AltaricaGenerator(std::string altaricaFile,epoch::ParsingDriverReporter & reporter) {
|
||||
altarica_driver * driver = new altarica_driver(reporter, altaricaFile, false, false);
|
||||
driver->Parse();
|
||||
amodel_ = driver->amodel;
|
||||
amodel_->finalize("main", false);
|
||||
delete driver;
|
||||
}
|
||||
|
||||
AltaricaGenerator::~AltaricaGenerator() {
|
||||
delete amodel_;
|
||||
}
|
||||
|
||||
std::size_t AltaricaGenerator::State::hash() const {
|
||||
// AltaricaState: as_
|
||||
return as_->hash();
|
||||
}
|
||||
|
||||
bool AltaricaGenerator::State::operator==(const State&o) const {
|
||||
return as_->equals(o.as_);
|
||||
}
|
||||
|
||||
bool AltaricaGenerator::State::operator<(const State&o) const {
|
||||
return as_<o.as_;
|
||||
}
|
||||
|
||||
std::ostream& AltaricaGenerator::State::print(std::ostream& o) const {
|
||||
o << (as_->toString(true, false,false,false));
|
||||
return o;
|
||||
}
|
||||
|
||||
std::ostream& AltaricaGenerator::State::printDot(std::ostream& o, std::string& att) const {
|
||||
return print(o);
|
||||
}
|
||||
|
||||
std::ostream& AltaricaGenerator::Transition::print(std::ostream& o) const {
|
||||
o << "{ probability = " << m_Probability << " , reward = " << m_Reward << " }";
|
||||
return o;
|
||||
}
|
||||
|
||||
std::ostream& AltaricaGenerator::Transition::printDot(std::ostream& o, std::string& att) const {
|
||||
o << "{p=" << m_Probability << ", r=" << m_Reward << "}";
|
||||
return o;
|
||||
}
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
std::ostream& operator<< (std::ostream& o, const AltaricaGenerator::State& s) {
|
||||
return s.print(o);
|
||||
}
|
||||
|
||||
std::ostream& operator<< (std::ostream& o, const AltaricaGenerator::Transition& t) {
|
||||
return t.print(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
96
src/grammars/altarica/AltaricaGenerator.hh
Normal file
96
src/grammars/altarica/AltaricaGenerator.hh
Normal file
@@ -0,0 +1,96 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_GENERATOR_HH
|
||||
#define ALTARICA_GENERATOR_HH
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "AltaricaState.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "MetaEvent.hh"
|
||||
#include "grammars/parsingdriverbase.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
struct AltaricaGenerator {
|
||||
|
||||
epoch::altarica::AltaricaModel *amodel_;
|
||||
|
||||
struct State {
|
||||
epoch::altarica::AltaricaState *as_;
|
||||
inline State(epoch::altarica::AltaricaState *s) : as_(s) {}
|
||||
inline State() : as_(NULL) {}
|
||||
inline State(const epoch::altarica::AltaricaGenerator::State& s) {
|
||||
as_ = s.as_->clone();
|
||||
}
|
||||
~State() {delete as_;}
|
||||
|
||||
std::size_t hash() const;
|
||||
bool operator==(const State&o) const;
|
||||
bool operator<(const State& o) const;
|
||||
|
||||
std::ostream& print(std::ostream& o) const;
|
||||
std::ostream& printDot(std::ostream& o, std::string& att) const;
|
||||
};
|
||||
|
||||
struct Transition {
|
||||
double m_Probability;
|
||||
double m_Reward;
|
||||
|
||||
Transition(double probability, double reward) : m_Probability(probability), m_Reward(reward) {}
|
||||
Transition() {}
|
||||
Transition(const Transition& other) : m_Probability(other.m_Probability), m_Reward(other.m_Reward) {}
|
||||
|
||||
inline const double& getProbability() const {return m_Probability;}
|
||||
inline const double& getReward() const {return m_Reward;}
|
||||
|
||||
std::ostream& print(std::ostream& o) const;
|
||||
std::ostream& printDot(std::ostream& o, std::string& att) const;
|
||||
};
|
||||
|
||||
template <typename Tfunctor>
|
||||
void generateTransitions(const State& s, const Tfunctor& functor);
|
||||
|
||||
AltaricaGenerator(std::string altaricaFile,epoch::ParsingDriverReporter & reporter );
|
||||
~AltaricaGenerator();
|
||||
|
||||
void setDiscrete() {amodel_->setDiscrete();}
|
||||
void setContinuous() {amodel_->setContinuous();}
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& o, const AltaricaGenerator::State& s);
|
||||
|
||||
std::ostream& operator<< (std::ostream& o, const AltaricaGenerator::Transition& t);
|
||||
|
||||
} // namespace altarica
|
||||
} // namespace epoch
|
||||
|
||||
#include "details/AltaricaGeneratorImpl.hh"
|
||||
|
||||
#endif // ALTARICA_GENERATOR_HH
|
||||
|
||||
164
src/grammars/altarica/AltaricaInitInfo.cc
Normal file
164
src/grammars/altarica/AltaricaInitInfo.cc
Normal file
@@ -0,0 +1,164 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "AltaricaInitInfo.hh"
|
||||
#include "AltaricaException.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include "Event.hh"
|
||||
#include "Variable.hh"
|
||||
#include "values/Value.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "domains/Domains.hh"
|
||||
#include "Values.hh"
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
void AltaricaInitInfo::overrideLaws() {
|
||||
for (auto i : initLaws)
|
||||
(i.first)->setLaw(i.second);
|
||||
}
|
||||
|
||||
Value * AltaricaInitInfo::getInitValue(unsigned int i) const {
|
||||
std::map<unsigned int, Value*>::const_iterator j = initValues.find(i);
|
||||
if (j!=initValues.end())
|
||||
return j->second;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
std::string AltaricaInitInfo::toString() const {
|
||||
std::ostringstream oss;
|
||||
oss << std::endl
|
||||
<< "INIT VALUES:" << std::endl;
|
||||
for (auto i: initValues) {
|
||||
oss << amodel->getStateVar(i.first)->toString()
|
||||
<< " = " << i.second->toString()
|
||||
<< std::endl;
|
||||
}
|
||||
oss << "INIT LAWS:" << std::endl;
|
||||
for (auto i: initLaws) {
|
||||
oss << i.first->toString() << " : "
|
||||
<< i.second->toString() << std::endl;
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
Value * AltaricaInitInfo::getValue(Variable *var, std::string valName) {
|
||||
|
||||
Value * v;
|
||||
Domain *d = var->getDomain();
|
||||
if (d != NULL) {
|
||||
PredefinedDomain *pd = dynamic_cast<PredefinedDomain*>(d);
|
||||
EnumDomain *ed = dynamic_cast<EnumDomain*>(d);
|
||||
RangeDomain *rd = dynamic_cast<RangeDomain*>(d);
|
||||
ArrayDomain *ad = dynamic_cast<ArrayDomain*>(d);
|
||||
StructuredDomain *sd = dynamic_cast<StructuredDomain*>(d);
|
||||
RealDomain *reald = dynamic_cast<RealDomain*>(d);
|
||||
|
||||
if (pd) {
|
||||
if (pd->isBooleanDomain()) {
|
||||
// scan true of false from valName
|
||||
std::transform(valName.begin(),
|
||||
valName.end(),
|
||||
valName.begin(),
|
||||
::toupper);
|
||||
if (valName.compare("TRUE") == 0)
|
||||
v = new ValueBool(true, false);
|
||||
else
|
||||
v = new ValueBool(false, true);
|
||||
} else {
|
||||
//scan int from valName
|
||||
std::istringstream stm;
|
||||
int i;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
v = new ValueInt(i);
|
||||
}
|
||||
} else if (ed) {
|
||||
v = new ValueSymbol(valName);
|
||||
} else if (rd) {
|
||||
//scan int from valName
|
||||
std::istringstream stm;
|
||||
int i;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
v = new ValueInt(i);
|
||||
} else if (reald) {
|
||||
std::istringstream stm;
|
||||
double i;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
v = new ValueReal(i);
|
||||
} else if (ad) {
|
||||
throw AltaricaException("initing array domains not yet implemented");
|
||||
} else if (sd) {
|
||||
throw AltaricaException("initing structured domains not yet implemented");
|
||||
}
|
||||
} else {
|
||||
//identifiers starting with digit are forbidden...
|
||||
std::istringstream stm;
|
||||
int i = INT_MIN;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
if (i != INT_MIN) {
|
||||
v = new ValueInt(i);
|
||||
} else {
|
||||
std::string temp(valName);
|
||||
std::transform(temp.begin(), temp.end(),temp.begin(), ::toupper);
|
||||
if (temp.compare("TRUE") == 0)
|
||||
v = new ValueBool(true, false);
|
||||
else if (temp.compare("FALSE") == 0)
|
||||
v = new ValueBool(false, true);
|
||||
else
|
||||
v = new ValueSymbol(valName);
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Node*> * AltaricaInitInfo::getNodes(std::string node_name) {
|
||||
std::vector<Node*> *altNodeVector = amodel->findNodesByType(node_name);
|
||||
if (altNodeVector == NULL) {
|
||||
altNodeVector = new std::vector<Node*>();
|
||||
Node * n = amodel->findNodeByFullName(node_name);
|
||||
if (n==NULL)
|
||||
std::cout << "cannot find node: " << node_name << std::endl;
|
||||
else {
|
||||
altNodeVector->push_back(n);
|
||||
}
|
||||
}
|
||||
return altNodeVector;
|
||||
|
||||
}
|
||||
66
src/grammars/altarica/AltaricaInitInfo.hh
Normal file
66
src/grammars/altarica/AltaricaInitInfo.hh
Normal file
@@ -0,0 +1,66 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_INIT_INFO_HH
|
||||
#define ALTARICA_INIT_INFO_HH
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Value;
|
||||
class AltaricaModel;
|
||||
class EventLaw;
|
||||
class Event;
|
||||
class Variable;
|
||||
class Node;
|
||||
|
||||
|
||||
|
||||
class AltaricaInitInfo {
|
||||
protected:
|
||||
std::map<unsigned int, Value*> initValues;
|
||||
std::map<Event *, EventLaw *> initLaws;
|
||||
AltaricaModel * amodel;
|
||||
Value * getValue(Variable *var, std::string valName);
|
||||
|
||||
public:
|
||||
AltaricaInitInfo(AltaricaModel *am) : amodel(am) {}
|
||||
Value * getInitValue(unsigned int i) const;
|
||||
virtual std::string toString() const;
|
||||
void overrideLaws();
|
||||
std::vector<Node*> * getNodes(std::string);
|
||||
|
||||
virtual bool hasInit() {return true;}
|
||||
virtual bool hasGoal() {return false;}
|
||||
virtual bool hasEvents() {return false;}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
278
src/grammars/altarica/AltaricaInitInfoXML.cc
Normal file
278
src/grammars/altarica/AltaricaInitInfoXML.cc
Normal file
@@ -0,0 +1,278 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "AltaricaInitInfoXML.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include "Event.hh"
|
||||
#include "Node.hh"
|
||||
#include "Variable.hh"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include "domains/Domains.hh"
|
||||
#include "values/ValueBool.hh"
|
||||
#include "values/ValueInt.hh"
|
||||
#include "values/ValueSymbol.hh"
|
||||
#include "values/ValueReal.hh"
|
||||
#include "expressions/ExpressionREAL.hh"
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
AltaricaInitInfoXML::AltaricaInitInfoXML(std::string initFile, AltaricaModel *am) : AltaricaInitInfo(am) {
|
||||
amodel = am;
|
||||
parser.set_substitute_entities();
|
||||
parser.parse_file(initFile);
|
||||
if (parser) {
|
||||
const xmlpp::Node* pNode = parser.get_document()->get_root_node();
|
||||
processRoot(pNode);
|
||||
}
|
||||
overrideLaws();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void AltaricaInitInfoXML::processRoot(const xmlpp::Node * root) {
|
||||
xmlpp::Node::NodeList list = root->get_children();
|
||||
for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter) {
|
||||
const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(*iter);
|
||||
if(nodeText && nodeText->is_white_space())
|
||||
continue;
|
||||
processNode(*iter);
|
||||
}
|
||||
}
|
||||
|
||||
void AltaricaInitInfoXML::processEvent(const xmlpp::Node * xmlnode, std::vector<Node *> *altNodeVector) {
|
||||
const xmlpp::Element* nodeLaw = dynamic_cast<const xmlpp::Element*>(xmlnode);
|
||||
const xmlpp::Element::AttributeList& attributes = nodeLaw->get_attributes();
|
||||
std::string eventName;
|
||||
std::string lawName;
|
||||
std::string param;
|
||||
bool expLaw = true;
|
||||
bool noParam = false;
|
||||
double paramdouble;
|
||||
for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) {
|
||||
const xmlpp::Attribute* attribute = *iter;
|
||||
std::string attname = attribute->get_name();
|
||||
std::string attval = attribute->get_value();
|
||||
if (attname.compare("name") == 0)
|
||||
eventName = attval;
|
||||
else if (attname.compare("law") == 0)
|
||||
lawName = attval;
|
||||
else if (attname.compare("param") == 0)
|
||||
param = attval;
|
||||
}
|
||||
|
||||
if (lawName.compare("dirac") == 0)
|
||||
expLaw = false;
|
||||
if (param.empty())
|
||||
noParam = true;
|
||||
else {
|
||||
std::istringstream stm;
|
||||
stm.str(param);
|
||||
stm >>paramdouble;
|
||||
}
|
||||
|
||||
MemberAccess * tempMA = new MemberAccess(eventName);
|
||||
|
||||
for (std::vector<Node*>::iterator altNodeIt = altNodeVector->begin(); altNodeIt!= altNodeVector->end(); ++altNodeIt) {
|
||||
|
||||
Event * oldEvent = (*altNodeIt)->findEventByName(tempMA);
|
||||
Expression *oldLaw = NULL;
|
||||
if (expLaw && noParam) {
|
||||
oldLaw = oldEvent->getLaw()->getParam();
|
||||
}
|
||||
|
||||
EventLaw * newLaw;
|
||||
if (expLaw) {
|
||||
if (oldLaw != NULL)
|
||||
newLaw = new EventLaw(ALTARICA_EXP,oldLaw);
|
||||
else
|
||||
newLaw = new EventLaw(ALTARICA_EXP,new ExpressionREAL(paramdouble));
|
||||
} else {
|
||||
newLaw = new EventLaw(ALTARICA_DIRAC_0,0);
|
||||
}
|
||||
|
||||
initLaws[oldEvent] = newLaw;
|
||||
}
|
||||
}
|
||||
|
||||
void AltaricaInitInfoXML::processValue(const xmlpp::Node * xmlnode, std::vector<Node *>* altNodeVector) {
|
||||
const xmlpp::Element* nodeValue = dynamic_cast<const xmlpp::Element*>(xmlnode);
|
||||
const xmlpp::Element::AttributeList& attributes = nodeValue->get_attributes();
|
||||
std::string varName;
|
||||
std::string valName;
|
||||
for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) {
|
||||
const xmlpp::Attribute* attribute = *iter;
|
||||
std::string attname = attribute->get_name();
|
||||
std::string attval = attribute->get_value();
|
||||
if (attname.compare("var") == 0)
|
||||
varName = attval;
|
||||
else if (attname.compare("val") == 0)
|
||||
valName = attval;
|
||||
}
|
||||
|
||||
for (std::vector<Node*>::iterator altNodeIt = altNodeVector->begin(); altNodeIt!= altNodeVector->end(); ++altNodeIt) {
|
||||
Value * v;
|
||||
Variable * var = (*altNodeIt)->findStateVariableByName(varName);
|
||||
if (var == NULL)
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("cannot find variable to init")));
|
||||
unsigned int varIndex = var->getIndex();
|
||||
// try to guess type from domain
|
||||
Domain * d = var->getDomain();
|
||||
if (d!= NULL) {
|
||||
PredefinedDomain *pd = dynamic_cast<PredefinedDomain*>(d);
|
||||
EnumDomain *ed = dynamic_cast<EnumDomain*>(d);
|
||||
RangeDomain *rd = dynamic_cast<RangeDomain*>(d);
|
||||
ArrayDomain *ad = dynamic_cast<ArrayDomain*>(d);
|
||||
StructuredDomain *sd = dynamic_cast<StructuredDomain*>(d);
|
||||
RealDomain *reald = dynamic_cast<RealDomain*>(d);
|
||||
|
||||
if (pd) {
|
||||
if (pd->isBooleanDomain()) {
|
||||
// scan true of false from valName
|
||||
std::transform(valName.begin(), valName.end(),valName.begin(), ::toupper);
|
||||
if (valName.compare("TRUE") == 0)
|
||||
v = new ValueBool(true, false);
|
||||
else
|
||||
v = new ValueBool(false, true);
|
||||
} else {
|
||||
//scan int from valName
|
||||
std::istringstream stm;
|
||||
int i;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
v = new ValueInt(i);
|
||||
}
|
||||
} else if (ed) {
|
||||
v = new ValueSymbol(valName);
|
||||
} else if (rd) {
|
||||
//scan int from valName
|
||||
std::istringstream stm;
|
||||
int i;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
v = new ValueInt(i);
|
||||
} else if (reald) {
|
||||
std::istringstream stm;
|
||||
double i;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
v = new ValueReal(i);
|
||||
} else if (ad) {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("initing array domains not yet implemented")));
|
||||
} else if (sd) {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("initing structured domains not yet implemented")));
|
||||
}
|
||||
} else {
|
||||
//identifiers starting with digit are forbidden...
|
||||
std::istringstream stm;
|
||||
int i = INT_MIN;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
if (i != INT_MIN) {
|
||||
v = new ValueInt(i);
|
||||
} else {
|
||||
std::string temp(valName);
|
||||
std::transform(temp.begin(), temp.end(),temp.begin(), ::toupper);
|
||||
if (temp.compare("TRUE") == 0)
|
||||
v = new ValueBool(true, false);
|
||||
else if (temp.compare("FALSE") == 0)
|
||||
v = new ValueBool(false, true);
|
||||
else
|
||||
v = new ValueSymbol(valName);
|
||||
}
|
||||
}
|
||||
initValues[varIndex] = v;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AltaricaInitInfoXML::processNode(const xmlpp::Node * xmlnode) {
|
||||
|
||||
|
||||
const Glib::ustring nodename = xmlnode->get_name();
|
||||
|
||||
bool nodeisclass = false;
|
||||
std::vector<Node *> *altNodeVector;
|
||||
|
||||
|
||||
|
||||
xmlpp::Node* nodeName = *((xmlnode->get_children(Glib::ustring("name"))).begin());
|
||||
|
||||
|
||||
xmlpp::Node* nodeNameSon = *(nodeName->get_children().begin());
|
||||
std::string altaricaNodeName = (dynamic_cast<const xmlpp::TextNode*>(nodeNameSon))->get_content();
|
||||
|
||||
xmlpp::Node::NodeList nodeTypeList = xmlnode->get_children(Glib::ustring("type"));
|
||||
if (nodeTypeList.size() != 0) {
|
||||
xmlpp::Node* nodeType = *(nodeTypeList.begin());
|
||||
xmlpp::Node::NodeList nodeTypeListSons = nodeType->get_children();
|
||||
xmlpp::Node* nodeTypeSon = *(nodeTypeListSons.begin());
|
||||
const xmlpp::TextNode * texttype = dynamic_cast<const xmlpp::TextNode*>(nodeTypeSon);
|
||||
std::string altaricaNodeType = texttype->get_content();
|
||||
if (altaricaNodeType.compare("class") == 0)
|
||||
nodeisclass = true;
|
||||
}
|
||||
|
||||
|
||||
if (nodeisclass) {
|
||||
altNodeVector = amodel->findNodesByType(altaricaNodeName);
|
||||
if (altNodeVector == NULL)
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("cannot find node by type")));
|
||||
} else {
|
||||
Node * n = amodel->findNodeByFullName(altaricaNodeName);
|
||||
if (n==NULL)
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("cannot find node")));
|
||||
altNodeVector = new std::vector<Node*>();
|
||||
altNodeVector->push_back(n);
|
||||
}
|
||||
|
||||
xmlpp::Node::NodeList lawnode = xmlnode->get_children(Glib::ustring("laws"));
|
||||
xmlpp::Node::NodeList eventlist = (*(lawnode.begin()))->get_children(Glib::ustring("event"));
|
||||
for(xmlpp::Node::NodeList::iterator iter = eventlist.begin(); iter != eventlist.end(); ++iter) {
|
||||
processEvent(*iter, altNodeVector);
|
||||
}
|
||||
|
||||
|
||||
xmlpp::Node::NodeList valuesnode = xmlnode->get_children(Glib::ustring("values"));
|
||||
xmlpp::Node::NodeList valueList = (*(valuesnode.begin()))->get_children(Glib::ustring("value"));
|
||||
for(xmlpp::Node::NodeList::iterator iter = valueList.begin(); iter != valueList.end(); ++iter) {
|
||||
processValue(*iter, altNodeVector);
|
||||
}
|
||||
delete altNodeVector;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
66
src/grammars/altarica/AltaricaInitInfoXML.hh
Normal file
66
src/grammars/altarica/AltaricaInitInfoXML.hh
Normal file
@@ -0,0 +1,66 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_INIT_INFO_XML_HH
|
||||
#define ALTARICA_INIT_INFO_XML_HH
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "libxml++/libxml++.h"
|
||||
#include "AltaricaInitInfo.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaModel;
|
||||
class Value;
|
||||
class Node;
|
||||
class Event;
|
||||
class EventLaw;
|
||||
|
||||
|
||||
class AltaricaInitInfoXML : public AltaricaInitInfo {
|
||||
private:
|
||||
xmlpp::DomParser parser;
|
||||
|
||||
// std::map<unsigned int, Value*> initValues;
|
||||
// std::map<Event *, EventLaw *> initLaws;
|
||||
|
||||
// void overrideLaws();
|
||||
// void computeInitValues();
|
||||
void processRoot(const xmlpp::Node * root);
|
||||
void processNode(const xmlpp::Node * node);
|
||||
|
||||
void processEvent(const xmlpp::Node * node, std::vector<Node *>* altNode);
|
||||
void processValue(const xmlpp::Node * node, std::vector<Node*>* altNode);
|
||||
public:
|
||||
AltaricaInitInfoXML(std::string initFile,AltaricaModel *am);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
174
src/grammars/altarica/AltaricaInitInfoXML2.cc
Normal file
174
src/grammars/altarica/AltaricaInitInfoXML2.cc
Normal file
@@ -0,0 +1,174 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "AltaricaInitInfoXML2.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include "Event.hh"
|
||||
#include "Node.hh"
|
||||
#include "Variable.hh"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include "domains/Domains.hh"
|
||||
#include "values/ValueBool.hh"
|
||||
#include "values/ValueInt.hh"
|
||||
#include "values/ValueSymbol.hh"
|
||||
#include "values/ValueReal.hh"
|
||||
#include "expressions/ExpressionREAL.hh"
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/xml_parser.hpp>
|
||||
#include <boost/property_tree/exceptions.hpp>
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::ptree_bad_path;
|
||||
|
||||
|
||||
AltaricaInitInfoXML2::AltaricaInitInfoXML2(std::string initFile, AltaricaModel *am) : AltaricaInitInfo(am) {
|
||||
amodel = am;
|
||||
ptree pt;
|
||||
read_xml (initFile, pt);
|
||||
|
||||
|
||||
processRoot(pt);
|
||||
overrideLaws();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void AltaricaInitInfoXML2::processRoot(ptree& root) {
|
||||
for (auto&v: root.get_child("init")) {
|
||||
if (v.first.compare("node")==0)
|
||||
processNode(v.second);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AltaricaInitInfoXML2::processEvent(ptree& eventattr, std::vector<Node *> *altNodeVector) {
|
||||
|
||||
std::string lawName;
|
||||
std::string param;
|
||||
std::string eventName = eventattr.get<std::string>("name");
|
||||
|
||||
try {
|
||||
lawName = eventattr.get<std::string>("law");
|
||||
} catch (ptree_bad_path e) {
|
||||
}
|
||||
|
||||
try {
|
||||
param = eventattr.get<std::string>("param");
|
||||
} catch (ptree_bad_path e) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool expLaw = true;
|
||||
bool noParam = false;
|
||||
double paramdouble;
|
||||
|
||||
if (lawName.compare("dirac") == 0)
|
||||
expLaw = false;
|
||||
if (param.empty())
|
||||
noParam = true;
|
||||
else {
|
||||
std::istringstream stm;
|
||||
stm.str(param);
|
||||
stm >>paramdouble;
|
||||
}
|
||||
|
||||
MemberAccess tempMA(eventName);
|
||||
|
||||
for (auto& altNodeIt : *altNodeVector) {
|
||||
|
||||
Event * oldEvent = altNodeIt->findEventByName(&tempMA);
|
||||
Expression *oldLaw = NULL;
|
||||
if (expLaw && noParam) {
|
||||
oldLaw = oldEvent->getLaw()->getParam();
|
||||
}
|
||||
|
||||
EventLaw * newLaw;
|
||||
if (expLaw) {
|
||||
if (oldLaw != NULL)
|
||||
newLaw = new EventLaw(ALTARICA_EXP,oldLaw);
|
||||
else
|
||||
newLaw = new EventLaw(ALTARICA_EXP,new ExpressionREAL(paramdouble));
|
||||
} else {
|
||||
newLaw = new EventLaw(ALTARICA_DIRAC_0,0);
|
||||
}
|
||||
|
||||
initLaws[oldEvent] = newLaw;
|
||||
}
|
||||
}
|
||||
|
||||
void AltaricaInitInfoXML2::processValue(ptree & node, std::vector<Node *>* altNodeVector) {
|
||||
for (auto &i: *altNodeVector) {
|
||||
Variable * var = i->findStateVariableByName(node.get<std::string>("var"));
|
||||
if (var != NULL) {
|
||||
Value * v = getValue(var,node.get<std::string>("val"));
|
||||
initValues[var->getIndex()] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AltaricaInitInfoXML2::processNode(ptree& pt) {
|
||||
|
||||
std::vector<Node *> *altNodeVector = getNodes(pt.get_child("name").data());
|
||||
|
||||
for (auto &i :pt)
|
||||
if (i.first.compare("laws")==0) {
|
||||
for (auto& ii:i.second) {
|
||||
if (ii.first.compare("event") == 0)
|
||||
processEvent(ii.second.get_child("<xmlattr>"), altNodeVector);
|
||||
}
|
||||
}
|
||||
|
||||
else if (i.first.compare("values") == 0) {
|
||||
for (auto& ii:i.second) {
|
||||
if (ii.first.compare("value") == 0)
|
||||
processValue(ii.second.get_child("<xmlattr>"), altNodeVector);
|
||||
}
|
||||
|
||||
}
|
||||
delete altNodeVector;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
64
src/grammars/altarica/AltaricaInitInfoXML2.hh
Normal file
64
src/grammars/altarica/AltaricaInitInfoXML2.hh
Normal file
@@ -0,0 +1,64 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_INIT_INFO_XML2_HH
|
||||
#define ALTARICA_INIT_INFO_XML2_HH
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "AltaricaInitInfo.hh"
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaModel;
|
||||
class Value;
|
||||
class Node;
|
||||
class Event;
|
||||
class EventLaw;
|
||||
|
||||
|
||||
class AltaricaInitInfoXML2 : public AltaricaInitInfo {
|
||||
private:
|
||||
void processRoot(boost::property_tree::ptree& root);
|
||||
void processNode(boost::property_tree::ptree& node);
|
||||
|
||||
void processEvent(boost::property_tree::ptree & node, std::vector<Node *>* altNode);
|
||||
// void processEvents(boost::property_tree::ptree & node, std::vector<Node *>* altNode);
|
||||
void processValue(boost::property_tree::ptree & node, std::vector<Node*>* altNode);
|
||||
// void processValues(boost::property_tree::ptree & node, std::vector<Node*>* altNode);
|
||||
public:
|
||||
AltaricaInitInfoXML2(std::string initFile,AltaricaModel *am);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
72
src/grammars/altarica/AltaricaInteractive.cc
Normal file
72
src/grammars/altarica/AltaricaInteractive.cc
Normal file
@@ -0,0 +1,72 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "AltaricaInteractive.hh"
|
||||
#include "AltaricaState.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "MetaEvent.hh"
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
void ::epoch::altarica::interactiveExecute(AltaricaState *cstate, AltaricaModel * amodel, bool printFlow, bool printNULL, bool printDomain) {
|
||||
int choice;
|
||||
while (true) {
|
||||
std::vector<epoch::altarica::MetaEvent*> * mev = amodel->getEnabledMetaEventsAll(cstate);
|
||||
std::cout<<"\n # metaEvents: "<< mev->size() << std::endl;
|
||||
for (int i=0; i<mev->size(); ++i) {
|
||||
std::cout << " MEV " << i << ": " << (*mev)[i]->toString();
|
||||
}
|
||||
do {
|
||||
std::cout << "\n\ninput MEV number (-1 exits): ";
|
||||
std::string l;
|
||||
std::getline(std::cin,l);
|
||||
std::stringstream ss(l);
|
||||
ss >> choice;
|
||||
if (ss.fail()) {
|
||||
if (std::cin.eof()){
|
||||
std::cout << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
choice = std::numeric_limits<int>::max();
|
||||
}
|
||||
} while (choice > ((int)mev->size() - 1));
|
||||
|
||||
if (choice <= -1)
|
||||
exit(0);
|
||||
|
||||
std::cout << "Executing MEV: "<< (*mev)[choice]->toString() << std::endl;
|
||||
std::cout << "state reached:" << std::endl;
|
||||
cstate = amodel->getNextState(cstate, (*mev)[choice]);
|
||||
if (printFlow)
|
||||
amodel->evaluateFlowVars(cstate);
|
||||
std::cout << cstate->toString(true,printFlow,printNULL,printDomain);
|
||||
}
|
||||
|
||||
}
|
||||
42
src/grammars/altarica/AltaricaInteractive.hh
Normal file
42
src/grammars/altarica/AltaricaInteractive.hh
Normal file
@@ -0,0 +1,42 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_INTERACTIVE_HH
|
||||
#define ALTARICA_INTERACTIVE_HH
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
void interactiveExecute(AltaricaState *cstate,
|
||||
AltaricaModel * amodel,
|
||||
bool printFlow = false,
|
||||
bool printNULL = false,
|
||||
bool printDomain = false);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
370
src/grammars/altarica/AltaricaJson.cc
Normal file
370
src/grammars/altarica/AltaricaJson.cc
Normal file
@@ -0,0 +1,370 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "AltaricaJson.hh"
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "Node.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "Event.hh"
|
||||
#include "MetaEvent.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include "expressions/ExpressionREAL.hh"
|
||||
#include "Variable.hh"
|
||||
#include "domains/Domains.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "AltaricaState.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
AltaricaJson::AltaricaJson(std::string jsonFile, AltaricaModel *am) : AltaricaInitInfo(am),
|
||||
hasInit_(false),
|
||||
hasGoal_(false),
|
||||
hasEvents_(false),
|
||||
hasActive_(false),
|
||||
hasInactive_(false)
|
||||
{
|
||||
verbose = true;
|
||||
parseJsonFile(jsonFile);
|
||||
overrideLaws();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void AltaricaJson::parseJsonFile(std::string jsonFile) {
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(jsonFile,pt);
|
||||
for (auto& ii : pt.get_child("init")) {
|
||||
hasInit_ = true;
|
||||
if (verbose) std::cout << "processing init info for " << ii.first << " ";
|
||||
std::string node_name = ii.first;
|
||||
std::vector<Node*> * altNodeVector = NULL;
|
||||
|
||||
|
||||
altNodeVector = getNodes(node_name);
|
||||
if (altNodeVector->size() == 0)
|
||||
{
|
||||
std::cerr << "could not find any node for: " << node_name << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
for (auto& iii : ii.second.get_child("")) {
|
||||
|
||||
for (auto &n : *altNodeVector) {
|
||||
|
||||
|
||||
|
||||
if (iii.first.compare("laws") == 0) {
|
||||
if (verbose) std::cout << " applying law init info on node: " << n->getMA()->toString() << std::endl;
|
||||
for (auto& i4 : iii.second.get_child("")) {
|
||||
std::string event_name = i4.first;
|
||||
MemberAccess * tempMA = new MemberAccess(event_name);
|
||||
|
||||
Event * oldEvent = n->findEventByName(tempMA);
|
||||
if (oldEvent == NULL) {
|
||||
std::cerr << " !!!! CANNOT FIND EVENT: " << event_name << " in node " << node_name << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
std::string law_type;
|
||||
double param = std::numeric_limits<double>::min();
|
||||
for (auto& i5:i4.second.get_child("")) {
|
||||
if (i5.first.compare("type") == 0) {
|
||||
law_type = i5.second.get_value<std::string>();
|
||||
}
|
||||
if (i5.first.compare("param") == 0) {
|
||||
param = i5.second.get_value<float>();
|
||||
}
|
||||
|
||||
}
|
||||
EventLaw * newLaw;
|
||||
Expression * newParam;
|
||||
if (law_type.compare("") == 0) {
|
||||
newLaw = oldEvent->getLaw()->clone();
|
||||
} else if (law_type.compare("exp") == 0) {
|
||||
newLaw = new EventLaw(ALTARICA_EXP);
|
||||
} else if (law_type.compare("dirac") == 0) {
|
||||
newLaw = new EventLaw(ALTARICA_DIRAC_0);
|
||||
} else if (law_type.compare("const") == 0) {
|
||||
newLaw = new EventLaw(ALTARICA_DISCRETE);
|
||||
}
|
||||
if (param == std::numeric_limits<double>::min())
|
||||
newParam = oldEvent->getLaw()->getParam();
|
||||
else
|
||||
newParam = new ExpressionREAL(param);
|
||||
newLaw->setParam(newParam);
|
||||
initLaws[oldEvent] = newLaw;
|
||||
}
|
||||
}
|
||||
|
||||
if (iii.first.compare("values") == 0) {
|
||||
if (verbose) std::cout << " applying values init info on node: " << n->getMA()->toString() << std::endl;
|
||||
for (auto& i4 : iii.second.get_child("")) {
|
||||
for (auto& i5 : i4.second.get_child("")) {
|
||||
std::string varName = i5.first;
|
||||
if (verbose)std::cout << " on variable: " << varName << std::endl;
|
||||
Variable * var = n->findStateVariableByName(varName);
|
||||
if (var == NULL) {
|
||||
std::cerr << " !!! CANNOT FIND VARIABLE " << varName << std::endl;
|
||||
break;
|
||||
}
|
||||
Value * v = getValue(var, i5.second.get_value<std::string>());
|
||||
initValues[var->getIndex()] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& ii : pt.get_child("goal")) {
|
||||
hasGoal_ = true;
|
||||
std::string node_name = ii.first;
|
||||
std::vector<Node*> * altNodeVector = NULL;
|
||||
if (verbose) std::cout << "processing goal info for " << node_name;
|
||||
|
||||
altNodeVector = amodel->findNodesByType(node_name);
|
||||
if (altNodeVector == NULL) {
|
||||
altNodeVector = new std::vector<Node*>();
|
||||
Node *n = amodel->findNodeByFullName(node_name);
|
||||
if (n != NULL) {
|
||||
if (verbose) std::cout << " (instance)" << std::endl;
|
||||
altNodeVector->push_back(n);
|
||||
}
|
||||
} else
|
||||
if (verbose) std::cout << " (type)" << std::endl;
|
||||
if (altNodeVector->size() == 0) {
|
||||
std::cerr << "cannot find node: " << node_name << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
for (auto &n : *altNodeVector) {
|
||||
for (auto & i3 : ii.second.get_child("")) {
|
||||
for (auto& i4 : i3.second.get_child("")) {
|
||||
std::string varName = i4.first;
|
||||
std::string varValue = i4.second.get_value<std::string>();
|
||||
Variable * var = n->findStateVariableByName(varName);
|
||||
if (var == NULL)
|
||||
var = n->findFlowVariableByName(varName);
|
||||
if (var == NULL) {
|
||||
if (verbose) std::cout << "cannot find variable " << varName << std::endl;
|
||||
break;
|
||||
}
|
||||
Value * v = getValue(var, varValue);
|
||||
goalValues[var] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (auto& ii : pt.get_child("events")) {
|
||||
hasEvents_ = true;
|
||||
std::vector<Event*> * newMEV = new std::vector<Event*>();
|
||||
for (auto& i3: ii.second.get_child("")) {
|
||||
std::string evName = i3.second.data();
|
||||
MemberAccess * tempMA = new MemberAccess(evName);
|
||||
tempMA->setGlobal(true);
|
||||
Event * ev = amodel->getMainNode()->findEventByName(tempMA);
|
||||
if (ev == NULL) {
|
||||
std::cerr << "cannot find event " << evName << std::endl;
|
||||
break;
|
||||
}
|
||||
newMEV->push_back(ev);
|
||||
}
|
||||
testCase.push_back(newMEV);
|
||||
}
|
||||
|
||||
for (auto& ii : pt.get_child("active")) {
|
||||
hasActive_ = true;
|
||||
std::vector<Event*> * newMEV = new std::vector<Event*>();
|
||||
for (auto& i3: ii.second.get_child("")) {
|
||||
std::string evName = i3.second.data();
|
||||
MemberAccess * tempMA = new MemberAccess(evName);
|
||||
tempMA->setGlobal(true);
|
||||
Event * ev = amodel->getMainNode()->findEventByName(tempMA);
|
||||
if (ev == NULL) {
|
||||
std::cerr << "cannot find event " << evName << std::endl;
|
||||
break;
|
||||
}
|
||||
newMEV->push_back(ev);
|
||||
}
|
||||
activeEvents.push_back(newMEV);
|
||||
}
|
||||
|
||||
for (auto& ii : pt.get_child("inactive")) {
|
||||
hasInactive_ = true;
|
||||
std::vector<Event*> * newMEV = new std::vector<Event*>();
|
||||
for (auto& i3: ii.second.get_child("")) {
|
||||
std::string evName = i3.second.data();
|
||||
MemberAccess * tempMA = new MemberAccess(evName);
|
||||
tempMA->setGlobal(true);
|
||||
Event * ev = amodel->getMainNode()->findEventByName(tempMA);
|
||||
if (ev == NULL) {
|
||||
std::cerr << "cannot find event " << evName << std::endl;
|
||||
break;
|
||||
}
|
||||
newMEV->push_back(ev);
|
||||
}
|
||||
inactiveEvents.push_back(newMEV);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::string AltaricaJson::toString() const {
|
||||
std::string s = AltaricaInitInfo::toString();
|
||||
if (hasGoal_) {
|
||||
s+= "GOAL VALUES:\n";
|
||||
// for (std::map<unsigned int, Value*>::const_iterator i = goalValues.begin(); i!= goalValues.end(); ++i) {
|
||||
for (auto &i:goalValues) {
|
||||
s+= i.first->toString() + " = " + i.second->toString()+"\n";
|
||||
}
|
||||
}
|
||||
if (hasEvents_) {
|
||||
s+="EVENTS:\n";
|
||||
for (auto& mev:testCase) {
|
||||
s+=" { ";
|
||||
for (auto &e : *mev) {
|
||||
s+= e->toString();
|
||||
}
|
||||
s+= " }\n";
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
std::vector<MetaEvent*> * AltaricaJson::matchMEV(std::vector<Event*> *mev, std::vector<MetaEvent*>* allmev) {
|
||||
std::vector<MetaEvent*> * matched = new std::vector<MetaEvent*>();
|
||||
for (auto& mevx:*allmev) {
|
||||
bool ok = true;
|
||||
for (auto& ev:*mev) {
|
||||
if (!mevx->containsE(ev)) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ok)
|
||||
matched->push_back(mevx);
|
||||
}
|
||||
return matched;
|
||||
|
||||
}
|
||||
|
||||
std::vector<MetaEvent*> * AltaricaJson::selectSmaller(std::vector<MetaEvent*> *set) {
|
||||
std::vector<MetaEvent*> * smallestMEVs = new std::vector<MetaEvent*>();
|
||||
unsigned int smaller = std::numeric_limits<unsigned int>::max();
|
||||
for (auto mev: *set) {
|
||||
if (smaller > mev->size())
|
||||
smaller = mev->size();
|
||||
}
|
||||
for (auto mev:*set) {
|
||||
if (mev->size() == smaller)
|
||||
smallestMEVs->push_back(mev);
|
||||
}
|
||||
delete set;
|
||||
return smallestMEVs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool AltaricaJson::runTestCase(AltaricaState *cstate, bool printFlow, bool printNULL, bool printDomain) {
|
||||
|
||||
for (auto& mev: testCase) {
|
||||
std::vector<MetaEvent*> * allmev = amodel->getEnabledMetaEventsAll(cstate);
|
||||
std::vector<MetaEvent*> * matched = matchMEV(mev, allmev);
|
||||
matched = selectSmaller(matched);
|
||||
if (matched->size() != 1) {
|
||||
std::cerr << "cannot find corresponding MEV\n";
|
||||
std::cerr << "required: {";
|
||||
for (auto& ev:*mev)
|
||||
std::cerr << ev->toString() << " ";
|
||||
std::cerr << "}\n";
|
||||
std::cerr << "possible: \n";
|
||||
for (auto& mev: *allmev)
|
||||
std::cerr << mev->toString();
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
} else {
|
||||
|
||||
std::cout << "Executing MEV: "<< (*matched)[0]->toString() << std::endl;
|
||||
std::cout << "state reached:" << std::endl;
|
||||
cstate = amodel->getNextState(cstate, (*matched)[0]);
|
||||
if (printFlow)
|
||||
amodel->evaluateFlowVars(cstate);
|
||||
std::cout << cstate->toString(true,printFlow,printNULL,printDomain);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasGoal_) {
|
||||
|
||||
std::cout << "GOAL VALUES:\n";
|
||||
for (auto &i:goalValues) {
|
||||
std::cout << i.first->toString() << " = " << i.second->toString() << std::endl;
|
||||
}
|
||||
std::cout << cstate->toString(true, printFlow, printNULL, printDomain);
|
||||
|
||||
for (auto& gv:goalValues) {
|
||||
Value * reachedValue = cstate->getValue(gv.first);
|
||||
if (!reachedValue->contains(gv.second)) {
|
||||
std::cout << "TESTCASE FAILED for variable " << gv.first->toString();
|
||||
std::cout << "\n required value: " << gv.second->toString();
|
||||
std::cout << "\n reached value : " << reachedValue->toString() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// return true;
|
||||
}
|
||||
|
||||
if (hasActive_) {
|
||||
std::vector<MetaEvent*> * allmev = amodel->getEnabledMetaEventsAll(cstate);
|
||||
for (auto& mev: activeEvents) {
|
||||
std::vector<MetaEvent*> * matched = matchMEV(mev, allmev);
|
||||
matched = selectSmaller(matched);
|
||||
if (matched->size() == 0)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasInactive_) {
|
||||
std::vector<MetaEvent*> * allmev = amodel->getEnabledMetaEventsAll(cstate);
|
||||
for (auto& mev: activeEvents) {
|
||||
std::vector<MetaEvent*> * matched = matchMEV(mev, allmev);
|
||||
matched = selectSmaller(matched);
|
||||
if (matched->size() != 0)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
79
src/grammars/altarica/AltaricaJson.hh
Normal file
79
src/grammars/altarica/AltaricaJson.hh
Normal file
@@ -0,0 +1,79 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_JSON_HH
|
||||
#define ALTARICA_JSON_HH
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "AltaricaInitInfo.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaModel;
|
||||
class Value;
|
||||
class Event;
|
||||
class EventLaw;
|
||||
class AltaricaState;
|
||||
class MetaEvent;
|
||||
class Event;
|
||||
|
||||
|
||||
class AltaricaJson : public AltaricaInitInfo {
|
||||
private:
|
||||
std::vector<std::vector<Event *>*> testCase;
|
||||
std::vector<std::vector<Event *>*> activeEvents;
|
||||
std::vector<std::vector<Event *>*> inactiveEvents;
|
||||
std::map<Variable*, Value*> goalValues;
|
||||
void parseJsonFile(std::string jsonFile);
|
||||
bool hasInit_;
|
||||
bool hasGoal_;
|
||||
bool hasEvents_;
|
||||
bool hasActive_;
|
||||
bool hasInactive_;
|
||||
|
||||
bool verbose;
|
||||
|
||||
std::vector<MetaEvent*> * matchMEV(std::vector<Event*> *mev, std::vector<MetaEvent*>* allmev);
|
||||
std::vector<MetaEvent*> * selectSmaller(std::vector<MetaEvent*> *set);
|
||||
|
||||
|
||||
|
||||
public:
|
||||
AltaricaJson(std::string jsonFile, AltaricaModel *am);
|
||||
virtual bool hasInit() {return hasInit_;}
|
||||
virtual bool hasGoal() {return hasGoal_;}
|
||||
virtual bool hasEvents() {return hasEvents_;}
|
||||
virtual std::string toString() const;
|
||||
bool runTestCase(AltaricaState *curState, bool printFlow =false, bool printNULL =false, bool printDomain = false);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
1369
src/grammars/altarica/AltaricaModel.cc
Normal file
1369
src/grammars/altarica/AltaricaModel.cc
Normal file
File diff suppressed because it is too large
Load Diff
353
src/grammars/altarica/AltaricaModel.hh
Normal file
353
src/grammars/altarica/AltaricaModel.hh
Normal file
@@ -0,0 +1,353 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_MODEL_HH
|
||||
#define ALTARICA_MODEL_HH
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <stddef.h>
|
||||
#include <cstddef>
|
||||
|
||||
#ifndef NDEBUG_SEMANTICS
|
||||
#define DEBUG_SEMANTICS
|
||||
#endif
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class Variable;
|
||||
class Node;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
class Constant;
|
||||
class Domain;
|
||||
class Event;
|
||||
class Synchronisation;
|
||||
class Value;
|
||||
class AltaricaInitInfo;
|
||||
class AltaricaInitInfoXML;
|
||||
class AltaricaJson;
|
||||
class MetaEvent;
|
||||
class Assertion;
|
||||
|
||||
//! The whole model itself, including functions to simulate it
|
||||
/*! AltaricaModel contains all information needed to simulate an AltaricaModel
|
||||
and functions to generate (meta) events at a given state, then following states
|
||||
*/
|
||||
class AltaricaModel {
|
||||
|
||||
private:
|
||||
bool hasDirac_;
|
||||
bool discrete_;
|
||||
|
||||
void (*probaComputer)(std::vector<MetaEvent*>* mev, bool mayHaveDirac, AltaricaModel *am, AltaricaState *as);
|
||||
std::vector<MetaEvent*> * (*metaEventOrderer)(std::vector<MetaEvent*> *mev);
|
||||
std::vector<MetaEvent*> * (AltaricaModel::*getEnabledMetaEventsMostPrioOnlyFunctor)(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * (AltaricaModel::*getEnabledMetaEventsAllFunctor)(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * (AltaricaModel::*getEnabledMetaEventsDiracFunctor)(AltaricaState *state);
|
||||
|
||||
std::string varStringCache;
|
||||
Variable * varCache;
|
||||
|
||||
AltaricaInitInfo * initInfo;
|
||||
|
||||
//! is the model ready to use?
|
||||
bool finalized_;
|
||||
|
||||
//! constants of the .alt file
|
||||
std::vector<epoch::altarica::Constant*> constants;
|
||||
|
||||
//! declared domains
|
||||
/*! declared domains of the .alt file
|
||||
does not contain anonymous domains !!!!
|
||||
(of the type flow A:[1,10];)
|
||||
*/
|
||||
std::vector<epoch::altarica::Domain*> domains;
|
||||
//! all declared nodes
|
||||
/*! declared nodes. each nodes contains a full living copy of its subnodes;
|
||||
so the model of the system is containdes in "main" node only, other
|
||||
are used for cloning during model building phase
|
||||
*/
|
||||
std::vector<epoch::altarica::Node*> nodes;
|
||||
|
||||
//! all state variables
|
||||
std::vector<epoch::altarica::Variable*> stateVars;
|
||||
|
||||
//! all different flow variables
|
||||
/*! all _different_ flow vars: if flow vars (in the sense of altarica
|
||||
have always the same value, only one flowvar appears in the list
|
||||
*/
|
||||
std::vector<epoch::altarica::Variable*> flowVars;
|
||||
|
||||
//! all atomic events
|
||||
/*! atomic events inside main node and subnodes */
|
||||
std::vector<epoch::altarica::Event*> atomicEvents;
|
||||
|
||||
std::vector<epoch::altarica::Event*> atomicDiracEvents;
|
||||
|
||||
//! all synchronisations
|
||||
/*! synchronisations inside main node and subnodes */
|
||||
std::vector<epoch::altarica::Synchronisation*> syncs;
|
||||
|
||||
//! all metaEvents
|
||||
/*! metaevents, used only if !onTheFly */
|
||||
std::vector<epoch::altarica::MetaEvent*> * metaEvents_;
|
||||
|
||||
//! all metaEvents, sorted by priority
|
||||
/*! all metaevents, sorted, used only if !onTheFly */
|
||||
std::vector<std::vector<epoch::altarica::MetaEvent*> *> *metaEventsByPrio_;
|
||||
|
||||
//! list of all asserts: unused
|
||||
std::list<epoch::altarica::Assertion*> * asserts_;
|
||||
|
||||
//! the main node (default: "main")
|
||||
epoch::altarica::Node * mainNode_;
|
||||
|
||||
//! helper to build global var list
|
||||
void addVars(epoch::altarica::Node* n);
|
||||
|
||||
//! helper to build global event list
|
||||
void addEvents(epoch::altarica::Node* n);
|
||||
|
||||
//! helper to build global sync list
|
||||
void addSyncs(epoch::altarica::Node* n);
|
||||
|
||||
//! helper to build global assert list
|
||||
void addAsserts(epoch::altarica::Node* n);
|
||||
|
||||
//! helper to build global lists
|
||||
void addGlobalDataRec(epoch::altarica::Node *n);
|
||||
|
||||
//! fusion/elimination of simple affectations
|
||||
void compactSimpleAssertsRec(epoch::altarica::Node *n);
|
||||
|
||||
//! compute metaevents
|
||||
/*! compute all metaevents
|
||||
if no state (NULL) no checking of preconditions -> use only with !onTheFly
|
||||
*/
|
||||
std::vector<epoch::altarica::MetaEvent*> * computeMetaEventsNoDirac(epoch::altarica::AltaricaState *s);
|
||||
std::vector<epoch::altarica::MetaEvent*> * computeDiracMetaEvents();
|
||||
|
||||
//! sub function of computeMetaEvents
|
||||
std::vector<epoch::altarica::MetaEvent*> * findAndRemoveMetas(epoch::altarica::Event*e, std::vector<epoch::altarica::MetaEvent*> * metas);
|
||||
|
||||
//! prioritize metaEvents as given by computeMetaEvents
|
||||
std::vector<std::vector<epoch::altarica::MetaEvent*> *> * buildPrioritizedMetaEvents(std::vector<epoch::altarica::MetaEvent*> *);
|
||||
|
||||
//! helper for buildPrioritizedMetaEvents
|
||||
std::vector<std::vector<epoch::altarica::MetaEvent*>*>* splitPrioClass(std::vector<epoch::altarica::MetaEvent*>* prioClass);
|
||||
|
||||
//! helper for buildPrioritizedMetaEvents
|
||||
epoch::altarica::MetaEvent* popMorePrio(std::vector<epoch::altarica::MetaEvent*> * prioClass);
|
||||
|
||||
//! helper for buildPrioritizedMetaEvents
|
||||
epoch::altarica::MetaEvent* popSamePrio(std::vector<epoch::altarica::MetaEvent*> *prioClass, epoch::altarica::MetaEvent* p);
|
||||
|
||||
static void computeDiscreteProbas(std::vector<MetaEvent*>* mev, bool mayHaveDirac, AltaricaModel *am, AltaricaState *as);
|
||||
static void giveContinuousProbas(std::vector<MetaEvent*>* mev, bool mayHaveDirac, AltaricaModel *am, AltaricaState *as);
|
||||
static std::vector<MetaEvent*>* orderMetaEventMostProbableFirst(std::vector<MetaEvent*>* mev);
|
||||
static std::vector<MetaEvent*>* orderMetaEventLessProbableFirst(std::vector<MetaEvent*>* mev);
|
||||
static std::vector<MetaEvent*>* orderMetaEventNOOP(std::vector<MetaEvent*>* mev);
|
||||
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsMostPrioOnlyOnTheFly(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsMostPrioOnlyOffLine(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsAllOnTheFly(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsAllOffLine(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsDiracOnTheFly(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsDiracOffLine(AltaricaState *state);
|
||||
|
||||
static void purgeMetaEvents(std::vector<MetaEvent*>*);
|
||||
|
||||
|
||||
static bool noProba(std::vector<MetaEvent*>* mev);
|
||||
static bool noProba(MetaEvent* mev);
|
||||
static bool hasDirac(std::vector<MetaEvent*> * mev);
|
||||
// static bool dirac(MetaEvent* mev);
|
||||
static bool discrete(std::vector<MetaEvent*>* mev);
|
||||
bool diracEnabled(AltaricaState*s);
|
||||
std::vector<MetaEvent*> * computeDiracMetaEvents(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsDirac(AltaricaState *state);
|
||||
AltaricaState * forwardDirac(AltaricaState *s, std::vector<const Variable*>* = NULL);
|
||||
|
||||
|
||||
bool isInAssigned(Variable* v, std::vector<std::vector<const Variable*>* >& assigned);
|
||||
bool isInAlreadyAssignedInDirac(const Variable* v, std::vector<const Variable*>* assigned);
|
||||
bool isInAlreadyAssignedInDirac(std::vector<const Variable*> *vv, std::vector<const Variable*>* assigned);
|
||||
static bool debugSemantics;
|
||||
|
||||
public:
|
||||
|
||||
//! simple constructor
|
||||
AltaricaModel(bool continuous = false);
|
||||
//! complex constructor :)
|
||||
~AltaricaModel();
|
||||
|
||||
void setInitInfo(std::string initFile);
|
||||
|
||||
AltaricaInitInfo * getInitInfo() const {return initInfo;}
|
||||
|
||||
// Functors changes
|
||||
|
||||
void giveMostProbableTransitionFirst() { metaEventOrderer = &AltaricaModel::orderMetaEventMostProbableFirst;}
|
||||
void giveLessProbableTransitionFirst() {metaEventOrderer = &AltaricaModel::orderMetaEventLessProbableFirst;}
|
||||
void setContinuous() {probaComputer = &AltaricaModel::giveContinuousProbas; discrete_ = false;}
|
||||
void setDiscrete() {probaComputer = &AltaricaModel::computeDiscreteProbas; discrete_ = true;}
|
||||
|
||||
bool discrete() {return discrete_;}
|
||||
|
||||
//! setter for the parser
|
||||
void addConstant(epoch::altarica::Constant* c);
|
||||
|
||||
//! setter for the parser
|
||||
void addDomain(epoch::altarica::Domain* d);
|
||||
|
||||
//! setter for the parser
|
||||
void addNode(epoch::altarica::Node* n);
|
||||
|
||||
//! after parsing, finlizing the model is mandatory
|
||||
void finalize(std::string mainNodeName = "main", bool onTheFlyMeta = true);
|
||||
void finalizeRec(epoch::altarica::Node *n);
|
||||
|
||||
static void setDebugSemantics(bool d) { AltaricaModel::debugSemantics = d;}
|
||||
static bool getDebugSemantics() { return AltaricaModel::debugSemantics; }
|
||||
//! find a node in the node list
|
||||
/*! mainly used for parsing */
|
||||
epoch::altarica::Node * findNodeByName(const std::string& s);
|
||||
const epoch::altarica::Node * findNodeByFullName(const std::string& s) const;
|
||||
epoch::altarica::Node* findNodeByFullName(const std::string& s) {
|
||||
return const_cast<Node*>(
|
||||
const_cast<const AltaricaModel*>(this)
|
||||
->findNodeByFullName(s));
|
||||
}
|
||||
std::vector<epoch::altarica::Node*> * findNodesByType(const std::string& s);
|
||||
//! find a constant in the constant list
|
||||
/*! used only by parsing */
|
||||
epoch::altarica::Constant * findConstantByName(const std::string& s) const;
|
||||
//! find a domain in the domain list
|
||||
/*! used only by parsing */
|
||||
epoch::altarica::Domain * findDomainByName(const std::string& s);
|
||||
|
||||
const epoch::altarica::Node * getMainNode() const {return mainNode_;}
|
||||
|
||||
//! build initial state
|
||||
/*! as stated by init declarations of the .alt file*/
|
||||
epoch::altarica::AltaricaState * initialState();
|
||||
|
||||
//! Orders the assertions in dataflow
|
||||
void orders_assertions();
|
||||
|
||||
//! give possible metaEvents for a given state of higher priority (useless for probabilistic MC)
|
||||
std::vector<epoch::altarica::MetaEvent*> * getEnabledMetaEventsMostPrioOnly(epoch::altarica::AltaricaState *s);
|
||||
|
||||
//! give possible metaEvents for a given state
|
||||
std::vector<epoch::altarica::MetaEvent*> * getEnabledMetaEventsAll(epoch::altarica::AltaricaState *s);
|
||||
|
||||
//! generate a new state from a state and a metaevent
|
||||
/*! if metaEvent is not enabled (does not come from getEnabledMetaEvents) -> trouble ahead */
|
||||
// void getNextState(epoch::altarica::AltaricaState *s, epoch::altarica::MetaEvent* me,
|
||||
// epoch::altarica::AltaricaState *ns);
|
||||
//! get next state, + allocation of a new state
|
||||
|
||||
epoch::altarica::AltaricaState * getNextState(epoch::altarica::AltaricaState *s, epoch::altarica::MetaEvent* me);
|
||||
// std::vector<epoch::altarica::AltaricaState*> *getNextStatesFull(epoch::altarica::AltaricaState *s);
|
||||
// std::vector<epoch::altarica::AltaricaState*> *getNextStatesPartial(epoch::altarica::AltaricaState *s);
|
||||
|
||||
//! helper for dealing with labri-style priorities in syncs
|
||||
static bool hasEventDAG(std::vector<epoch::altarica::MetaEvent*>* prioClass);
|
||||
|
||||
//! print all flow variables and values at a given state
|
||||
void evaluateFlowVars(epoch::altarica::AltaricaState *s) const;
|
||||
|
||||
//! evalute a flow var
|
||||
Value * getFlowVarValueAndRelease(AltaricaState *s, std::string n);
|
||||
//! reads a state var
|
||||
Value * getStateVarValue(AltaricaState *s, std::string n);
|
||||
//! gives a var value
|
||||
Value * getVarValueAndRelease(AltaricaState *s, std::string n);
|
||||
|
||||
unsigned int getNFlowVars() const {return flowVars.size();}
|
||||
unsigned int getNStateVars() const {return stateVars.size();}
|
||||
unsigned int getNNodes() const {return nodes.size();}
|
||||
unsigned int getNEvents() const {return atomicEvents.size();}
|
||||
|
||||
Variable* getStateVar(unsigned int i) const;
|
||||
Variable* getFlowVar(unsigned int i) const;
|
||||
|
||||
bool existsVar(std::string n);
|
||||
|
||||
void setInitInfoXML(std::string initFile);
|
||||
AltaricaJson * setInitInfoJSON(std::string initFile);
|
||||
|
||||
|
||||
const std::vector<epoch::altarica::Event*>& getAtomicDiracEvents() const {
|
||||
return atomicDiracEvents;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Event*>& getAtomicEvents() const {
|
||||
return atomicEvents;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Constant*>& getConstants() const {
|
||||
return constants;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::MetaEvent*>& getMetaEvents() const {
|
||||
return *metaEvents_;
|
||||
}
|
||||
|
||||
std::list<epoch::altarica::Assertion*>& getAsserts() const {
|
||||
return *asserts_;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Domain*>& getDomains() const {
|
||||
return domains;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Variable*>& getFlowVars() const {
|
||||
return flowVars;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Node*>& getNodes() const {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Variable*>& getStateVars() const {
|
||||
return stateVars;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Synchronisation*>& getSyncs() const {
|
||||
return syncs;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
409
src/grammars/altarica/AltaricaState.cc
Normal file
409
src/grammars/altarica/AltaricaState.cc
Normal file
@@ -0,0 +1,409 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "AltaricaState.hh"
|
||||
#include "Assignment.hh"
|
||||
#include <sstream>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include "AltaricaModel.hh"
|
||||
#include <iostream>
|
||||
#include "Values.hh"
|
||||
#include "Variable.hh"
|
||||
#include "AltaricaInitInfo.hh"
|
||||
#include <cassert>
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
AltaricaState::AltaricaState(bool initial, const AltaricaModel *amodel, AltaricaInitInfo *initInfo) : amodel_(amodel), cache(NULL) {
|
||||
unsigned int ns = amodel_->getNStateVars();
|
||||
unsigned int nf = amodel_->getNFlowVars();
|
||||
stateVars_.resize(ns,NULL);
|
||||
flowVars_.resize(nf,NULL);
|
||||
|
||||
if (initial) {
|
||||
for (unsigned int i = 0; i<ns; ++i) {
|
||||
Value * v = NULL;
|
||||
// if we have something to init in initFile, take value here
|
||||
Value *iv = NULL;
|
||||
if (initInfo != NULL)
|
||||
iv = initInfo->getInitValue(i);
|
||||
if (iv != NULL) {
|
||||
v = iv;
|
||||
} else {
|
||||
const Assignment * init = amodel_->getStateVar(i)->getInit();
|
||||
if (init != NULL) {
|
||||
v = amodel_->getStateVar(i)->getInit()->evaluate(amodel, this, amodel_->getStateVar(i)->getNode());
|
||||
}
|
||||
}
|
||||
if (v == NULL) {
|
||||
std::string b = "cannot init variable: " + amodel_->getStateVar(i)->toString();
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(b));
|
||||
exit(-1);
|
||||
}
|
||||
if (v->isSymbol()) {
|
||||
EnumDomain * d = (EnumDomain*) amodel_->getStateVar(i)->getDomain();
|
||||
ValueSymbol* vs = (ValueSymbol*) v;
|
||||
if (!d->contains(vs->toSymbol()))
|
||||
{
|
||||
std::string s = "unknown value: ";
|
||||
s+= vs->toSymbol();
|
||||
s+= " for variable " ;
|
||||
s+= amodel_->getStateVar(i)->toString();
|
||||
s+= " should be in ";
|
||||
s+= amodel_->getStateVar(i)->getDomain()->toString();
|
||||
throw AltaricaException(s, "AltaricaState constructor of initial state");
|
||||
}
|
||||
|
||||
vs->setDomain((EnumDomain*)amodel_->getStateVar(i)->getDomain());
|
||||
}
|
||||
stateVars_[i] = v;
|
||||
v->own();
|
||||
}
|
||||
rehash_();
|
||||
}
|
||||
}
|
||||
|
||||
AltaricaState::AltaricaState(const std::vector<Value*> &mstate, const AltaricaModel *amodel) {
|
||||
amodel_ = amodel;
|
||||
cache = NULL;
|
||||
stateVars_.assign(mstate.begin(),mstate.end());
|
||||
for (unsigned int i = 0; i< stateVars_.size(); ++i)
|
||||
if (stateVars_[i] != NULL)
|
||||
stateVars_[i]->own();
|
||||
flowVars_.resize(amodel_->getNFlowVars(),NULL);
|
||||
}
|
||||
|
||||
void AltaricaState::addValue(const Variable* var, Value*v) {
|
||||
if (var->isState())
|
||||
addStateValue(var->getIndex(), v);
|
||||
else
|
||||
addFlowValue(var->getIndex(), v);
|
||||
}
|
||||
|
||||
bool AltaricaState::isEmpty() const {
|
||||
for (unsigned int i=0; i< stateVars_.size(); ++i)
|
||||
if (stateVars_[i] != NULL)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void AltaricaState::setValue(const Variable*var, Value *val) {
|
||||
|
||||
if (var->isState()) {
|
||||
if (val->isSymbol()) {
|
||||
ValueSymbol* vs = (ValueSymbol*) val;
|
||||
vs->setDomain((EnumDomain*)var->getDomain());
|
||||
}
|
||||
setStateValue(var->getIndex(),val);
|
||||
} else
|
||||
setFlowValue(var->getIndex(),val);
|
||||
}
|
||||
|
||||
void AltaricaState::addStateValue(unsigned int i, Value*val) {
|
||||
if (val == NULL)
|
||||
return;
|
||||
if (stateVars_[i] == NULL) {
|
||||
stateVars_[i] = val;
|
||||
} else {
|
||||
if (stateVars_[i]->ro())
|
||||
stateVars_[i] = stateVars_[i]->clone();
|
||||
stateVars_[i]->merge(val);
|
||||
}
|
||||
stateVars_[i]->own();
|
||||
Value::deleteIfPossible(val);
|
||||
}
|
||||
|
||||
|
||||
void AltaricaState::setStateValue(unsigned int i, Value*val) {
|
||||
if (val == NULL)
|
||||
return;
|
||||
Value::release(stateVars_[i]);
|
||||
val->own();
|
||||
stateVars_[i] = val;
|
||||
}
|
||||
|
||||
void AltaricaState::addFlowValue(unsigned int i, Value*val) {
|
||||
if (val == NULL)
|
||||
return;
|
||||
if (flowVars_[i] == NULL) {
|
||||
flowVars_[i] = val;
|
||||
} else {
|
||||
if (flowVars_[i]->ro())
|
||||
flowVars_[i] = flowVars_[i]->clone();
|
||||
flowVars_[i]->merge(val);
|
||||
}
|
||||
flowVars_[i]->own();
|
||||
Value::deleteIfPossible(val);
|
||||
}
|
||||
|
||||
|
||||
void AltaricaState::setFlowValue(unsigned int i, Value*val) {
|
||||
if (val != NULL)
|
||||
val->own();
|
||||
Value::release(flowVars_[i]);
|
||||
flowVars_[i] = val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Value * AltaricaState::getValue(const Variable *v) const{
|
||||
// if (hasValue(v))
|
||||
// return (*vars_)[v];
|
||||
// else
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
|
||||
bool AltaricaState::hasStateValue(unsigned int i ) const {
|
||||
if (stateVars_[i] == NULL)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool AltaricaState::hasValue(const Variable * v) const {
|
||||
if (v->isState()) {
|
||||
if (stateVars_[v->getIndex()] == NULL)
|
||||
return false;
|
||||
return true;
|
||||
} else {
|
||||
if (flowVars_[v->getIndex()] == NULL)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Value * AltaricaState::getValue(const Variable *v) const {
|
||||
if (v->isState()) {
|
||||
return stateVars_[v->getIndex()];
|
||||
} else {
|
||||
return flowVars_[v->getIndex()];
|
||||
}
|
||||
}
|
||||
|
||||
Value * AltaricaState::getStateValue(unsigned int i) const {
|
||||
return stateVars_[i];
|
||||
}
|
||||
|
||||
Value * AltaricaState::getFlowValue(unsigned int i) const {
|
||||
return flowVars_[i];
|
||||
}
|
||||
|
||||
void AltaricaState::removeValue(const Variable *v) {
|
||||
if (v->isState()) {
|
||||
Value * vv = stateVars_[v->getIndex()];
|
||||
Value::release(vv);
|
||||
stateVars_[v->getIndex()] = NULL;
|
||||
} else {
|
||||
Value * vv = flowVars_[v->getIndex()];
|
||||
if (vv != NULL)
|
||||
Value::release(vv);
|
||||
flowVars_[v->getIndex()] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void AltaricaState::releaseFlowVars() const {
|
||||
for (unsigned int i = 0; i<flowVars_.size(); ++i) {
|
||||
Value::release(flowVars_[i]);
|
||||
flowVars_[i]= NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void AltaricaState::deleteFlowValues() {
|
||||
for (unsigned int i = 0; i<flowVars_.size(); ++i) {
|
||||
Value::release(flowVars_[i]);
|
||||
flowVars_[i]= NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void AltaricaState::mergeToState(AltaricaState*s) const {
|
||||
unsigned int i = 0;
|
||||
for (std::vector<Value*>::const_iterator vi = stateVars_.begin(); vi!= stateVars_.end(); ++vi)
|
||||
s->addStateValue(i++, *vi);
|
||||
i = 0;
|
||||
for (std::vector<Value*>::const_iterator vi = flowVars_.begin(); vi!= flowVars_.end(); ++vi)
|
||||
s->addFlowValue(i++, *vi);
|
||||
}
|
||||
|
||||
void AltaricaState::intersectState(const AltaricaState *s) {
|
||||
if (s == NULL)
|
||||
return;
|
||||
for (unsigned int i = 0; i< amodel_->getNStateVars(); ++i)
|
||||
removeValue(i, s->getStateValue(i));
|
||||
}
|
||||
|
||||
void AltaricaState::mergeIntersectState (const AltaricaState *s) {
|
||||
if (s == NULL)
|
||||
return;
|
||||
for (unsigned int i = 0; i< amodel_->getNStateVars(); ++i) {
|
||||
if (hasStateValue(i)) {
|
||||
if (s->hasStateValue(i))
|
||||
getStateValue(i)->intersectValue(s->getStateValue(i));
|
||||
} else {
|
||||
setStateValue(i, s->getStateValue(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void AltaricaState::removeValue(const Variable *v, const Value*vv) {
|
||||
removeValue(v->getIndex(), vv);
|
||||
}
|
||||
|
||||
void AltaricaState::removeValue(unsigned int i, const Value*vv) {
|
||||
Value *v = stateVars_[i];
|
||||
if (v != NULL) {
|
||||
if (v->ro())
|
||||
v = v->clone();
|
||||
v->removeValue(vv);
|
||||
if (v->card() == 0) {
|
||||
Value::deleteIfPossible(v);
|
||||
v = NULL;
|
||||
} else
|
||||
v->own();
|
||||
stateVars_[i] = v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AltaricaState::~AltaricaState() {
|
||||
for (std::vector<Value*>::iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
Value::release(*i);
|
||||
}
|
||||
releaseFlowVars();
|
||||
Value::release(cache);
|
||||
}
|
||||
|
||||
AltaricaState * AltaricaState::clone() const {
|
||||
AltaricaState * n = new AltaricaState(stateVars_,amodel_);
|
||||
n->setHash(hash_);
|
||||
return n;
|
||||
|
||||
}
|
||||
|
||||
// AltaricaState * AltaricaState::getMacroState() const {
|
||||
// AltaricaState *n = new AltaricaState((*stateVars_),amodel_,true);
|
||||
// n->rehash_();
|
||||
// return n;
|
||||
// }
|
||||
|
||||
// unsigned int AltaricaState::size() {
|
||||
// return vars_->size();
|
||||
// }
|
||||
|
||||
void AltaricaState::setHash(size_t h) {
|
||||
hash_ = h;
|
||||
}
|
||||
|
||||
bool AltaricaState::equals(AltaricaState *s) {
|
||||
// if (this == s)
|
||||
// return true;
|
||||
unsigned int j = 0;
|
||||
for (std::vector<Value*>::iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
if ( ((*i) != s->getStateValue(j)) && !(*i)->equals(s->getStateValue(j)) )
|
||||
return false;
|
||||
++j;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string AltaricaState::toString(bool state, bool flow, bool printNULL, bool printDomain) {
|
||||
std::stringstream ss;
|
||||
// std::string s;
|
||||
if (state) {
|
||||
if (flow)
|
||||
ss << "STATE VARS:"<<std::endl;
|
||||
unsigned int j = 0;
|
||||
for (std::vector<Value*>::iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
if (printNULL ||(*i) != NULL ) {
|
||||
Variable * v = amodel_->getStateVar(j);
|
||||
ss << v->toString();
|
||||
if ((*i) != NULL) {
|
||||
ss << " : " << (*i)->toString();// << "(" << *i << ")" ;
|
||||
if (printDomain)
|
||||
ss << " in " << v->getDomain()->toString();
|
||||
ss <<";" ;
|
||||
} else
|
||||
ss<< " : NULL;";
|
||||
ss<< std::endl;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
if (flow) {
|
||||
if (state)
|
||||
ss<< "FLOW VARS:\n";
|
||||
unsigned int j = 0;
|
||||
for (std::vector<Value*>::iterator i = flowVars_.begin(); i!= flowVars_.end(); ++i) {
|
||||
Variable *v = amodel_->getFlowVar(j++);
|
||||
ss << v->toString();
|
||||
if ((*i) != NULL)
|
||||
ss<< " : " << (*i)->toString() << " in " << v->getDomain()->toString() <<";" ;
|
||||
ss<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
void AltaricaState::rehash_() {
|
||||
hash_ = 0;
|
||||
boost::hash<int> int_hash;
|
||||
for (std::vector<Value*>::iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
int h = (*i)->toHash();
|
||||
boost::hash_combine(hash_, int_hash(h));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::size_t AltaricaState::hash() {
|
||||
return hash_;
|
||||
}
|
||||
|
||||
bool AltaricaState::operator<(const AltaricaState&o) const {
|
||||
unsigned int j = 0;
|
||||
for (std::vector<Value*>::const_iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
Value* ov = o.getStateValue(j++);
|
||||
|
||||
if ((*i)->less(ov))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
109
src/grammars/altarica/AltaricaState.hh
Normal file
109
src/grammars/altarica/AltaricaState.hh
Normal file
@@ -0,0 +1,109 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_STATE_HH
|
||||
#define ALTARICA_STATE_HH
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaModel;
|
||||
class Variable;
|
||||
class Value;
|
||||
class AltaricaInitInfo;
|
||||
|
||||
class AltaricaState {
|
||||
|
||||
private:
|
||||
std::vector<Value*> stateVars_;
|
||||
mutable std::vector<Value*> flowVars_;
|
||||
const AltaricaModel * amodel_;
|
||||
std::size_t hash_;
|
||||
// bool macro_;
|
||||
|
||||
Value *cache;
|
||||
public:
|
||||
// AltaricaState(const AltaricaModel* amodel);
|
||||
AltaricaState(bool initial, const AltaricaModel* amodel, AltaricaInitInfo *initInfo);
|
||||
AltaricaState(const std::vector<Value*> &mstate, const AltaricaModel* amodel);
|
||||
|
||||
// bool isMacro() {return macro_;}
|
||||
|
||||
void setValue(const Variable* var, Value*v);
|
||||
void setStateValue(unsigned int i, Value*val);
|
||||
void setFlowValue(unsigned int i, Value*val);
|
||||
|
||||
// macro state specifics
|
||||
void addValue(const Variable* var, Value*v);
|
||||
void addStateValue(unsigned int i, Value*val);
|
||||
void addFlowValue(unsigned int i, Value*val);
|
||||
|
||||
Value * getValue(const Variable *v) const;
|
||||
Value * getStateValue(unsigned int i) const;
|
||||
Value * getFlowValue(unsigned int i) const;
|
||||
|
||||
void mergeToState(AltaricaState *s) const;
|
||||
void intersectState(const AltaricaState *s);
|
||||
void mergeIntersectState(const AltaricaState *s);
|
||||
|
||||
bool isEmpty() const;
|
||||
|
||||
~AltaricaState();
|
||||
AltaricaState *clone()const;
|
||||
// AltaricaState * getMacroState() const;
|
||||
|
||||
bool equals(AltaricaState*s);
|
||||
// unsigned int size();
|
||||
bool hasValue( const Variable * v) const;
|
||||
bool hasStateValue(unsigned int i) const;
|
||||
std::string toString(bool printStateVar, bool printFlowVar, bool printNULL = true, bool printDomain = true);
|
||||
void removeValue(const Variable *v);
|
||||
void removeValue(const Variable *v, const Value*vv);
|
||||
void removeValue(unsigned int i, const Value*vv);
|
||||
|
||||
std::size_t hash();
|
||||
bool operator<(const AltaricaState&o) const;
|
||||
|
||||
void rehash_();
|
||||
void setHash(size_t h);
|
||||
|
||||
inline const AltaricaModel * getAModel() const {return amodel_;}
|
||||
void releaseFlowVars() const;
|
||||
void deleteFlowValues() ;
|
||||
|
||||
Value * getCachedValue() {return cache;}
|
||||
void setCachedValue(Value *vv) {cache = vv;}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
77
src/grammars/altarica/Assertion.cc
Normal file
77
src/grammars/altarica/Assertion.cc
Normal file
@@ -0,0 +1,77 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Assertion.hh"
|
||||
#include "Node.hh"
|
||||
#include <limits.h>
|
||||
#include "expressions/ExpressionLOG.hh"
|
||||
#include "Values.hh"
|
||||
#include "Variable.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
std::vector<Variable*> * Assertion::infoVars(const AltaricaModel* am, bool flow, bool computed) const {
|
||||
return assert_->infoVars(am, n_, flow, computed);
|
||||
}
|
||||
|
||||
void Assertion::evaluate(const AltaricaModel* am, AltaricaState *s) const {
|
||||
Value * v = assert_->evaluate(am, s, n_,true);
|
||||
Value::deleteIfPossible(v);
|
||||
}
|
||||
|
||||
void Assertion::evaluateLM(const AltaricaModel*am, LandmarkState *lms) const {
|
||||
assert_->evaluateLM(am, lms, n_,true);
|
||||
}
|
||||
|
||||
void Assertion::addVariable(Variable* v) {
|
||||
if (variables_ == NULL)
|
||||
variables_ = new std::vector<Variable*>();
|
||||
// std::cerr << "Adding to assertion variable " << v->getFullName() << std::endl;
|
||||
variables_->push_back(v);
|
||||
}
|
||||
|
||||
const std::vector<Variable*> * Assertion::getVars() const {
|
||||
return variables_;
|
||||
}
|
||||
|
||||
Assertion::~Assertion() {
|
||||
delete variables_;
|
||||
}
|
||||
|
||||
|
||||
std::pair<Variable*,Variable*> * Assertion::isSimpleAffect(const AltaricaModel *am) {
|
||||
ExpressionLOG * el = dynamic_cast<ExpressionLOG*>(assert_);
|
||||
if (el == NULL)
|
||||
return NULL;
|
||||
return el->isSimpleAffect(am, n_);
|
||||
}
|
||||
|
||||
Assertion * Assertion::clone() const {
|
||||
return new Assertion(assert_);
|
||||
}
|
||||
77
src/grammars/altarica/Assertion.hh
Normal file
77
src/grammars/altarica/Assertion.hh
Normal file
@@ -0,0 +1,77 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_ASSERT_H_
|
||||
#define ALTA_ASSERT_H_
|
||||
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "expressions/Expression.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Node;
|
||||
class Variable;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
class LandmarkState;
|
||||
|
||||
class Assertion {
|
||||
protected:
|
||||
Expression * assert_;
|
||||
Node * n_;
|
||||
std::vector<Variable*>* variables_;
|
||||
public:
|
||||
Assertion(Expression * a): assert_(a), n_(NULL) {
|
||||
variables_ = NULL;
|
||||
}
|
||||
~Assertion();
|
||||
|
||||
std::vector<Variable*> * infoVars(const AltaricaModel *am, bool flow, bool computed) const;
|
||||
|
||||
void setNode(Node *n) {n_ = n;}
|
||||
const Node * getNode() {return n_;}
|
||||
const Expression * getExpr() const {return assert_;}
|
||||
void addVariable(Variable* a);
|
||||
const std::vector<Variable*> * getVars() const;
|
||||
|
||||
void evaluate(const AltaricaModel *am, AltaricaState *s) const;
|
||||
void evaluateLM(const AltaricaModel *am, LandmarkState *lms) const;
|
||||
|
||||
std::pair<Variable*,Variable*> * isSimpleAffect(const AltaricaModel*am);
|
||||
|
||||
Assertion * clone() const;
|
||||
|
||||
void deleteExpr() {delete assert_;}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
80
src/grammars/altarica/Assignment.cc
Normal file
80
src/grammars/altarica/Assignment.cc
Normal file
@@ -0,0 +1,80 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Assignment.hh"
|
||||
#include "Node.hh"
|
||||
#include <iostream>
|
||||
#include "expressions/Expression.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
// void Assignment::matchVariable(bool init) {
|
||||
// std::cerr << "matching variable " << *(ma_->toString());
|
||||
// std::cerr << " of node " << *(n_->getMA()->toString());
|
||||
// Variable *v = n_->findVariableByName(ma_);
|
||||
// if (init)
|
||||
// n_->findVariableByName(ma_)->setInit(this);
|
||||
// }
|
||||
|
||||
|
||||
Value * Assignment::evaluate(const AltaricaModel *am, AltaricaState * m, const Node *n) const {
|
||||
return e_->evaluate(am,m,n);
|
||||
}
|
||||
|
||||
Value * Assignment::evaluate(const AltaricaModel *am, AltaricaState * m) const {
|
||||
return e_->evaluate(am, m,n_);
|
||||
}
|
||||
|
||||
|
||||
void Assignment::setNode(Node*n) {
|
||||
n_ = n;
|
||||
// if (n_ != NULL)
|
||||
// matchVariable(false);
|
||||
if (n_ != NULL) {
|
||||
v_ = n_->findVariableByName(ma_);
|
||||
if (v_ == NULL) {
|
||||
std::cerr << "COULD NOT MATCH VARIABLE " << ma_->toString() << " in node " << n_->toString() <<
|
||||
" in assignment " << ma_->toString() << " := " << e_->toString() << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Assignment::deleteExprs() {
|
||||
delete e_;
|
||||
// delete oe_;
|
||||
}
|
||||
|
||||
Assignment::~Assignment() {
|
||||
delete ma_;
|
||||
}
|
||||
82
src/grammars/altarica/Assignment.hh
Normal file
82
src/grammars/altarica/Assignment.hh
Normal file
@@ -0,0 +1,82 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_ASSIGNMENT_H_
|
||||
#define ALTA_ASSIGNMENT_H_
|
||||
|
||||
#include "MemberAccess.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Node;
|
||||
class Variable;
|
||||
class Expression;
|
||||
class Value;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
|
||||
class Assignment {
|
||||
protected :
|
||||
//! liste des membres a affecter
|
||||
MemberAccess* ma_;
|
||||
|
||||
//! affectation à donner au membre correspondant
|
||||
Expression* e_;
|
||||
// Expression* oe_;
|
||||
|
||||
Node * n_;
|
||||
|
||||
Variable * v_;
|
||||
|
||||
public :
|
||||
Assignment(MemberAccess* m, Expression*e):ma_(m),e_(e),n_(NULL),v_(NULL) {
|
||||
// oe_ = e_->toOpenExpr();
|
||||
}
|
||||
~Assignment();
|
||||
|
||||
Assignment * clone() const {return new Assignment(ma_->clone(), e_);}
|
||||
|
||||
void setNode(Node*n);
|
||||
Node * getNode() {return n_;}
|
||||
|
||||
// void matchVariable(bool init);
|
||||
|
||||
const Variable* getVar() const {return v_;}
|
||||
const Expression * getExpr() const {return e_;}
|
||||
|
||||
Value * evaluate(const AltaricaModel *am, AltaricaState *m, const Node *n) const;
|
||||
Value * evaluate(const AltaricaModel *am, AltaricaState *m) const;
|
||||
|
||||
|
||||
void deleteExprs();
|
||||
|
||||
const MemberAccess * getMA() {return ma_;}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
99
src/grammars/altarica/CMakeLists.txt
Normal file
99
src/grammars/altarica/CMakeLists.txt
Normal file
@@ -0,0 +1,99 @@
|
||||
# This file is part of EPOCH.
|
||||
# File: CMakeLists.txt
|
||||
# Author: Florent Teichteil-Königsbuch
|
||||
# Contact: florent.teichteil@onera.fr
|
||||
#
|
||||
# EPOCH is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# EPOCH is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with EPOCH. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#FIND_PACKAGE(LibXML++ REQUIRED)
|
||||
#set(LIBS ${LIBS} ${LibXML++_LIBRARIES})
|
||||
|
||||
|
||||
BISON_TARGET (AltaricaParser altarica.yy ${CMAKE_CURRENT_BINARY_DIR}/altarica_parser.cc)
|
||||
FLEX_TARGET (AltaricaScanner altarica.l ${CMAKE_CURRENT_BINARY_DIR}/altarica_lexer.cc COMPILE_FLAGS --header-file=${CMAKE_CURRENT_BINARY_DIR}/altarica_lexer.h)
|
||||
ADD_FLEX_BISON_DEPENDENCY (AltaricaScanner AltaricaParser)
|
||||
|
||||
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
# ${LibXML++_INCLUDE_DIRS}
|
||||
)
|
||||
ADD_LIBRARY (epoch-altarica SHARED
|
||||
${BISON_AltaricaParser_OUTPUTS}
|
||||
${FLEX_AltaricaScanner_OUTPUTS}
|
||||
AltaricaGenerator.cc
|
||||
AltaricaState.cc
|
||||
AltaricaModel.cc
|
||||
AltaricaInitInfo.cc
|
||||
AltaricaException.cc
|
||||
# AltaricaInitInfoXML.cc
|
||||
AltaricaInitInfoXML2.cc
|
||||
AltaricaJson.cc
|
||||
AltaricaInteractive.cc
|
||||
MetaEvent.cc
|
||||
domains/RangeDomain.cc
|
||||
domains/Domain.cc
|
||||
domains/EnumDomain.cc
|
||||
domains/PredefinedDomain.cc
|
||||
domains/StructuredDomain.cc
|
||||
domains/ArrayDomain.cc
|
||||
domains/RealDomain.cc
|
||||
Parameter.cc
|
||||
Variable.cc
|
||||
Event.cc
|
||||
Assignment.cc
|
||||
EventLaw.cc
|
||||
Constant.cc
|
||||
MemberAccess.cc
|
||||
Transition.cc
|
||||
Synchronisation.cc
|
||||
Assertion.cc
|
||||
Node.cc
|
||||
values/Value.cc
|
||||
values/ValueBool.cc
|
||||
values/ValueInt.cc
|
||||
values/ValueSymbol.cc
|
||||
values/ValueReal.cc
|
||||
LandmarkState.cc
|
||||
LandmarkMetaEvent.cc
|
||||
LandmarkDriver.cc
|
||||
expressions/Expression.cc
|
||||
expressions/ExpressionADD.cc
|
||||
expressions/ExpressionAND.cc
|
||||
expressions/ExpressionARITH.cc
|
||||
expressions/ExpressionBOOLCONSTANT.cc
|
||||
expressions/ExpressionCONSTARRAY.cc
|
||||
expressions/ExpressionCONSTSTRUCT.cc
|
||||
expressions/ExpressionFUNCTIONCALL.cc
|
||||
expressions/ExpressionLOG.cc
|
||||
expressions/ExpressionMINMAX.cc
|
||||
expressions/ExpressionMUL.cc
|
||||
expressions/ExpressionOR.cc
|
||||
expressions/ExpressionQUANTIFIED.cc
|
||||
expressions/ExpressionUNARY.cc
|
||||
expressions/ExpressionUNSIGNEDINT.cc
|
||||
expressions/ExpressionREAL.cc
|
||||
expressions/ExpressionCARD.cc
|
||||
expressions/ExpressionCASE.cc
|
||||
expressions/ExpressionPAREN.cc
|
||||
expressions/ExpressionMEMBER.cc
|
||||
expressions/ExpressionINTERVAL.cc
|
||||
expressions/ExpressionIfThenElse.cc
|
||||
expressions/ExpressionEvaluator.cc
|
||||
expressions/ExpressionEvaluatorLandmark.cc
|
||||
expressions/ExpressionInfoVar.cc
|
||||
altarica_driver.cc
|
||||
parser_helper.cc
|
||||
FiacreTranslator.cc
|
||||
)
|
||||
|
||||
#TARGET_LINK_LIBRARIES (epoch-altarica ${LibXML++_LIBRARIES})
|
||||
80
src/grammars/altarica/Constant.cc
Normal file
80
src/grammars/altarica/Constant.cc
Normal file
@@ -0,0 +1,80 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Constant.hh"
|
||||
#include "./expressions/Expression.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
Constant::Constant(std::string name) : expr_(NULL), domain_(NULL) {
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
Constant::Constant(std::string name, Domain* d) : expr_(NULL) {
|
||||
name_ = name;
|
||||
domain_ = d;
|
||||
}
|
||||
|
||||
Constant::Constant(std::string name, Domain* d, Expression *expr) {
|
||||
name_ = name;
|
||||
domain_ = d;
|
||||
expr_ = expr;
|
||||
}
|
||||
|
||||
const Domain* Constant::getDomain() const {
|
||||
return domain_;
|
||||
}
|
||||
|
||||
const Expression* Constant::getExpression() const {
|
||||
return expr_;
|
||||
}
|
||||
|
||||
void Constant::setExpression(Expression *expr) {
|
||||
delete expr_;
|
||||
expr_=expr;
|
||||
}
|
||||
|
||||
Value * Constant::getValue(const AltaricaModel *am, AltaricaState *s, const Node* n) const {
|
||||
return expr_->evaluate(am, s, n);
|
||||
}
|
||||
|
||||
|
||||
// Constant* Constant::findConstantInVector(std::vector<Constant*> v,
|
||||
// std::string *constName) {
|
||||
// for (std::vector<Constant*>::iterator constIt = v.begin();
|
||||
// constIt != v.end(); ++constIt)
|
||||
// if ((*constIt)->getName() == constName)
|
||||
// return *constIt;
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
Constant::~Constant() {
|
||||
delete(expr_);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
79
src/grammars/altarica/Constant.hh
Normal file
79
src/grammars/altarica/Constant.hh
Normal file
@@ -0,0 +1,79 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_CONSTANT_H_
|
||||
#define ALTA_CONSTANT_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Domain;
|
||||
class Expression;
|
||||
class Value;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
class Node;
|
||||
|
||||
class Constant {
|
||||
|
||||
protected:
|
||||
|
||||
//!
|
||||
std::string name_;
|
||||
Domain * domain_;
|
||||
Expression * expr_;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//!
|
||||
Constant(std::string name);
|
||||
|
||||
Constant(std::string name, Domain* d);
|
||||
|
||||
Constant(std::string name, Domain* d, Expression *expr);
|
||||
~Constant();
|
||||
|
||||
const Domain* getDomain() const;
|
||||
const Expression* getExpression() const;
|
||||
void setExpression(Expression *expr);
|
||||
|
||||
Value * getValue(const AltaricaModel *am,
|
||||
AltaricaState *s,
|
||||
const Node* n) const;
|
||||
|
||||
static Constant* findConstantInVector(std::vector<Constant*>v,
|
||||
std::string *constName);
|
||||
|
||||
std::string getName() {return name_;}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
262
src/grammars/altarica/Event.cc
Normal file
262
src/grammars/altarica/Event.cc
Normal file
@@ -0,0 +1,262 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "Event.hh"
|
||||
#include "Transition.hh"
|
||||
#include "Node.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include "MemberAccess.hh"
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
// Event::Event(std::string * name) {
|
||||
// name_ = new std::string(*name);
|
||||
// this->path_ = NULL;
|
||||
// this->path_indexes_ = NULL;
|
||||
// }
|
||||
|
||||
|
||||
Event::Event(MemberAccess *ma) {
|
||||
ma_ = ma;
|
||||
law_ = NULL;
|
||||
}
|
||||
|
||||
|
||||
void Event::addUppers(std::set<Event*>* b) {
|
||||
for (std::set<Event*>::iterator it = b->begin();
|
||||
it != b->end(); ++it)
|
||||
addUpper(*it);
|
||||
}
|
||||
|
||||
void Event::addUpper(Event *b) {
|
||||
|
||||
uppers_.insert(b);
|
||||
for (std::set<Event*>::iterator li = lowers_.begin(); li!=lowers_.end(); ++li)
|
||||
(*li)->addUpper(b);
|
||||
}
|
||||
|
||||
|
||||
void Event::addLowers(std::set<Event*>* b) {
|
||||
for (std::set<Event*>::iterator it = b->begin();
|
||||
it != b->end(); ++it)
|
||||
addLower(*it);
|
||||
}
|
||||
|
||||
void Event::addLower(Event *b) {
|
||||
lowers_.insert(b);
|
||||
for (std::set<Event*>::iterator ui = uppers_.begin(); ui!=uppers_.end(); ++ui)
|
||||
(*ui)->addLower(b);
|
||||
}
|
||||
|
||||
|
||||
void Event::addAttribute(const std::string a) {
|
||||
attributes_.push_back(std::string(a));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Event::addAttributes(const std::vector<std::string> *va) {
|
||||
for (std::vector<std::string>::const_iterator si = va->begin(); si != va->end(); ++si) {
|
||||
addAttribute(*si);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Event::setLaw(EventLaw* el) {
|
||||
if (law_ != NULL)
|
||||
delete law_;
|
||||
law_ = el;
|
||||
if (law_ != NULL)
|
||||
law_->setNode(node_);
|
||||
}
|
||||
|
||||
const EventLaw * Event::getLaw() const {
|
||||
return law_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Event * Event::clone() {
|
||||
Event *n = new Event(ma_->clone());
|
||||
n->addAttributes(&attributes_);
|
||||
n->addUppers(&uppers_);
|
||||
n->addLowers(&lowers_);
|
||||
if (law_ != NULL)
|
||||
n->setLaw(law_->clone());
|
||||
|
||||
return n;
|
||||
}
|
||||
const MemberAccess* Event::getMA() const {
|
||||
return ma_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// void Event::addPath(std::string *p) {
|
||||
// if (path_ == NULL) {
|
||||
// path_ = new std::vector<std::string*>();
|
||||
// path_indexes_ = new std::vector<int>();
|
||||
// }
|
||||
|
||||
// path_->push_back(new std::string(*p));
|
||||
// path_indexes_->push_back(-1);
|
||||
// }
|
||||
|
||||
// void Event::addPathIndexed(std::string *p, int i) {
|
||||
// if (path_ == NULL) {
|
||||
// path_ = new std::vector<std::string*>();
|
||||
// path_indexes_ = new std::vector<int>();
|
||||
// }
|
||||
// path_->push_back(new std::string(*p));
|
||||
// path_indexes_->push_back(i);
|
||||
|
||||
// }
|
||||
|
||||
std::set<Event*> const * Event::getUppers() {
|
||||
return &uppers_;
|
||||
}
|
||||
|
||||
void Event::setNode(Node*n) {
|
||||
node_ = n;
|
||||
if (law_ != NULL)
|
||||
law_->setNode(n);
|
||||
}
|
||||
|
||||
void Event::addTrans(Transition* t) {
|
||||
trans_.push_back(t);
|
||||
}
|
||||
|
||||
void Event::addSync(Synchronisation* s) {
|
||||
bool found = false;
|
||||
for (std::vector<Synchronisation*>::iterator i = syncs_.begin(); i!= syncs_.end(); ++i)
|
||||
if (*i == s) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
syncs_.push_back(s);
|
||||
}
|
||||
|
||||
int Event::nSynchros() {
|
||||
return (syncs_.size());
|
||||
}
|
||||
|
||||
const Node * Event::getNode() {
|
||||
return node_;
|
||||
}
|
||||
|
||||
std::vector<const Node*>* Event::getPath() const {
|
||||
std::vector<const Node*>* path = node_->getPath();
|
||||
path->push_back(node_);
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string Event::getFullName() const {
|
||||
std::stringstream ss;
|
||||
for(auto &n: *getPath())
|
||||
ss << n->getMA()->toString() << ".";
|
||||
ss << getMA()->toString();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool Event::isMorePriorThan(Event*e) {
|
||||
if (e->getNode() != node_)
|
||||
return false;
|
||||
for (std::set<Event*>::iterator i = lowers_.begin(); i!= lowers_.end(); ++i) {
|
||||
if (e == *i)
|
||||
return true;
|
||||
}
|
||||
for (std::set<Event*>::iterator i = lowers_.begin(); i!= lowers_.end(); ++i) {
|
||||
return (*i)->isMorePriorThan(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Event::isLessPriorThan(Event*e) {
|
||||
if (e->getNode() != node_)
|
||||
return false;
|
||||
for (std::set<Event*>::iterator i = uppers_.begin(); i!= uppers_.end(); ++i) {
|
||||
if (e == *i)
|
||||
return true;
|
||||
}
|
||||
for (std::set<Event*>::iterator i = uppers_.begin(); i!= uppers_.end(); ++i) {
|
||||
return (*i)->isLessPriorThan(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Event::isEnabled(const AltaricaModel *am, AltaricaState *s) {
|
||||
if (law_ != NULL && law_->isDisabled())
|
||||
return false;
|
||||
if (s == NULL)
|
||||
return true;
|
||||
if (trans_.size() == 0)
|
||||
return true;
|
||||
for (std::vector<Transition*>::iterator ti = trans_.begin(); ti != trans_.end(); ++ti) {
|
||||
if ( (*ti)->precondOK(am, s))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Event::isDirac() const {
|
||||
if (law_ == NULL)
|
||||
return false;
|
||||
return (law_->isDirac());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Event::doEvent(const AltaricaModel *am, AltaricaState *s, AltaricaState *ns) {
|
||||
for (std::vector<Transition*>::iterator ti = trans_.begin();
|
||||
ti != trans_.end(); ++ti) {
|
||||
if ((*ti)->precondOK(am, s))
|
||||
(*ti)->doTransition(am, s,ns);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Event::toString() {
|
||||
std::string s;
|
||||
s+= " "+ node_->toString() + "." + ma_->toString() + " ";
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
void Event::deleteExprs() {
|
||||
if(law_ != NULL)
|
||||
law_->deleteExpr();
|
||||
}
|
||||
|
||||
Event::~Event() {
|
||||
delete ma_;
|
||||
delete law_;
|
||||
}
|
||||
}
|
||||
}
|
||||
121
src/grammars/altarica/Event.hh
Normal file
121
src/grammars/altarica/Event.hh
Normal file
@@ -0,0 +1,121 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EVENT_H_
|
||||
#define ALTA_EVENT_H_
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Node;
|
||||
class Transition;
|
||||
class Synchronisation;
|
||||
class MetaEvent;
|
||||
class AltaricaState;
|
||||
class MemberAccess;
|
||||
class EventLaw;
|
||||
class AltaricaModel;
|
||||
|
||||
//! EVENT
|
||||
/*!
|
||||
Stucture pour stocker les event et leur priorite
|
||||
*/
|
||||
class Event {
|
||||
|
||||
protected:
|
||||
|
||||
//!
|
||||
// std::string *name_;
|
||||
//! full qualified name
|
||||
MemberAccess *ma_;
|
||||
std::set<Event*> uppers_;
|
||||
std::set<Event*> lowers_;
|
||||
std::vector<std::string> attributes_;
|
||||
EventLaw * law_;
|
||||
|
||||
Node * node_;
|
||||
std::vector<Transition *> trans_;
|
||||
std::vector<Synchronisation*> syncs_;
|
||||
|
||||
public:
|
||||
|
||||
//!
|
||||
// Event(std::string *name);
|
||||
Event(MemberAccess *ma);
|
||||
|
||||
void addUppers(std::set<Event*>* b);
|
||||
void addUpper(Event *b);
|
||||
void addLowers(std::set<Event*>* b);
|
||||
void addLower(Event* b);
|
||||
void addAttribute(const std::string a);
|
||||
void addAttributes(const std::vector<std::string> *va);
|
||||
void setLaw(EventLaw* el);
|
||||
const EventLaw * getLaw() const;
|
||||
|
||||
void setNode(Node* n);
|
||||
const Node* getNode();
|
||||
|
||||
std::vector<const Node *>* getPath() const;
|
||||
std::string getFullName() const;
|
||||
|
||||
const MemberAccess* getMA() const;
|
||||
|
||||
void addTrans(Transition* t);
|
||||
const std::vector<Transition *> * getTrans() const {return &trans_;}
|
||||
void addSync(Synchronisation* s);
|
||||
|
||||
int nSynchros();
|
||||
|
||||
// void addPath(std::string* p);
|
||||
// void addPathIndexed(std::string* p, int i);
|
||||
|
||||
std::set<Event*> const * getUppers();
|
||||
Event * clone();
|
||||
|
||||
bool isMorePriorThan(Event*e);
|
||||
bool isLessPriorThan(Event*e);
|
||||
|
||||
bool isEnabled(const AltaricaModel *am, AltaricaState *s);
|
||||
bool isDirac() const;
|
||||
|
||||
void doEvent(const AltaricaModel *am, AltaricaState *s, AltaricaState *ns);
|
||||
|
||||
std::string toString();
|
||||
~Event();
|
||||
|
||||
void deleteExprs() ;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
119
src/grammars/altarica/EventLaw.cc
Normal file
119
src/grammars/altarica/EventLaw.cc
Normal file
@@ -0,0 +1,119 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "EventLaw.hh"
|
||||
#include <stdlib.h>
|
||||
#include "MemberAccess.hh"
|
||||
#include <sstream>
|
||||
#include "values/Value.hh"
|
||||
#include "values/ValueInt.hh"
|
||||
#include "values/ValueReal.hh"
|
||||
#include "expressions/Expression.hh"
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
EventLaw * EventLaw::clone() const {
|
||||
EventLaw * el;
|
||||
if (ma_ != NULL)
|
||||
el = new EventLaw(ma_->clone(), type_, param1_, param2_);
|
||||
else
|
||||
el = new EventLaw(NULL, type_, param1_, param2_);
|
||||
return el;
|
||||
}
|
||||
|
||||
EventLaw::~EventLaw() {
|
||||
delete ma_;
|
||||
// delete param_;
|
||||
}
|
||||
|
||||
void EventLaw::deleteExpr()
|
||||
{
|
||||
delete param1_;
|
||||
}
|
||||
|
||||
|
||||
bool EventLaw::isDisabled() const {
|
||||
return (type_ == ALTARICA_DISCRETE && param1_ == 0);
|
||||
}
|
||||
|
||||
bool EventLaw::isDirac() const {
|
||||
return type_ == ALTARICA_DIRAC_0;
|
||||
}
|
||||
|
||||
bool EventLaw::isDiscrete() const {
|
||||
return type_ == ALTARICA_DISCRETE;
|
||||
}
|
||||
|
||||
bool EventLaw::isCont() const {
|
||||
return type_ == ALTARICA_EXP;
|
||||
}
|
||||
|
||||
bool EventLaw::isTimed() const {
|
||||
return type_ == ALTARICA_TIMED;
|
||||
}
|
||||
|
||||
double EventLaw::evalParam(const AltaricaModel *am, AltaricaState *s) const {
|
||||
Value *v = param1_->evaluate(am, s, n_, true);
|
||||
double ret;
|
||||
if (v->isInt())
|
||||
ret = ((ValueInt*)v)->toInt();
|
||||
else
|
||||
ret = ((ValueReal*)v)->toDouble();
|
||||
Value::deleteIfPossible(v);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string EventLaw::toString() const {
|
||||
std::stringstream ss;
|
||||
switch(type_) {
|
||||
case ALTARICA_TIMED:
|
||||
ss<<"timed(" << param1_->toString() <<", " << param2_->toString() << ")";
|
||||
break;
|
||||
case ALTARICA_DISCRETE:
|
||||
ss << "discrete(" << param1_->toString() <<")";
|
||||
break;
|
||||
case ALTARICA_EXP:
|
||||
ss << "exp(" << param1_->toString() <<")";
|
||||
break;
|
||||
case ALTARICA_DIRAC_0:
|
||||
ss<<"dirac(0)";
|
||||
break;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
111
src/grammars/altarica/EventLaw.hh
Normal file
111
src/grammars/altarica/EventLaw.hh
Normal file
@@ -0,0 +1,111 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EVENTLAW_H_
|
||||
#define ALTA_EVENTLAW_H_
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class MemberAccess;
|
||||
class Expression;
|
||||
class Node;
|
||||
class AltaricaModel;
|
||||
class AltaricaState;
|
||||
|
||||
//! EVENT
|
||||
/*!
|
||||
Stucture pour stocker les event et leur priorite
|
||||
*/
|
||||
typedef enum LawType {
|
||||
ALTARICA_DISCRETE,
|
||||
ALTARICA_DIRAC_0,
|
||||
ALTARICA_EXP,
|
||||
ALTARICA_TIMED
|
||||
} LawType;
|
||||
|
||||
class EventLaw {
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//!
|
||||
// std::string *eventName_;
|
||||
//! full qualified name
|
||||
MemberAccess *ma_;
|
||||
LawType type_;
|
||||
//double param_;
|
||||
Expression * param1_;
|
||||
Expression * param2_;
|
||||
Node *n_;
|
||||
|
||||
public:
|
||||
|
||||
//!
|
||||
// EventLaw(std::string *name);
|
||||
// EventLaw(std::string *name, LawType t, double p);
|
||||
~EventLaw();
|
||||
EventLaw(MemberAccess *ma) : ma_(ma), n_(NULL), param1_(NULL), param2_(NULL) {}
|
||||
EventLaw(MemberAccess *ma, LawType t, Expression * p) : ma_(ma), type_(t), param1_(p), param2_(NULL), n_(NULL) {}
|
||||
EventLaw(MemberAccess *ma, LawType t, Expression * p, Expression * q) : ma_(ma), type_(t), param1_(p), param2_(q), n_(NULL) {}
|
||||
EventLaw(LawType t, Expression * p = NULL, Expression * q = NULL) : ma_(NULL), type_(t), param1_(p), param2_(q), n_(NULL) {}
|
||||
|
||||
// void setName(std::string *name);
|
||||
void setMA(MemberAccess *ma) {ma_ = ma;}
|
||||
void setType(LawType t) {type_=t;}
|
||||
void setParam(Expression *e) {param1_ = e;}
|
||||
Expression * getParam() const {return param1_;}
|
||||
Expression * getStartParam() const {return param1_;}
|
||||
Expression * getEndParam() const {return param2_;}
|
||||
|
||||
double evalParam(const AltaricaModel *am, AltaricaState *s) const;
|
||||
bool isDisabled() const;
|
||||
bool isDirac() const;
|
||||
bool isDiscrete() const;
|
||||
bool isCont() const;
|
||||
bool isTimed() const;
|
||||
void setNode(Node *n) {n_ = n;}
|
||||
|
||||
const MemberAccess* getMA() const {return ma_;}
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
EventLaw * clone() const;
|
||||
|
||||
void deleteExpr();
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
709
src/grammars/altarica/FiacreTranslator.cc
Normal file
709
src/grammars/altarica/FiacreTranslator.cc
Normal file
@@ -0,0 +1,709 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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 the IRT AESE (IRT Saint Exupéry).
|
||||
* 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:
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* FiacreTranslator.cc
|
||||
*
|
||||
* Created on: 27 oct. 2016
|
||||
* Author: alexandre.albore
|
||||
* This file is part of the IRT MOISE project
|
||||
*/
|
||||
#include <algorithm>
|
||||
#include "FiacreTranslator.hh"
|
||||
#include "Variable.hh"
|
||||
#include "Constant.hh"
|
||||
#include "expressions/Expressions.hh"
|
||||
#include "Assignment.hh"
|
||||
#include "AltaricaGenerator.hh"
|
||||
#include "Event.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "Synchronisation.hh"
|
||||
#include "Transition.hh"
|
||||
#include "Node.hh"
|
||||
#include "Assertion.hh"
|
||||
#include "EventLaw.hh"
|
||||
|
||||
//#define USEUNDEF true // Used to extend the types with an undef value
|
||||
// 2016031810012552 to fr
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
const std::string xx = std::string("x");
|
||||
const std::string yy = std::string("y");
|
||||
const std::pair<std::string,std::string> prefixes(xx,yy);
|
||||
|
||||
FiacreTranslator::FiacreTranslator(const AltaricaModel *amodel): amodel_(amodel) {
|
||||
|
||||
}
|
||||
|
||||
FiacreTranslator::~FiacreTranslator() {
|
||||
os_.clear();
|
||||
}
|
||||
|
||||
|
||||
std::string FiacreTranslator::getType(Value* dom) {
|
||||
if (dom->isBool())
|
||||
return std::string("bool");
|
||||
else if (dom->isInt())
|
||||
return std::string("int");
|
||||
else if (dom->isSymbol())
|
||||
return std::string("union");
|
||||
}
|
||||
|
||||
/* @return a string with the union
|
||||
* Could return a list for ex.
|
||||
*/
|
||||
std::string FiacreTranslator::makesUnion(const std::vector<std::string>* sym) {
|
||||
std::string currentType;
|
||||
|
||||
for (std::vector<std::string>::const_iterator i = sym->begin(); i!= sym->end(); ++i) {
|
||||
if (i+1 == sym->end())
|
||||
currentType += *i ;
|
||||
else
|
||||
currentType += *i + "|";
|
||||
}
|
||||
return currentType;
|
||||
}
|
||||
|
||||
std::string FiacreTranslator::removeAmp(std::string &r) {
|
||||
size_t index = 0;
|
||||
while (true) {
|
||||
index = r.find("&", index);
|
||||
if (index == std::string::npos) break;
|
||||
r.replace(index, 1, ".");
|
||||
index += 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/// Does the product of MetaEvents
|
||||
/// NB: A·B= AB (but not A, B)
|
||||
std::string FiacreTranslator::print_MandatoryEvents_sync (const std::vector<epoch::altarica::Event*> *ev, int n,
|
||||
std::ostringstream * spre, std::ostringstream * spost) {
|
||||
|
||||
std::ostringstream sret;
|
||||
std::string s ;
|
||||
|
||||
// if ( spre->rdbuf()->in_avail() == 0 )
|
||||
// *spre << "on (";
|
||||
// else *spre << "\t[] on (";
|
||||
|
||||
|
||||
if (n < 0) {
|
||||
sret << spre->str() + ");\n" + spost->str() + "\t\tx := assertions(y";
|
||||
|
||||
// listing the state vars
|
||||
/* for(auto &s : model().getStateVars()) {
|
||||
sret << s->toFiacre();
|
||||
if (&s != &model().getStateVars().back())
|
||||
sret << ", " ;
|
||||
} */
|
||||
sret << ");" << std::endl << "\t\tto s0"<< std::endl;
|
||||
return sret.str();
|
||||
}
|
||||
|
||||
// unsigned j = 0;
|
||||
if (ev->at(n)->getTrans()->size() != 0)
|
||||
for (auto &ti : *(ev->at(n)->getTrans()) ) {
|
||||
std::ostringstream s1, s2;
|
||||
std::string ti_str = ti->getPrecond()->toString( ti->getNode(), &prefixes, model());
|
||||
s1 << spre->str() << removeAmp(ti_str);
|
||||
if ( n != 0 )
|
||||
s1 << " and ";
|
||||
//s1 << sout->str() << "\tE" << n << "T" << j++;
|
||||
|
||||
const std::vector<epoch::altarica::Assignment*>* effects = ti->getAssigns();
|
||||
if(effects->size() > 0) {
|
||||
s2 << spost->str();
|
||||
|
||||
for(auto &a : *effects) {
|
||||
std::string eff_str = "\t\t"
|
||||
+ a->getVar()->toFiacre()
|
||||
+ " := "
|
||||
+ a->getExpr()->toString( a->getNode(), &prefixes, model() )
|
||||
+ ";\n";
|
||||
s2 << removeAmp(eff_str);
|
||||
}
|
||||
}
|
||||
sret << print_MandatoryEvents_sync( ev, n-1, &s1, &s2);
|
||||
}
|
||||
else { // null transition
|
||||
std::ostringstream s1, s2;
|
||||
s1 << spre->str();
|
||||
s2 << spost->str();
|
||||
sret << print_MandatoryEvents_sync( ev, n-1, &s1, &s2);
|
||||
}
|
||||
|
||||
return sret.str();
|
||||
}
|
||||
|
||||
|
||||
/// Does the optional syncs
|
||||
/// NB: A: a -> a' ; B: b -> b'
|
||||
/// A·B: a|b -> (if a then a') & (if b then b')
|
||||
std::string FiacreTranslator::print_OptionalEvents_sync (const std::vector<epoch::altarica::Event*> *ev, int n,
|
||||
std::ostringstream * spre, std::ostringstream * spost) {
|
||||
|
||||
std::ostringstream sret;
|
||||
std::string s ;
|
||||
|
||||
if (n < 0) {
|
||||
sret << spre->str() + ");\n" + spost->str() + "\t\tx := assertions(y";
|
||||
// for(auto &s : model().getStateVars()) {
|
||||
// sret << s->toFiacre();
|
||||
// if (&s != &model().getStateVars().back())
|
||||
// sret << ", " ;
|
||||
// }
|
||||
sret << ");" << std::endl << "\t\tto s0"<< std::endl;
|
||||
return sret.str();
|
||||
}
|
||||
///
|
||||
// const std::string ff = std::string("f");
|
||||
// const std::string gg = std::string("g");
|
||||
// const std::pair<std::string,std::string> prefixes(ff,gg);
|
||||
// std::string assertion = " " + ai->getExpr()->toString((ai->getNode()), &prefixes, model()) + ";\n";//
|
||||
// size_t index = 0;
|
||||
// while (true) {
|
||||
// index = assertion.find(".", index);
|
||||
// if (index == std::string::npos) break;
|
||||
// assertion.replace(index, 1, "_");
|
||||
// index += 1;
|
||||
// }
|
||||
// index = 0;
|
||||
// while (true) { // NB: Transitions already use ':='
|
||||
// index = assertion.find("=", index);
|
||||
// size_t indexif = assertion.find("if", 0);
|
||||
// if (index == std::string::npos) break;
|
||||
// if (indexif == std::string::npos) // does not replace for if conditions (the rest of expr is taken care by the Expressions)
|
||||
// assertion.replace(index, 1, ":=");
|
||||
// break;
|
||||
// }
|
||||
///
|
||||
|
||||
if (ev->at(n)->getTrans()->size() != 0)
|
||||
for (auto &ti : *(ev->at(n)->getTrans()) ) { // HERE: do it in reverse order (?)
|
||||
std::ostringstream s1, s2;
|
||||
std::string ti_str = ti->getPrecond()->toString( ti->getNode(), &prefixes, model());
|
||||
s1 << spre->str() << removeAmp(ti_str);
|
||||
if ( n != 0 )
|
||||
s1 << " or ";
|
||||
|
||||
const std::vector<epoch::altarica::Assignment*>* effects = ti->getAssigns();
|
||||
if(effects->size() > 0) {
|
||||
s2 << spost->str();
|
||||
for(auto &a : *effects) {
|
||||
std::string eff_str = "\t\tif ("
|
||||
+ ti->getPrecond()->toString( ti->getNode(), &prefixes, model() )
|
||||
+ ") then "
|
||||
+ a->getVar()->toFiacre()
|
||||
+ " := "
|
||||
+ a->getExpr()->toString( a->getNode(), &prefixes, model() )
|
||||
+ "\n\t\tend;\n";
|
||||
s2 << removeAmp(eff_str);
|
||||
}
|
||||
}
|
||||
sret << print_OptionalEvents_sync( ev, n-1, &s1, &s2);
|
||||
}
|
||||
else { // null transition
|
||||
std::ostringstream s1, s2;
|
||||
s1 << spre->str();
|
||||
s2 << spost->str();
|
||||
sret << print_OptionalEvents_sync( ev, n-1, &s1, &s2);
|
||||
}
|
||||
|
||||
return sret.str();
|
||||
}
|
||||
|
||||
|
||||
std::string FiacreTranslator::print_assertions_function (std::vector<std::string> &vecStateVars, std::vector<std::string> &vecFlowVars) {
|
||||
|
||||
std::ostringstream ss;
|
||||
|
||||
const std::string ff = std::string("f");
|
||||
const std::string gg = std::string("g");
|
||||
const std::pair<std::string,std::string> prefixes(ff,gg);
|
||||
|
||||
// Updates the assertions
|
||||
ss << std::endl << "function assertions (";
|
||||
ss << "g : StateVars) : FlowVars is" << std::endl << " var f : FlowVars";
|
||||
|
||||
//Produces the list of state variables
|
||||
// for (int t=0;t<vecStateVars.size();++t) {
|
||||
// ss << vecStateVars.at(t);
|
||||
//
|
||||
// if (t+1 == vecStateVars.size()) {
|
||||
// ss << ") : FlowVars is" << std::endl << " var f : FlowVars";
|
||||
|
||||
//
|
||||
//
|
||||
// #ifdef USEUNDEF
|
||||
// ss << ":= {" << std::endl;
|
||||
//
|
||||
// for(auto &v : model().getFlowVars()) {
|
||||
// os_<< "\t" << v->toFiacre();
|
||||
//
|
||||
// ss << "=" << UNDEF;
|
||||
//
|
||||
// if (&v != &model().getFlowVars().back())
|
||||
// ss<< "," << std::endl;
|
||||
// else
|
||||
// os_ << "\n }";
|
||||
// }
|
||||
// #endif
|
||||
//
|
||||
ss << std::endl << " begin"<< std::endl;
|
||||
// } else
|
||||
// ss << ", ";
|
||||
// }
|
||||
|
||||
for(auto &ai : model().getAsserts()) {
|
||||
std::string assertion = " " + ai->getExpr()->toString((ai->getNode()), &prefixes, model()) + ";\n";//
|
||||
size_t index = 0;
|
||||
while (true) {
|
||||
index = assertion.find(".", index);
|
||||
if (index == std::string::npos) break;
|
||||
assertion.replace(index, 1, "_");
|
||||
index += 1;
|
||||
}
|
||||
index = 0;
|
||||
while (true) { // NB: Transitions already use ':='
|
||||
index = assertion.find("=", index);
|
||||
size_t indexif = assertion.find("if", 0);
|
||||
if (index == std::string::npos) break;
|
||||
if (indexif == std::string::npos) // does not replace for if conditions (the rest of expr is taken care by the Expressions)
|
||||
assertion.replace(index, 1, ":=");
|
||||
break;
|
||||
}
|
||||
index = 0;
|
||||
ss << removeAmp(assertion);
|
||||
}
|
||||
// }
|
||||
// }
|
||||
|
||||
ss << " return f"<< std::endl<< std::endl;
|
||||
ss << " end"<< std::endl;
|
||||
|
||||
return ss.str();
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::string FiacreTranslator::print_metaEvents(const epoch::altarica::MetaEvent& e) {
|
||||
std::ostringstream sret;
|
||||
size_t index = 0;
|
||||
|
||||
if (e.getEvents()->size() != 0) {
|
||||
std::ostringstream s1;
|
||||
std::ostringstream s2;
|
||||
std::string label;
|
||||
|
||||
label = ((e.getEvents()->size() == 1)? "" : "meta_event_");
|
||||
|
||||
double minTime, maxTime = -100000.0;
|
||||
bool has_Tlaw = false;
|
||||
|
||||
s1 << "on (";
|
||||
for (std::vector<epoch::altarica::Event*>::iterator i = e.getEvents()->begin();
|
||||
i!=e.getEvents()->end(); ++i) {
|
||||
for (auto &t : *(*i)->getTrans()) {
|
||||
|
||||
/* Prints preconditions = guards */
|
||||
std::string r(t->getPrecond()->toString( t->getNode(), &prefixes, model() ));
|
||||
s1 << removeAmp(r);
|
||||
if ((i+1) != e.getEvents()->end()) s1 << " and ";
|
||||
else if (*(&t+1) != *(*i)->getTrans()->end()) s1 << " and ";
|
||||
|
||||
/* Gets the transition law */
|
||||
const EventLaw *law = (*i)->getLaw();
|
||||
const Node * ne = (*i)->getNode();
|
||||
if ( law && law->isTimed()) {
|
||||
has_Tlaw = true;
|
||||
double minT = std::atof(law->getStartParam()->toString( ne , model() ).c_str()) ;
|
||||
double maxT = std::atof(law->getEndParam()->toString(ne, model() ).c_str());
|
||||
|
||||
// Note to self: faire une metaEvent law.
|
||||
minTime = std::min( minTime, minT );
|
||||
maxTime = maxT < 0 ? maxTime : std::max(maxT, maxTime);
|
||||
}
|
||||
|
||||
/* Prints effects */
|
||||
if(t->getAssigns()->size() > 0) {
|
||||
for(auto &a : *(t->getAssigns())) {
|
||||
std::string rr = "\t\t" + a->getVar()->toFiacre()
|
||||
+ " := "
|
||||
+ a->getExpr()->toString( a->getNode(), &prefixes, model())
|
||||
+ ";\n";
|
||||
s2 << removeAmp(rr);
|
||||
}
|
||||
}
|
||||
}
|
||||
label += (*i)->getFullName() ;
|
||||
}
|
||||
|
||||
sret << s1.str() << ");" << std::endl;
|
||||
|
||||
if (has_Tlaw) {
|
||||
sret << "\t\twait";
|
||||
if (minTime < 0)
|
||||
sret << "]w,";
|
||||
else sret << "[" << minTime << ",";
|
||||
if (maxTime < 0)
|
||||
sret << "w[;";
|
||||
else sret << maxTime << "];" ;
|
||||
sret << std::endl;
|
||||
}
|
||||
|
||||
sret << s2.str();
|
||||
|
||||
sret << "\t\t/* flow resolution */"<< std::endl;
|
||||
sret << "\t\tx := assertions(y);" << std::endl;
|
||||
/* Prints transition label */
|
||||
{
|
||||
size_t index = 0;
|
||||
|
||||
while (true) {
|
||||
index = label.find(".", index);
|
||||
if (index == std::string::npos) break;
|
||||
label.replace(index, 1, "_");
|
||||
index += 1;
|
||||
}
|
||||
sret << "\t\t#" << label << ";" << std::endl;
|
||||
}
|
||||
|
||||
sret << "\t\tto s0"<< std::endl;
|
||||
}
|
||||
else
|
||||
std::cerr << " NO EVENT";
|
||||
|
||||
return sret.str();
|
||||
}
|
||||
|
||||
std::string FiacreTranslator::print_transitions (Event &e,std::string &sconnect) {
|
||||
std::ostringstream sret;
|
||||
size_t index = 0;
|
||||
|
||||
if(e.getTrans()->size() > 0) {
|
||||
|
||||
if (sconnect.empty())
|
||||
sret <<"\t select"<< std::endl << "\t\t";
|
||||
|
||||
for(auto &t : *e.getTrans()) {
|
||||
std::string r = "on (" + t->getPrecond()->toString( t->getNode(), &prefixes, model() ) + ");\n";
|
||||
|
||||
sret << sconnect << removeAmp(r);
|
||||
|
||||
const EventLaw * law = e.getLaw();
|
||||
const Node * ne = e.getNode();
|
||||
if ( law && law->isTimed())
|
||||
sret << "\t\twait" << (std::atof(law->getStartParam()->toString( ne , model() ).c_str()) < 0 ? "]w"
|
||||
: "[" + law->getStartParam()->toString( ne, model() )) << ","
|
||||
<< (std::atof(law->getEndParam()->toString(ne, model() ).c_str()) < 0 ? "w[;"
|
||||
: law->getEndParam()->toString(ne, model() ) + "];") << std::endl;
|
||||
|
||||
if(t->getAssigns()->size() > 0) {
|
||||
for(auto &a : *t->getAssigns()) {
|
||||
std::string rr = "\t\t" // NB: tail is always a state variable
|
||||
+ a->getVar()->toFiacre()
|
||||
+ " := "
|
||||
+ a->getExpr()->toString( a->getNode(), &prefixes, model() )
|
||||
+ ";\n";
|
||||
sret << removeAmp(rr);
|
||||
}
|
||||
}
|
||||
sret << "\t\t/* flow resolution */"<< std::endl;
|
||||
sret << "\t\tx := assertions(y);" << std::endl;
|
||||
|
||||
/* Prints transition label */
|
||||
{
|
||||
std::string s = e.getFullName();
|
||||
size_t index = 0;
|
||||
|
||||
while (true) {
|
||||
index = s.find(".", index);
|
||||
if (index == std::string::npos) break;
|
||||
s.replace(index, 1, "_");
|
||||
index += 1;
|
||||
}
|
||||
sret << "\t\t#" << s << ";" << std::endl;
|
||||
}
|
||||
|
||||
sret << "\t\tto s0"<< std::endl;
|
||||
if (sconnect.empty())
|
||||
sconnect += "\t\t[] ";
|
||||
}
|
||||
}
|
||||
return sret.str();
|
||||
}
|
||||
|
||||
void FiacreTranslator::printFiacre() {
|
||||
|
||||
// Gets types and state variables
|
||||
std::ostringstream osStateVars, osStateVars2, osTransitions, liftedTypes;
|
||||
std::vector<std::string> vecFlowVars, vecStateVars;
|
||||
|
||||
os_ << "/* Types */"<<std::endl<<std::endl;
|
||||
liftedTypes << "type flowtype is union" << std::endl << "\t";
|
||||
|
||||
|
||||
if (model().getNStateVars()) osStateVars <<"\tvar ";
|
||||
for (unsigned int j = 0; j != model().getNStateVars(); ) {
|
||||
|
||||
// State Vars
|
||||
|
||||
Variable * v = model().getStateVar(j++);
|
||||
Value* dom = v->getDomain()->toValue();
|
||||
|
||||
// gets the type
|
||||
// NB: works only if they are always present in the same order in the Altarica file, otherwise use a list (more costly)
|
||||
|
||||
if (dom->isSymbol()) {
|
||||
const std::vector<std::string>* sym = ((ValueSymbol*)dom)->toSymbols();
|
||||
std::string currentType = makesUnion(sym);
|
||||
std::string typeName = ( v->getDomain()->get_name() == "" ?
|
||||
std::string("type").append( std::to_string(types_.size())) :
|
||||
v->getDomain()->get_name() );
|
||||
// Hashes the type
|
||||
if (types_.emplace(currentType, typeName).second ) {
|
||||
// prints the type
|
||||
os_ << "type " << types_[currentType];// state var v->toFiacre();
|
||||
os_ << " is union " << currentType << " end" << std::endl;// getType(dom);
|
||||
}
|
||||
|
||||
vecStateVars.push_back( v->toFiacre(false) + " : " + types_[currentType] );
|
||||
osStateVars <<"\t" << v->toFiacre(false) << " : " << types_[currentType];
|
||||
|
||||
} // is symbol
|
||||
else { // is basic type
|
||||
vecStateVars.push_back( v->toFiacre(false) + " : " + getType(dom) );
|
||||
osStateVars <<"\t" << v->toFiacre(false) << " : " << getType(dom);
|
||||
}
|
||||
osStateVars << " := " << v->getInit()->getExpr()->toString() << "," << std::endl;
|
||||
if (j == 1)
|
||||
osStateVars2 << "\t" << v->toFiacre(false) << " = " << v->getInit()->getExpr()->toString() ;
|
||||
else
|
||||
osStateVars2 << "," << std::endl <<"\t" << v->toFiacre(false) << " = " << v->getInit()->getExpr()->toString() ;
|
||||
}
|
||||
os_ << std::endl;
|
||||
|
||||
// Flow Vars
|
||||
for(auto &v : model().getFlowVars()) {
|
||||
|
||||
std::string theType;
|
||||
Value* dom = v->getDomain()->toValue();
|
||||
|
||||
// gets the type
|
||||
|
||||
if (dom->isSymbol()) { // is symbol
|
||||
const std::vector<std::string>* sym = ((ValueSymbol*)dom)->toSymbols();
|
||||
std::string currentType = makesUnion(sym);
|
||||
std::string typeName = ( v->getDomain()->get_name() == "" ?
|
||||
std::string("type").append( std::to_string(types_.size())) :
|
||||
v->getDomain()->get_name() );
|
||||
|
||||
// Hashes the type
|
||||
#ifdef USEUNDEF
|
||||
if (std::find(flowtypes_.begin(), flowtypes_.end(), typeName) == flowtypes_.end())
|
||||
{
|
||||
std::string tn= typeName;
|
||||
flowtypes_.push_back(tn);
|
||||
transform(tn.begin(), tn.end(), tn.begin(), toupper);
|
||||
liftedTypes << tn << " of " << typeName << "|\n\t";
|
||||
}
|
||||
#endif
|
||||
|
||||
if (types_.emplace(currentType, typeName).second ) {
|
||||
// prints the type
|
||||
os_ << "type " << types_[currentType];// state var v->toFiacre();
|
||||
os_ << " is union " << currentType << " end" << std::endl;// getType(dom);
|
||||
}
|
||||
|
||||
theType = types_[currentType];
|
||||
} // end is symbol
|
||||
else {
|
||||
#ifdef USEUNDEF
|
||||
if (std::find(flowtypes_.begin(), flowtypes_.end(), getType(dom)) == flowtypes_.end()) { // is basic type
|
||||
|
||||
std::string tn = getType(dom);
|
||||
|
||||
flowtypes_.push_back(tn);
|
||||
transform(tn.begin(), tn.end(), tn.begin(), toupper);
|
||||
liftedTypes << tn << " of " << getType(dom) << "|\n\t";
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
theType = getType(dom);
|
||||
}// end is basic type
|
||||
|
||||
|
||||
#ifdef USEUNDEF
|
||||
vecFlowVars.push_back(v->toFiacre(false) + " : flowtype"); // + types_[currentType]);
|
||||
|
||||
} // end for
|
||||
|
||||
liftedTypes << UNDEF << " end" << std::endl;
|
||||
os_ << liftedTypes.str();
|
||||
#else
|
||||
|
||||
vecFlowVars.push_back(v->toFiacre(false) + " : " + theType);
|
||||
// Gets the aliases
|
||||
// for (std::vector<std::pair<const Node*, const MemberAccess*>*>::const_iterator i = (v->getAliases())->begin(); i!= v->getAliases()->end(); ++i) {
|
||||
//
|
||||
//
|
||||
// {
|
||||
// // Get the variable
|
||||
// std::ostringstream oss;
|
||||
//
|
||||
// oss.str("");
|
||||
// std::string nodename = (*i)->first->getFullName();
|
||||
// if (nodename != "main")
|
||||
// oss << nodename.substr(5, std::string::npos) << ".";
|
||||
// oss << (*i)->second->toString();
|
||||
// std::string aliasname = oss.str();
|
||||
// std::cout << "looking for " << v->getFullName() << std::endl;
|
||||
// //epoch::altarica::Variable* av = v->getNode()->findVariableByName(aliasname);
|
||||
// //if (av == NULL)
|
||||
// // throw new std::out_of_range("Cannot find Variable: " + nodename +
|
||||
// // " in node " + nodename + "\n");
|
||||
// //vecFlowVars.push_back( av->toFiacre() + " : " + theType );
|
||||
//
|
||||
//
|
||||
// MemberAccess *ma = new MemberAccess(aliasname);
|
||||
// // ma->setGlobal(true);
|
||||
// Variable * av = model().getMainNode()->findVariableByName(ma);
|
||||
// std::cout << " - " << av->getFullName() << std::endl;
|
||||
// // model().existsVar();
|
||||
//
|
||||
// }
|
||||
|
||||
// vecFlowVars.push_back( (*i)->first->toFiacre() + "_" + (*i)->second->toString() + " : " + theType );
|
||||
// }
|
||||
} // end for
|
||||
#endif
|
||||
|
||||
os_ << "type FlowVars is record\n";
|
||||
for (int t=0;t<vecFlowVars.size();++t) {
|
||||
os_ << "\t" << vecFlowVars.at(t);
|
||||
if (t+1 < vecFlowVars.size())
|
||||
os_<< ",\n";
|
||||
else
|
||||
os_ << " end" << std::endl;
|
||||
}
|
||||
|
||||
os_ << "type StateVars is record\n";
|
||||
for (int t=0;t<vecStateVars.size();++t) {
|
||||
os_ << "\t" << vecStateVars.at(t);
|
||||
if (t+1 < vecStateVars.size())
|
||||
os_<< ",\n";
|
||||
else
|
||||
os_ << " end" << std::endl;
|
||||
}
|
||||
|
||||
os_ <<std::endl<< "/* Constants */"<<std::endl;
|
||||
|
||||
std::vector<epoch::altarica::Constant*> constants = model().getConstants();
|
||||
for (std::vector<epoch::altarica::Constant*>::const_iterator c = constants.begin(); c!= constants.end(); ++c) {
|
||||
std::string t = std::string("type");
|
||||
const Expression* expr = (*c)->getExpression();
|
||||
|
||||
if (const ExpressionUNSIGNEDINT* vu = dynamic_cast<const ExpressionUNSIGNEDINT*>(expr))
|
||||
t = std::string("nat");
|
||||
else if (const ExpressionBOOLCONSTANT* vu = dynamic_cast<const ExpressionBOOLCONSTANT*>(expr))
|
||||
t = std::string("bool");
|
||||
// for (auto &n : model().getNodes())
|
||||
// if (n->getMA()->isGlobal() || n->getParent() != NULL) // << n->getMA()->toString() << "_"
|
||||
os_ << "const " << (*c)->getName() << " : "
|
||||
<< t << " is " << (*c)->getExpression()->toString()<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
os_ << print_assertions_function(vecStateVars, vecFlowVars);
|
||||
|
||||
|
||||
os_<<std::endl << "process mainprocess (&x : FlowVars, &y: StateVars) is\n\tstates s0"<<std::endl;
|
||||
|
||||
|
||||
// for (int t=0;t<vecFlowVars.size();++t)
|
||||
// os_ << "," << std::endl <<"\t" << vecFlowVars.at(t); /* NB: FLOW VARS have no Init value << " := " << v->getInit()->getExpr()->toString() */
|
||||
// os_ << std::endl;
|
||||
|
||||
/*********** Transitions ********/
|
||||
|
||||
osTransitions << std::endl <<"\tfrom s0"<<std::endl;
|
||||
|
||||
std::string sconnect("");
|
||||
for(auto &e : model().getAtomicEvents()) {
|
||||
// osTransitions << print_transitions(*e, sconnect);
|
||||
}
|
||||
|
||||
// osTransitions << "\t\t/* Syncs */"<<std::endl;
|
||||
// for(auto &sy : model().getSyncs()) {
|
||||
// if (sy->getMandatoryEvents()->size() || sy->getOptionalEvents()->size()) {
|
||||
// std::ostringstream s1("\t\t[] on (");
|
||||
// std::ostringstream s2;
|
||||
// int num = sy->getMandatoryEvents()->size()-1;
|
||||
//
|
||||
// if (sy->getMandatoryEvents()->size() > 1)
|
||||
// osTransitions << print_MandatoryEvents_sync(sy->getMandatoryEvents(), num, &s1, &s2);
|
||||
//
|
||||
// num = sy->getOptionalEvents()->size()-1;
|
||||
// if (sy->getOptionalEvents()->size() > 1)
|
||||
// osTransitions << print_OptionalEvents_sync(sy->getOptionalEvents(), num, &s1, &s2);
|
||||
// }
|
||||
// }
|
||||
|
||||
osTransitions << "/* Syncs */" << std::endl;
|
||||
osTransitions <<"\t select"<< std::endl << "\t\t";
|
||||
bool firstME = true;
|
||||
|
||||
for(auto &sy :model().getMetaEvents()) {
|
||||
if (firstME)
|
||||
firstME=false;
|
||||
else osTransitions << "\t\t[]";
|
||||
|
||||
osTransitions << print_metaEvents(*sy);
|
||||
}
|
||||
|
||||
os_ << osTransitions.str();
|
||||
os_ << "\t end" << std::endl;
|
||||
|
||||
std::cout << os_.str();
|
||||
|
||||
|
||||
std::cout << "component Main is" << std::endl;
|
||||
|
||||
// Removing the last comma
|
||||
osStateVars.seekp(osStateVars.str().length()-1);
|
||||
std::cout << "\t/* State Variables */\n\tvar y : StateVars := {"<< std::endl;
|
||||
std::cout << osStateVars2.str() << " }," << std::endl;
|
||||
std::cout << "\tx : FlowVars"<< std::endl << std::endl;
|
||||
|
||||
std::cout << "\tpar * in\n\t\tmainprocess (&x, &y)\n\tend" << std::endl << std::endl << "Main"<< std::endl;
|
||||
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
}
|
||||
110
src/grammars/altarica/FiacreTranslator.hh
Normal file
110
src/grammars/altarica/FiacreTranslator.hh
Normal file
@@ -0,0 +1,110 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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 the IRT AESE (IRT Saint Exupéry).
|
||||
* 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:
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* \class FiacreTranslator
|
||||
*
|
||||
* \ingroup PackageName
|
||||
* (Note, this needs exactly one \defgroup somewhere)
|
||||
*
|
||||
* \brief Provide an example
|
||||
*
|
||||
* This class contains all the printouts of the Altarica data structure
|
||||
* to a fiacre file.
|
||||
* Called in the main console.
|
||||
*
|
||||
* \note This file is part of the IRT MOISE project
|
||||
*
|
||||
* \author alexandre.albore $Author: bv $
|
||||
*
|
||||
* \version $Revision: 1.0 $
|
||||
*
|
||||
* \date $Date: 2016/10/27 09:16:20 $
|
||||
*
|
||||
* Contact: alexandre.albore@irt-saintexupery.com
|
||||
*
|
||||
* Created on: Wed Oct 27 09:16:20 2016
|
||||
*
|
||||
* $Id: doxygen-howto.html,v 1.0 2016/10/27 14:16:20 bv Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FIACRETRANSLATOR_HH_
|
||||
#define FIACRETRANSLATOR_HH_
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <unordered_map>
|
||||
#include <algorithm>
|
||||
#include "Values.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Value;
|
||||
|
||||
class FiacreTranslator {
|
||||
|
||||
private:
|
||||
std::vector<Value*> stateVars_;
|
||||
mutable std::vector<Value*> flowVars_;
|
||||
const AltaricaModel * amodel_;
|
||||
// std::vector<Assertion*> * asserts_;
|
||||
|
||||
protected:
|
||||
std::ostringstream os_;
|
||||
std::unordered_map<std::string,std::string> types_;
|
||||
std::vector<std::string> flowtypes_;
|
||||
const std::string UNDEF = std::string("UNDEF");
|
||||
std::string print_MandatoryEvents_sync (const std::vector<epoch::altarica::Event*> *ev, int n, std::ostringstream * s1, std::ostringstream * s2);
|
||||
std::string print_OptionalEvents_sync (const std::vector<epoch::altarica::Event*> *ev, int n, std::ostringstream * s1, std::ostringstream * s2);
|
||||
std::string print_assertions_function (std::vector<std::string> &vs, std::vector<std::string> &vf);
|
||||
std::string print_transitions (epoch::altarica::Event &e, std::string &sconnect);
|
||||
std::string print_metaEvents(const epoch::altarica::MetaEvent& e) ; //,std::string &sconnect
|
||||
|
||||
public:
|
||||
//!
|
||||
FiacreTranslator(const AltaricaModel* amodel);
|
||||
|
||||
~FiacreTranslator();
|
||||
|
||||
std::string getType(Value* dom);
|
||||
|
||||
std::ostringstream *fiacre() {return &os_;}
|
||||
void printFiacre();
|
||||
const AltaricaModel &model() {return *amodel_;}
|
||||
std::string makesUnion(const std::vector<std::string>* sym);
|
||||
std::string removeAmp(std::string &r);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* FIACRETRANSLATOR_HH_ */
|
||||
110
src/grammars/altarica/LandmarkDriver.cc
Normal file
110
src/grammars/altarica/LandmarkDriver.cc
Normal file
@@ -0,0 +1,110 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "LandmarkDriver.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "AltaricaState.hh"
|
||||
#include "LandmarkState.hh"
|
||||
#include "LandmarkMetaEvent.hh"
|
||||
#include "Values.hh"
|
||||
#include "iostream"
|
||||
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
LandmarkDriver::LandmarkDriver(AltaricaModel * amodel) {
|
||||
amodel_ = amodel;
|
||||
finalState_ = NULL;
|
||||
}
|
||||
|
||||
|
||||
void LandmarkDriver::computeLandmarks() {
|
||||
AltaricaState *init = amodel_->initialState();
|
||||
// AltaricaState *initialMacroState = init->getMacroState();
|
||||
std::cerr << "INIT STATE:" << init->toString(true,true,false,false);
|
||||
|
||||
LandmarkState * is = new LandmarkState(init);
|
||||
is->addSelfAsLabel();
|
||||
// std::cerr<<is->toString();
|
||||
|
||||
LandmarkState * currentState = is;
|
||||
LandmarkState * previousState = NULL;
|
||||
|
||||
int i = 0;
|
||||
while (!stablePlanningGraph(previousState,currentState)) {
|
||||
std::cout << "LEVEL IN PLANNINGGRAPH: " << i++ << "\n";
|
||||
previousState = currentState;
|
||||
currentState = new LandmarkState(previousState->getState()->clone());
|
||||
std::cout << "CURRENT STATE: " << currentState->getState()->toString(true,true,false,false) << "\n";
|
||||
|
||||
std::vector<MetaEvent*> * mevs = amodel_->getEnabledMetaEventsAll(previousState->getState());
|
||||
int j=0;
|
||||
for (std::vector<MetaEvent*>::iterator mevi = mevs->begin(); mevi!= mevs->end(); ++mevi) {
|
||||
std::cout << "EVALUATING MEV: " << j++ << "\n";
|
||||
LandmarkMetaEvent * lmev = new LandmarkMetaEvent(*mevi, amodel_);
|
||||
lmev->computeLabels((const AltaricaModel*)amodel_, previousState);
|
||||
std::cout << "LANDMARK MEV\n" << lmev->toString();
|
||||
AltaricaState * cs = amodel_->getNextState(previousState->getState(), *mevi);
|
||||
//amodel_->evaluateFlowVars(cs);
|
||||
LandmarkState * tempState = new LandmarkState(cs);
|
||||
tempState->computeLabels((const AltaricaModel*) amodel_, previousState->getState(), lmev);
|
||||
//tempState->computeFlowLabels(amodel_);
|
||||
// std::cout << "TEMPSTATE\n" << tempState->toString();
|
||||
currentState->mergeIntersectLabels(tempState);
|
||||
cs->mergeToState(currentState->getState());
|
||||
// std::cout << "CURRENTSTATE INC\n" << currentState->toString();
|
||||
}
|
||||
if (currentState == NULL)
|
||||
currentState = previousState;
|
||||
else {
|
||||
currentState->addNoopLabels(previousState);
|
||||
// std::cout << "CURRENTSTATE AFTER NOOP\n" << currentState->toString();
|
||||
currentState->addSelfAsLabel();
|
||||
// std::cout << "CURRENTSTATE AFTER SELF\n" << currentState->toString();
|
||||
}
|
||||
std::cout << "CURRENTSTATE AT END\n" << currentState->toString();
|
||||
|
||||
|
||||
}
|
||||
finalState_ = currentState;
|
||||
// std::cout << "CURRENTSTATE AT END BEFORE REMOVESELF\n" << currentState->toString();
|
||||
// finalState_->removeSelfAsLabel();
|
||||
// std::cout << "CURRENTSTATE AT END AFTER REMOVESELF\n" << currentState->toString();
|
||||
finalState_->computeFlowLabels(amodel_);
|
||||
}
|
||||
|
||||
bool LandmarkDriver::stablePlanningGraph(LandmarkState *ps, LandmarkState*cs) {
|
||||
if (ps == NULL)
|
||||
return false;
|
||||
for (unsigned int i = 0; i<amodel_->getNStateVars(); ++i)
|
||||
if (!ps->getState()->getStateValue(i)->equals(cs->getState()->getStateValue(i)))
|
||||
return false;
|
||||
for (unsigned int i = 0; i<amodel_->getNFlowVars(); ++i)
|
||||
if (ps->getState()->getFlowValue(i) != NULL && cs->getState()->getFlowValue(i) != NULL)
|
||||
if (!ps->getState()->getFlowValue(i)->equals(cs->getState()->getFlowValue(i)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
54
src/grammars/altarica/LandmarkDriver.hh
Normal file
54
src/grammars/altarica/LandmarkDriver.hh
Normal file
@@ -0,0 +1,54 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef LANDMARK_DRIVER_HH
|
||||
#define LANDMARK_DRIVER_HH
|
||||
|
||||
#include "LandmarkState.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Variable;
|
||||
class FixedValue;
|
||||
class LandmarkState;
|
||||
class AltaricaModel;
|
||||
class AltaricaState;
|
||||
|
||||
class LandmarkDriver {
|
||||
private:
|
||||
AltaricaModel* amodel_;
|
||||
bool stablePlanningGraph(LandmarkState *ps, LandmarkState*cs);
|
||||
LandmarkState * finalState_;
|
||||
|
||||
public:
|
||||
LandmarkDriver(AltaricaModel *amodel);
|
||||
void computeLandmarks();
|
||||
const LandmarkState* getAllLM() {return finalState_;}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
104
src/grammars/altarica/LandmarkMetaEvent.cc
Normal file
104
src/grammars/altarica/LandmarkMetaEvent.cc
Normal file
@@ -0,0 +1,104 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "LandmarkMetaEvent.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "AltaricaState.hh"
|
||||
#include "LandmarkState.hh"
|
||||
#include "Transition.hh"
|
||||
#include "Event.hh"
|
||||
#include "MetaEvent.hh"
|
||||
#include "expressions/Expression.hh"
|
||||
#include "Variable.hh"
|
||||
#include "Values.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
LandmarkMetaEvent::LandmarkMetaEvent(MetaEvent *me, AltaricaModel *am) {
|
||||
me_ = me;
|
||||
am_ = am;
|
||||
label_ = new AltaricaState(false,am_,am_->getInitInfo());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LandmarkMetaEvent::addLabel(const AltaricaState * l) {
|
||||
l->mergeToState(label_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string LandmarkMetaEvent::toString() const {
|
||||
std::string s;
|
||||
s += me_->toString();
|
||||
s += "LABELS :\n";
|
||||
s += label_->toString(true,false,false,false);
|
||||
return s;
|
||||
}
|
||||
|
||||
void LandmarkMetaEvent::computeLabels(const AltaricaModel*am, const LandmarkState *als) {
|
||||
|
||||
std::vector<bool> varInPreconds(am_->getNStateVars(), false);
|
||||
|
||||
const std::vector<Event*> * evs = me_->getEvents();
|
||||
for (std::vector<Event*>::const_iterator evi = evs->begin(); evi != evs->end(); ++evi) {
|
||||
const std::vector<Transition*> * trans = (*evi)->getTrans();
|
||||
for (std::vector<Transition*>::const_iterator ti = trans->begin(); ti != trans->end(); ++ti) {
|
||||
const Expression * precond = (*ti)->getPrecond();
|
||||
std::vector<Variable*> * newvars = precond->infoVars(am, (*ti)->getNode(), false, false);
|
||||
for (std::vector<Variable*>::iterator nvi = newvars->begin(); nvi != newvars->end(); ++nvi) {
|
||||
varInPreconds[(*nvi)->getIndex()] = true;
|
||||
}
|
||||
delete newvars;
|
||||
}
|
||||
}
|
||||
|
||||
// pour chaque var à true, on prend une seule valeur, et le reste change pas,
|
||||
// si mev valide, on ajoute les labels de cette valeur (addLabel)
|
||||
// vrai car on fait l'union des labels: si une valeur d'une var d'une précond est ok, alors son
|
||||
// label sera dans le label final
|
||||
|
||||
AltaricaState *as = als->getState()->clone();
|
||||
|
||||
for (int i =0; i<am_->getNStateVars(); ++i) {
|
||||
if (varInPreconds[i]) {
|
||||
Value *v = as->getStateValue(i);
|
||||
std::vector<Value*> *afv = v->getSingletons();
|
||||
for (std::vector<Value*>::iterator fvi = afv->begin(); fvi!= afv->end(); ++fvi) {
|
||||
// on teste une des valeurs possibles pour la variable
|
||||
as->setStateValue(i,*fvi);
|
||||
if (me_->isEnabled(am, as)) {
|
||||
addLabel(als->getLabel(i, *fvi));
|
||||
}
|
||||
}
|
||||
as->setStateValue(i,v);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
65
src/grammars/altarica/LandmarkMetaEvent.hh
Normal file
65
src/grammars/altarica/LandmarkMetaEvent.hh
Normal file
@@ -0,0 +1,65 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef LANDMARK_METAEVENT_HH
|
||||
#define LANDMARK_METAEVENT_HH
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaModel;
|
||||
class MetaEvent;
|
||||
class LandmarkState;
|
||||
class AltaricaState;
|
||||
|
||||
class LandmarkMetaEvent {
|
||||
|
||||
private:
|
||||
MetaEvent *me_;
|
||||
AltaricaModel *am_;
|
||||
AltaricaState *label_;
|
||||
|
||||
public:
|
||||
LandmarkMetaEvent(MetaEvent *me, AltaricaModel *m);
|
||||
const MetaEvent * getMetaEvent() const {return me_;}
|
||||
|
||||
void addLabel(const AltaricaState * l);
|
||||
|
||||
const AltaricaState* getLabel() const {return label_;}
|
||||
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
void computeLabels(const AltaricaModel*am, const LandmarkState *als);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
269
src/grammars/altarica/LandmarkState.cc
Normal file
269
src/grammars/altarica/LandmarkState.cc
Normal file
@@ -0,0 +1,269 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "LandmarkState.hh"
|
||||
#include "AltaricaState.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "LandmarkMetaEvent.hh"
|
||||
#include "Transition.hh"
|
||||
#include "Variable.hh"
|
||||
#include "Event.hh"
|
||||
#include "MetaEvent.hh"
|
||||
#include "Assignment.hh"
|
||||
#include "Values.hh"
|
||||
#include "iostream"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
LandmarkState::LandmarkState(AltaricaState *as) {
|
||||
as_ = as;
|
||||
labels_ = new labelsType(as->getAModel()->getNStateVars(), NULL);
|
||||
flowLabels_ = new labelsType(as->getAModel()->getNFlowVars(), NULL);
|
||||
}
|
||||
|
||||
void LandmarkState::addSelfAsLabel() {
|
||||
for (unsigned int i = 0; i<labels_->size(); ++i) {
|
||||
if ((*labels_)[i] == NULL) {
|
||||
(*labels_)[i] = new std::map<Value*, AltaricaState*, ValueComparator>();
|
||||
}
|
||||
Value *v = as_->getStateValue(i);
|
||||
if (v != NULL) {
|
||||
std::vector<Value*> * vfv = v->getSingletons();
|
||||
for (std::vector<Value*>::iterator j = vfv->begin(); j!= vfv->end(); ++j) {
|
||||
if ((*labels_)[i]->find(*j) == (*labels_)[i]->end())
|
||||
(*(*labels_)[i])[*j] = new AltaricaState(false, as_->getAModel(),as_->getAModel()->getInitInfo());
|
||||
(*(*labels_)[i])[*j]->addStateValue(i, *j);
|
||||
(*j)->own();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LandmarkState::removeSelfAsLabel() {
|
||||
for (unsigned int i = 0; i<labels_->size(); ++i) {
|
||||
Value *v = as_->getStateValue(i);
|
||||
if (v != NULL) {
|
||||
std::vector<Value*> * vfv = v->getSingletons();
|
||||
for (std::vector<Value*>::iterator j = vfv->begin(); j!= vfv->end(); ++j) {
|
||||
if ((*labels_)[i]->find(*j) != (*labels_)[i]->end()) {
|
||||
AltaricaState * lm = (*(*labels_)[i])[*j];
|
||||
lm->removeValue(i, *j);
|
||||
if (lm->isEmpty()) {
|
||||
delete lm;
|
||||
((*labels_)[i])->erase(*j);
|
||||
// (*(*labels_)[i])[*j] = NULL;
|
||||
}
|
||||
}
|
||||
// (*j)->own();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LandmarkState::addLabel(unsigned int i, Value* v, const AltaricaState* label) {
|
||||
if ((*labels_)[i] == NULL) {
|
||||
(*labels_)[i] = new std::map<labelsKeyType, AltaricaState*, ValueComparator>();
|
||||
(*((*labels_)[i]))[v] = label->clone();
|
||||
} else {
|
||||
std::map<labelsKeyType, AltaricaState*, ValueComparator>::iterator j = (*labels_)[i]->find(v);
|
||||
if (j == (*labels_)[i]->end())
|
||||
(*((*labels_)[i]))[v] = label->clone();
|
||||
else
|
||||
label->mergeToState(j->second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LandmarkState::addNoopLabels(LandmarkState *ps) {
|
||||
for (unsigned int i =0; i<labels_->size(); ++i) {
|
||||
Value *v = as_->getStateValue(i);
|
||||
Value *vps = ps->getState()->getStateValue(i);
|
||||
if (v != NULL && vps != NULL) {
|
||||
std::vector<Value*> *vfv = v->getSingletons();
|
||||
for (std::vector<Value*>::iterator j = vfv->begin(); j!= vfv->end(); ++j) {
|
||||
if ((*labels_)[i] != NULL)
|
||||
if ((*labels_)[i]->find(*j) != (*labels_)[i]->end())
|
||||
(*(*labels_)[i])[*j]->mergeIntersectState(ps->getLabel(i,*j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AltaricaState* LandmarkState::getLabel(Variable* v, Value *fv) const {
|
||||
if (v->isFlow())
|
||||
return getFlowLabel(v->getIndex(), fv);
|
||||
return getLabel(v->getIndex(), fv);
|
||||
|
||||
}
|
||||
|
||||
AltaricaState* LandmarkState::getLabel(unsigned int i, Value *fv) const {
|
||||
if ((*labels_)[i] == NULL)
|
||||
return NULL;
|
||||
if ((*labels_)[i]->find(fv) == (*labels_)[i]->end())
|
||||
return NULL;
|
||||
return (*(*labels_)[i])[fv];
|
||||
}
|
||||
|
||||
|
||||
AltaricaState* LandmarkState::getFlowLabel(unsigned int i, Value *fv) const {
|
||||
if ((*flowLabels_)[i] == NULL)
|
||||
return NULL;
|
||||
if ((*flowLabels_)[i]->find(fv) == (*flowLabels_)[i]->end())
|
||||
return NULL;
|
||||
return (*(*flowLabels_)[i])[fv];
|
||||
}
|
||||
|
||||
|
||||
std::string LandmarkState::toString() const {
|
||||
std::string s;
|
||||
s += as_->toString(true,true,false,false);
|
||||
s += "LABELS :\n";
|
||||
for (unsigned int i = 0; i<labels_->size(); ++i) {
|
||||
if (as_->getStateValue(i) != NULL) {
|
||||
if ((*labels_)[i] != NULL)
|
||||
for (std::map<labelsKeyType, AltaricaState*>::const_iterator j = (*labels_)[i]->begin(); j!= (*labels_)[i]->end(); ++j) {
|
||||
s += "STATE VAR:" + as_->getAModel()->getStateVar(i)->toString() + "/" + j->first->toString() + " : \n" ;
|
||||
s += j->second->toString(true,false,false,false) ;
|
||||
s += "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
for (unsigned int i = 0; i<flowLabels_->size(); ++i) {
|
||||
if (as_->getFlowValue(i) != NULL) {
|
||||
if ((*flowLabels_)[i] != NULL)
|
||||
for (std::map<labelsKeyType, AltaricaState*>::const_iterator j = (*flowLabels_)[i]->begin(); j!= (*flowLabels_)[i]->end(); ++j) {
|
||||
s += "FLOW VAR:" + as_->getAModel()->getFlowVar(i)->toString() + "/" + j->first->toString() + " : \n" ;
|
||||
if (j->second != NULL)
|
||||
s += j->second->toString(true,false,false,false) ;
|
||||
s+= "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
void LandmarkState::computeLabels(const AltaricaModel *am, const AltaricaState *ps, LandmarkMetaEvent *la) {
|
||||
|
||||
// as_ is current macro state
|
||||
|
||||
std::vector<std::vector<Value*> *> assigned(ps->getAModel()->getNStateVars(), NULL);
|
||||
AltaricaState * ts = ps->clone();
|
||||
|
||||
// we replay the transition to see what values are created by it
|
||||
|
||||
const std::vector<Event*> *evs = la->getMetaEvent()->getEvents();
|
||||
|
||||
for (std::vector<Event*>::const_iterator evi = evs->begin(); evi!= evs->end(); ++evi) {
|
||||
const std::vector<Transition*> * trans = (*evi)->getTrans();
|
||||
for (std::vector<Transition*>::const_iterator transi = trans->begin(); transi!=trans->end(); ++transi) {
|
||||
const std::vector<Assignment*> * assigns = (*transi)->getAssigns();
|
||||
for (std::vector<Assignment*>::const_iterator assi = assigns->begin(); assi!= assigns->end(); ++assi) {
|
||||
//assigned[(*k)->getVar()->getIndex()] = true;
|
||||
Value * v = (*assi)->evaluate(am, ts);
|
||||
std::vector<Value*> *afv = v->getSingletons();
|
||||
for (std::vector<Value*>::iterator i = afv->begin(); i!= afv->end(); ++i) {
|
||||
if (assigned[(*assi)->getVar()->getIndex()] == NULL)
|
||||
assigned[(*assi)->getVar()->getIndex()] = new std::vector<Value*>();
|
||||
assigned[(*assi)->getVar()->getIndex()]->push_back(*i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for each of values created by the transition, we add transition label
|
||||
|
||||
for (unsigned int i = 0; i<ps->getAModel()->getNStateVars(); ++i) {
|
||||
if (assigned[i]!=NULL) {
|
||||
for (std::vector<Value*>::iterator j = assigned[i]->begin(); j!= assigned[i]->end(); ++j)
|
||||
addLabel(i,(Value*)*j, la->getLabel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LandmarkState::mergeIntersectLabels(const LandmarkState * os) {
|
||||
const labelsType * l = os->getLabels();
|
||||
for (unsigned int i =0; i<labels_->size(); ++i) {
|
||||
if ((*labels_)[i] == NULL) {
|
||||
if (((*l)[i])!=NULL)
|
||||
(*labels_)[i] = new std::map<labelsKeyType, AltaricaState*, ValueComparator>(*((*l)[i]));
|
||||
else
|
||||
(*labels_)[i] = new std::map<labelsKeyType, AltaricaState*, ValueComparator>();
|
||||
} else {
|
||||
if ((*l)[i]!=NULL)
|
||||
for (std::map<Value*, AltaricaState*,ValueComparator>::iterator
|
||||
j = (*l)[i]->begin(); j!= (*l)[i]->end(); ++j) {
|
||||
if ((*labels_)[i]->find(j->first) == (*labels_)[i]->end())
|
||||
(*(*labels_)[i])[j->first] = j->second->clone();
|
||||
else
|
||||
(*(*labels_)[i])[j->first]->intersectState(j->second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
l = os->getFlowLabels();
|
||||
for (unsigned int i =0; i<flowLabels_->size(); ++i) {
|
||||
if ((*flowLabels_)[i] == NULL) {
|
||||
if (((*l)[i])!=NULL)
|
||||
(*flowLabels_)[i] = new std::map<labelsKeyType, AltaricaState*, ValueComparator>(*((*l)[i]));
|
||||
else
|
||||
(*flowLabels_)[i] = new std::map<labelsKeyType, AltaricaState*, ValueComparator>();
|
||||
} else {
|
||||
if ((*l)[i]!=NULL)
|
||||
for (std::map<Value*, AltaricaState*,ValueComparator>::iterator
|
||||
j = (*l)[i]->begin(); j!= (*l)[i]->end(); ++j) {
|
||||
if ((*flowLabels_)[i]->find(j->first) == (*flowLabels_)[i]->end())
|
||||
(*(*flowLabels_)[i])[j->first] = j->second->clone();
|
||||
else
|
||||
(*(*flowLabels_)[i])[j->first]->intersectState(j->second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LandmarkState::computeFlowLabels(const AltaricaModel *am) {
|
||||
unsigned int nfv = am->getNFlowVars();
|
||||
as_->deleteFlowValues();
|
||||
for (unsigned int i = 0; i<nfv; ++i) {
|
||||
Variable *v = am->getFlowVar(i);
|
||||
v->evaluateLM(am, this);
|
||||
std::cout << this->toString();
|
||||
}
|
||||
|
||||
}
|
||||
95
src/grammars/altarica/LandmarkState.hh
Normal file
95
src/grammars/altarica/LandmarkState.hh
Normal file
@@ -0,0 +1,95 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef LANDMARK_STATE_HH
|
||||
#define LANDMARK_STATE_HH
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Values.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaModel;
|
||||
class AltaricaState;
|
||||
class Variable;
|
||||
class LandmarkMetaEvent;
|
||||
class Value;
|
||||
|
||||
typedef Value* labelsKeyType;
|
||||
|
||||
|
||||
class ValueComparator {
|
||||
public:
|
||||
bool operator() (const labelsKeyType& a, const labelsKeyType& b) const {
|
||||
return a->less(b);
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<Value*, AltaricaState*, ValueComparator> landmarkType;
|
||||
|
||||
typedef std::vector<landmarkType*> labelsType;
|
||||
|
||||
|
||||
// for each variable (vector) a map between a value and corresponding labels
|
||||
|
||||
class LandmarkState {
|
||||
|
||||
|
||||
private:
|
||||
AltaricaState *as_;
|
||||
labelsType *labels_;
|
||||
labelsType *flowLabels_;
|
||||
|
||||
public:
|
||||
LandmarkState(AltaricaState *as);
|
||||
AltaricaState * getState() const {return as_;}
|
||||
void addSelfAsLabel();
|
||||
void removeSelfAsLabel();
|
||||
// void addLabel(labelsType *l);
|
||||
void addLabel(unsigned int i, Value* v, const AltaricaState* label);
|
||||
void addNoopLabels(LandmarkState *ps);
|
||||
|
||||
// return NULL if no label
|
||||
AltaricaState* getLabel(Variable* v, Value *fv) const ;
|
||||
AltaricaState* getLabel(unsigned int i, Value *fv) const ;
|
||||
AltaricaState* getFlowLabel(unsigned int i, Value *fv) const ;
|
||||
labelsType * getLabels() const {return labels_;}
|
||||
labelsType * getFlowLabels() const {return flowLabels_;}
|
||||
|
||||
void computeLabels(const AltaricaModel*am, const AltaricaState *ps, LandmarkMetaEvent *la);
|
||||
void computeFlowLabels(const AltaricaModel*am);
|
||||
void mergeIntersectLabels(const LandmarkState *os);
|
||||
|
||||
std::string toString() const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
458
src/grammars/altarica/MemberAccess.cc
Normal file
458
src/grammars/altarica/MemberAccess.cc
Normal file
@@ -0,0 +1,458 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MemberAccess.hh"
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <boost/tokenizer.hpp>
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
Ident::~Ident() {
|
||||
}
|
||||
|
||||
MemberAccess::MemberAccess(){
|
||||
isGlobal_ = false;
|
||||
doString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
MemberAccess::MemberAccess(std::string id, std::vector<int> *v) {
|
||||
isGlobal_ = false;
|
||||
Ident* i = new Ident();
|
||||
i->id = id;
|
||||
for (std::vector<int>::iterator j = v->begin(); j != v->end(); ++j)
|
||||
i->indexes.push_back(*j);
|
||||
// i->indexes = v;
|
||||
path_.push_back(i);
|
||||
doString();
|
||||
}
|
||||
|
||||
MemberAccess::MemberAccess(std::string id) {
|
||||
isGlobal_ = false;
|
||||
std::istringstream iss(id);
|
||||
std::string slice;
|
||||
bool first = true;
|
||||
|
||||
while (std::getline(iss,slice,'.')) {
|
||||
Ident* i = new Ident();
|
||||
boost::char_separator<char> sep("[]");
|
||||
boost::tokenizer<boost::char_separator<char> > tok(slice, sep);
|
||||
i->id = *(tok.begin());
|
||||
if (first && i->id.compare("main") == 0)
|
||||
isGlobal_ = true;
|
||||
first = false;
|
||||
|
||||
// i->indexes = new std::vector<int>();
|
||||
for (boost::tokenizer<boost::char_separator<char> >::const_iterator j = ++tok.begin();
|
||||
j != tok.end(); ++j)
|
||||
i->indexes.push_back(atoi((*j).c_str()));
|
||||
path_.push_back(i);
|
||||
}
|
||||
doString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MemberAccess::addIdBack(std::string id) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
// nap->indexes = new std::vector<int>();
|
||||
path_.push_back(nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
|
||||
void MemberAccess::addIdBack(std::string id, std::vector<int> &iv) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
for (std::vector<int>::iterator i = iv.begin(); i!=iv.end(); ++i)
|
||||
nap->indexes.push_back(*i);
|
||||
path_.push_back(nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIdBackNoString(std::string id, std::vector<int> &iv) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
for (std::vector<int>::iterator i = iv.begin(); i!=iv.end(); ++i)
|
||||
nap->indexes.push_back(*i);
|
||||
// nap->indexes = iv;
|
||||
path_.push_back(nap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MemberAccess::addIdBack(std::string id, int i) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
// nap->indexes = new std::vector<int>();
|
||||
nap->indexes.push_back(i);
|
||||
path_.push_back(nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIdFront(std::string id) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
// nap->indexes = new std::vector<int>();
|
||||
path_.insert(path_.begin(),nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIdFront(std::string id, std::vector<int> &iv) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
for (std::vector<int>::iterator i = iv.begin(); i!=iv.end(); ++i)
|
||||
nap->indexes.push_back(*i);
|
||||
// nap->indexes = iv;
|
||||
path_.insert(path_.begin(),nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIdFront(std::string id, int i) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
// nap->indexes = new std::vector<int>();
|
||||
nap->indexes.push_back(i);
|
||||
path_.insert(path_.begin(),nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::removeIdFront() {
|
||||
Ident * a= path_[0];
|
||||
path_.erase(path_.begin());
|
||||
delete a;
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::removeIdFrontNoString() {
|
||||
Ident * a= path_[0];
|
||||
path_.erase(path_.begin());
|
||||
delete a;
|
||||
}
|
||||
|
||||
|
||||
bool MemberAccess::removeIdFront(std::string id) {
|
||||
if (id.compare(path_[0]->id)!= 0)
|
||||
return false;
|
||||
removeIdFront();
|
||||
return true;
|
||||
doString();
|
||||
}
|
||||
|
||||
bool MemberAccess::removeIdFront(std::string id, std::vector<int> *iv) {
|
||||
Ident * a = path_[0];
|
||||
if ((!sameIndexes(iv, &a->indexes)) || (id.compare(a->id)!= 0))
|
||||
return false;
|
||||
removeIdFront();
|
||||
doString();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MemberAccess::removeIdFrontNoString(std::string id, std::vector<int> *iv) {
|
||||
Ident * a = path_[0];
|
||||
if ((!sameIndexes(iv, &a->indexes)) || (id.compare(a->id)!= 0))
|
||||
return false;
|
||||
removeIdFrontNoString();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MemberAccess::addIndexBack(int i) {
|
||||
path_[path_.size()-1]->indexes.push_back(i);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIndexesBack(std::vector<int> *iv){
|
||||
for (std::vector<int>::iterator i = iv->begin();
|
||||
i != iv->end(); ++i)
|
||||
addIndexBack(*i);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIndexFront(int i) {
|
||||
path_[0]->indexes.push_back(i);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIndexesFront(std::vector<int> *iv) {
|
||||
for (std::vector<int>::iterator i = iv->begin();
|
||||
i != iv->end(); ++i)
|
||||
addIndexFront(*i);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIndex(std::string id, int i) {
|
||||
for (std::vector<Ident*>::iterator pi = path_.begin();
|
||||
pi != path_.end(); ++pi) {
|
||||
if ((*pi)->id.compare(id)==0) {
|
||||
(*pi)->indexes.push_back(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIndexes(std::string id, std::vector<int> *v) {
|
||||
for (std::vector<Ident*>::iterator pi = path_.begin();
|
||||
pi != path_.end(); ++pi) {
|
||||
if ((*pi)->id.compare(id)==0) {
|
||||
for (std::vector<int>::iterator vi = v->begin(); vi != v->end(); ++vi)
|
||||
(*pi)->indexes.push_back(*vi);
|
||||
return;
|
||||
}
|
||||
}
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIndexSecond(int i) {
|
||||
if (path_[0]->indexes.size() != 0)
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("wrong logic in member access name while flattening array domain")));
|
||||
path_[0]->indexes.push_back(i);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIdSecond(std::string s) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = s;
|
||||
// nap->indexes = new std::vector<int>();
|
||||
path_.insert(++path_.begin(), nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MemberAccess::setGlobal(bool b) {
|
||||
isGlobal_ = b;
|
||||
}
|
||||
|
||||
bool MemberAccess::isGlobal() const {
|
||||
return isGlobal_;
|
||||
}
|
||||
|
||||
MemberAccess* MemberAccess::clone() const{
|
||||
MemberAccess * n = new MemberAccess();
|
||||
for (std::vector<Ident*>::const_iterator i = path_.begin(); i!= path_.end(); ++i)
|
||||
n->addIdBackNoString(std::string((*i)->id), (*i)->indexes);
|
||||
n->setGlobal(isGlobal_);
|
||||
n->doString();
|
||||
return n;
|
||||
}
|
||||
|
||||
const std::vector<Ident*> * MemberAccess::getAccesses() const {
|
||||
return &path_;
|
||||
}
|
||||
|
||||
void MemberAccess::addMemberAccessBack(MemberAccess *ma) {
|
||||
for (std::vector<Ident*>::const_iterator i = ma->getAccesses()->begin();
|
||||
i!= ma->getAccesses()->end(); ++i)
|
||||
addIdBack((*i)->id, (*i)->indexes);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addMemberAccessFront(MemberAccess *ma) {
|
||||
for (std::vector<Ident*>::const_iterator i = ma->getAccesses()->begin();
|
||||
i!= ma->getAccesses()->end(); ++i)
|
||||
addIdFront((*i)->id, (*i)->indexes);
|
||||
doString();
|
||||
}
|
||||
|
||||
bool MemberAccess::sameIndexes(const std::vector<int> * ind1, const std::vector<int> * ind2) {
|
||||
if (ind1 == NULL)
|
||||
return ind2 == NULL;
|
||||
else if (ind2 == NULL)
|
||||
return false;
|
||||
// if (ind1->size() == 0)
|
||||
// return (ind2->size() == 0);
|
||||
if (ind1->size() != ind2->size())
|
||||
return false;
|
||||
std::vector<int>::const_iterator i2 = ind2->begin();
|
||||
for (std::vector<int>::const_iterator i1 = ind1->begin(); i1 != ind1->end(); ++i1) {
|
||||
if (*i1 != *i2)
|
||||
return false;
|
||||
++i2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MemberAccess::equals(const MemberAccess* ma) const {
|
||||
return (s_.compare(ma->toString()) == 0);
|
||||
// const std::vector<Ident*> * otherPath = ma->getAccesses();
|
||||
// if (otherPath->size() != path_.size())
|
||||
// return false;
|
||||
// std::vector<Ident*>::iterator i2 = path_.begin();
|
||||
// for (std::vector<Ident*>::const_iterator i1 = otherPath->begin(); i1 != otherPath->end(); ++i1, ++i2) {
|
||||
// if ((*i1)->id.compare((*i2)->id) != 0)
|
||||
// return false;
|
||||
// if (!sameIndexes((*i1)->indexes, (*i2)->indexes))
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
MemberAccess * MemberAccess::buildSuffix(const MemberAccess *ma) const {
|
||||
// MemberAccess * nma = clone();
|
||||
// nma->setGlobal(false);
|
||||
// const std::vector<Ident*> * frontPath = ma->getAccesses();
|
||||
// for (std::vector<Ident*>::const_iterator i = frontPath->begin();
|
||||
// i != frontPath->end(); ++i)
|
||||
// if (!nma->removeIdFrontNoString((*i)->id, (*i)->indexes)) {
|
||||
// delete(nma);
|
||||
// return NULL;
|
||||
// }
|
||||
// nma->doString();
|
||||
// return nma;
|
||||
|
||||
const std::vector<Ident*> * frontPath = ma->getAccesses();
|
||||
int j = 0;
|
||||
for (std::vector<Ident*>::const_iterator i = frontPath->begin(); i != frontPath->end(); ++i) {
|
||||
Ident *ij = path_[j];
|
||||
if ((!sameIndexes(&ij->indexes, &(*i)->indexes)) || (ij->id.compare((*i)->id)!= 0))
|
||||
return NULL;
|
||||
++j;
|
||||
}
|
||||
MemberAccess *nma = new MemberAccess();
|
||||
for (; j<path_.size(); ++j) {
|
||||
nma->addIdBackNoString(std::string(path_[j]->id),path_[j]->indexes);
|
||||
}
|
||||
nma->doString();
|
||||
return nma;
|
||||
}
|
||||
|
||||
|
||||
void MemberAccess::addSimpleCombinationsRec(std::vector<int>* idx, std::vector<int>* maxidxs,
|
||||
std::vector<std::vector<int>*>* iidx) {
|
||||
if (maxidxs->size() == 0) {
|
||||
iidx->push_back(new std::vector<int>(*idx));
|
||||
} else {
|
||||
int m = maxidxs->front();
|
||||
maxidxs->erase(maxidxs->begin());
|
||||
for (int i = 0; i<m; ++i) {
|
||||
idx->push_back(i);
|
||||
addSimpleCombinationsRec(idx, maxidxs, iidx);
|
||||
idx->pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::vector<int>*>* MemberAccess::buildSimpleCombinations(std::vector<int>* idxs) {
|
||||
std::vector<int> * idx = new std::vector<int>();
|
||||
std::vector<std::vector<int>*>* iidx = new std::vector<std::vector<int>*>();
|
||||
addSimpleCombinationsRec(idx, idxs, iidx);
|
||||
delete(idx);
|
||||
return iidx;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<MemberAccess*> * MemberAccess::buildCombinations() {
|
||||
std::vector<MemberAccess*> * ret = new std::vector<MemberAccess*>();
|
||||
ret->push_back(new MemberAccess());
|
||||
|
||||
for (std::vector<Ident*>::iterator api = path_.begin(); api!= path_.end(); ++api) {
|
||||
Ident* ap = (*api);
|
||||
std::vector<std::vector<int>* > * comb = buildSimpleCombinations ( &ap->indexes );
|
||||
int ncomb = comb->size();
|
||||
int nma = ret->size();
|
||||
|
||||
|
||||
for (int i = 1; i<ncomb; ++i) {
|
||||
for (int j = 0; j<nma; ++j) {
|
||||
ret->push_back( ((*ret)[j])->clone());
|
||||
}
|
||||
}
|
||||
for (int i = 0; i< ncomb; ++i) {
|
||||
for (int j= 0; j<nma; ++j) {
|
||||
(*ret)[i*nma+j]->addIdBack(ap->id, *((*comb)[i]));
|
||||
}
|
||||
delete (*comb)[i];
|
||||
}
|
||||
delete comb;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const std::string MemberAccess::getSymbol() const {
|
||||
return path_[0]->id;
|
||||
}
|
||||
|
||||
|
||||
void MemberAccess::toString_() {
|
||||
s_.clear();
|
||||
|
||||
for (std::vector<Ident*>::iterator ii = path_.begin(); ii != path_.end();) {
|
||||
s_+= (*ii)->id ;
|
||||
if ((*ii)->indexes.size() != 0)
|
||||
for (std::vector<int>::iterator iii = (*ii)->indexes.begin();
|
||||
iii != (*ii)->indexes.end(); ++iii) {
|
||||
s_+= "[";
|
||||
s_+= (*iii);
|
||||
s_+= "]";
|
||||
}
|
||||
if (++ii != path_.end())
|
||||
s_+= ".";
|
||||
}
|
||||
}
|
||||
|
||||
void MemberAccess::headToString_() {
|
||||
h_.clear();
|
||||
if (path_.size() == 0)
|
||||
return;
|
||||
h_+= path_[0]->id ;
|
||||
if (path_[0]->indexes.size() != 0)
|
||||
for (std::vector<int>::iterator iii = path_[0]->indexes.begin();
|
||||
iii != path_[0]->indexes.end(); ++iii) {
|
||||
h_+= "[";
|
||||
h_+= (*iii);
|
||||
h_+= "]";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MemberAccess::~MemberAccess() {
|
||||
for (std::vector<Ident*>::iterator i = path_.begin();
|
||||
i!= path_.end(); ++i)
|
||||
delete(*i);
|
||||
h_.clear();
|
||||
s_.clear();
|
||||
}
|
||||
|
||||
void MemberAccess::doString() {
|
||||
toString_();
|
||||
headToString_();
|
||||
}
|
||||
}
|
||||
}
|
||||
135
src/grammars/altarica/MemberAccess.hh
Normal file
135
src/grammars/altarica/MemberAccess.hh
Normal file
@@ -0,0 +1,135 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_MEMBER_ACCESS_H_
|
||||
#define ALTA_MEMBER_ACCESS_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Ident {
|
||||
public :
|
||||
std::string id;
|
||||
std::vector<int> indexes;
|
||||
~Ident();
|
||||
} ;
|
||||
|
||||
class MemberAccess {
|
||||
protected:
|
||||
std::vector<Ident*> path_;
|
||||
bool isGlobal_ ;
|
||||
std::string s_;
|
||||
std::string h_;
|
||||
const std::vector<Ident*> * getAccesses() const;
|
||||
|
||||
|
||||
void addSimpleCombinationsRec(std::vector<int>* idx, std::vector<int>* maxidxs,
|
||||
std::vector<std::vector<int>*>* iidx);
|
||||
std::vector<std::vector<int>*>* buildSimpleCombinations(std::vector<int>* idxs);
|
||||
void toString_();
|
||||
void headToString_();
|
||||
|
||||
|
||||
private:
|
||||
void addIdBackNoString(std::string id, std::vector<int> &iv);
|
||||
void removeIdFrontNoString();
|
||||
bool removeIdFrontNoString(std::string id, std::vector<int> *iv);
|
||||
public:
|
||||
|
||||
|
||||
//! empty constructor
|
||||
MemberAccess();
|
||||
~MemberAccess();
|
||||
|
||||
//! empty constructor with reservation
|
||||
MemberAccess(int n);
|
||||
|
||||
MemberAccess(std::string id, std::vector<int> *v);
|
||||
MemberAccess(std::string id);
|
||||
|
||||
|
||||
void addIdBack(std::string id);
|
||||
// void addIdBack(std::string id, std::vector<int> *iv);
|
||||
void addIdBack(std::string id, std::vector<int> &iv);
|
||||
|
||||
void addIdBack(std::string id, int i);
|
||||
|
||||
void addIdFront(std::string id);
|
||||
void addIdFront(std::string id, std::vector<int> &iv);
|
||||
void addIdFront(std::string id, int i);
|
||||
void removeIdFront();
|
||||
|
||||
bool removeIdFront(std::string id);
|
||||
bool removeIdFront(std::string id, std::vector<int> *iv);
|
||||
|
||||
|
||||
|
||||
|
||||
void addIndexBack(int i);
|
||||
void addIndexesBack(std::vector<int> *iv);
|
||||
|
||||
void addIndexFront(int i);
|
||||
void addIndexesFront(std::vector<int> *iv);
|
||||
|
||||
void addIndexSecond(int i);
|
||||
void addIdSecond(std::string s);
|
||||
|
||||
void addIndex(std::string id, int i);
|
||||
void addIndexes(std::string id, std::vector<int> *iv);
|
||||
|
||||
void setGlobal(bool b);
|
||||
bool isGlobal() const;
|
||||
|
||||
//! join two memberAcesses
|
||||
void addMemberAccessBack(MemberAccess *ma);
|
||||
void addMemberAccessFront(MemberAccess *ma);
|
||||
|
||||
MemberAccess * buildSuffix(const MemberAccess *ma) const;
|
||||
|
||||
bool equals(const MemberAccess* ma) const;
|
||||
|
||||
MemberAccess* clone() const;
|
||||
|
||||
static bool sameIndexes(const std::vector<int> * ind1, const std::vector<int> * ind2);
|
||||
|
||||
std::vector<MemberAccess*> * buildCombinations();
|
||||
|
||||
inline std::string toString() const {return s_;}
|
||||
|
||||
inline std::string headToString() const {return h_;}
|
||||
const std::string getSymbol() const;
|
||||
|
||||
void doString();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
292
src/grammars/altarica/MetaEvent.cc
Normal file
292
src/grammars/altarica/MetaEvent.cc
Normal file
@@ -0,0 +1,292 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MetaEvent.hh"
|
||||
#include "Event.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include <sstream>
|
||||
#include <cfloat>
|
||||
#include <iostream>
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
double MetaEvent::complementOthersProba(std::vector<const Event*> * allEvents, AltaricaModel *am, AltaricaState *as) {
|
||||
double proba = 1.0;
|
||||
for (std::vector<const Event*>::iterator i = allEvents->begin(); i!= allEvents->end(); ++i) {
|
||||
if (!containsE(*i))
|
||||
proba *= 1.0-(*i)->getLaw()->evalParam(am,as);
|
||||
}
|
||||
return proba;
|
||||
}
|
||||
|
||||
|
||||
void MetaEvent::push_back(Event *e) {
|
||||
events_->push_back(e);
|
||||
}
|
||||
|
||||
bool MetaEvent::containsE(const Event *e) const{
|
||||
for (std::vector<Event*>::iterator i = events_->begin(); i!= events_->end(); ++i)
|
||||
if (e == *i)
|
||||
return true;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
MetaEvent* MetaEvent::unionMetaEvents(std::vector<MetaEvent*> * metavec) {
|
||||
MetaEvent * unions = new MetaEvent();
|
||||
for (std::vector<MetaEvent*>::iterator si = metavec->begin(); si!=metavec->end(); ++si) {
|
||||
unions->add(*si);
|
||||
}
|
||||
return unions;
|
||||
}
|
||||
|
||||
bool MetaEvent::contains(const MetaEvent* mev) const
|
||||
{
|
||||
for (auto i:*mev->getEvents())
|
||||
if (!containsE(i))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MetaEvent::equals(const MetaEvent* mev) const
|
||||
{
|
||||
if (!contains(mev))
|
||||
return false;
|
||||
if (!mev->contains(this))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MetaEvent::addMEV(std::vector<MetaEvent*> * list, MetaEvent* mev)
|
||||
{
|
||||
for (auto i:*list)
|
||||
if (i->equals(mev))
|
||||
return false;
|
||||
list->push_back(mev);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::vector<MetaEvent*>* MetaEvent::combineMetaEvents(std::vector<MetaEvent*> * metavec) {
|
||||
std::vector<MetaEvent*> * combined = new std::vector<MetaEvent*>();
|
||||
|
||||
while (!metavec->empty()) {
|
||||
MetaEvent * mev = metavec->back();
|
||||
metavec->pop_back();
|
||||
|
||||
if (combined->empty())
|
||||
combined->push_back(mev);
|
||||
else {
|
||||
std::vector<MetaEvent*> newMEVs;
|
||||
for (auto i:*combined) {
|
||||
if (!i->contains(mev)) {
|
||||
MetaEvent * nmev = i->clone();
|
||||
nmev->add(mev);
|
||||
newMEVs.push_back(nmev);
|
||||
}
|
||||
}
|
||||
for (auto i:newMEVs)
|
||||
if (!addMEV(combined, i))
|
||||
delete i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return combined;
|
||||
|
||||
}
|
||||
|
||||
|
||||
unsigned int MetaEvent::size() {
|
||||
return events_->size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool MetaEvent::eventIn(Event *e) {
|
||||
for (std::vector<Event*>::iterator i = events_->begin(); i!= events_->end(); ++i)
|
||||
if (e == *i)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MetaEvent::add(MetaEvent* m) {
|
||||
bool changed = false;
|
||||
const std::vector<Event*> * otherE = m->getEvents();
|
||||
for (std::vector<Event*>::const_iterator i = otherE->begin(); i!= otherE->end(); ++i) {
|
||||
if (!eventIn(*i)) {
|
||||
events_->push_back(*i);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::vector<MetaEvent*>* MetaEvent::buildVec(std::vector<std::vector<Event*>*>* v) {
|
||||
std::vector<MetaEvent*>* ret = new std::vector<MetaEvent*>();
|
||||
for (std::vector<std::vector<Event*>*>::iterator i = v->begin(); i!= v->end(); ++i) {
|
||||
ret->push_back(new MetaEvent(*i));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
MetaEvent::MetaEvent() {
|
||||
events_ = new std::vector<Event*>();
|
||||
}
|
||||
|
||||
MetaEvent::MetaEvent(std::vector<Event*> *v) {
|
||||
events_ = v;
|
||||
}
|
||||
|
||||
MetaEvent * MetaEvent::clone() const {
|
||||
MetaEvent * r = new MetaEvent();
|
||||
for (std::vector<Event*>::iterator i = events_->begin(); i!= events_->end(); ++i)
|
||||
r->push_back(*i);
|
||||
r->setProba(proba_);
|
||||
r->setReward(reward_);
|
||||
return r;
|
||||
}
|
||||
|
||||
MetaEvent::~MetaEvent() {
|
||||
delete events_;
|
||||
}
|
||||
|
||||
int MetaEvent::comparePrioTo(MetaEvent* other) {
|
||||
bool meMorePrior = false;
|
||||
bool meLessPrior = false;
|
||||
const std::vector<Event*> * otherE= other->getEvents();
|
||||
|
||||
// first check if I have one event comparable
|
||||
for (std::vector<Event*>::const_iterator i = otherE->begin();
|
||||
meMorePrior == false && meLessPrior == false && i!= otherE->end(); ++i) {
|
||||
for (std::vector<Event*>::iterator j = events_->begin();
|
||||
meMorePrior == false && meLessPrior == false && j!= events_->end(); ++j) {
|
||||
if ((*j)->isMorePriorThan(*i))
|
||||
meMorePrior = true;
|
||||
if ((*j)->isLessPriorThan(*i))
|
||||
meLessPrior = true;
|
||||
}
|
||||
}
|
||||
|
||||
// if incomparable, same prio
|
||||
if (!meLessPrior && !meMorePrior)
|
||||
return 0;
|
||||
|
||||
// if comparable,
|
||||
// now check that I do not have and opposite prio event
|
||||
// if so -> same prio
|
||||
if (meLessPrior || meMorePrior)
|
||||
for (std::vector<Event*>::const_iterator i = otherE->begin(); i!= otherE->end(); ++i) {
|
||||
for (std::vector<Event*>::iterator j = events_->begin(); j!= events_->end(); ++j) {
|
||||
if (meMorePrior && (*i)->isMorePriorThan(*j))
|
||||
return 0;
|
||||
if (meLessPrior && (*i)->isLessPriorThan(*j))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (meMorePrior)
|
||||
return 1;
|
||||
if (meLessPrior)
|
||||
return -1;
|
||||
|
||||
// never reached
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool MetaEvent::isEnabled(const AltaricaModel *am, AltaricaState *s) const {
|
||||
for (std::vector<Event*>::iterator ei = events_->begin(); ei != events_->end(); ++ei) {
|
||||
if (!(*ei)->isEnabled(am, s))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MetaEvent::isDirac() const {
|
||||
for (std::vector<Event*>::const_iterator i = events_->begin(); i!= events_->end(); ++i) {
|
||||
if ((*i)->getLaw() != NULL && (*i)->getLaw()->isDirac())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string MetaEvent::toString() {
|
||||
// std::string s;
|
||||
std::stringstream s;
|
||||
s << "MetaEvent: < p = ";
|
||||
s << proba_;
|
||||
s << " r = ";
|
||||
s << reward_;
|
||||
s << " ";
|
||||
if (events_->size() != 0)
|
||||
for (std::vector<Event*>::iterator i = events_->begin(); i!=events_->end(); ++i)
|
||||
s << (*i)->toString();
|
||||
else
|
||||
s << " NO EVENT";
|
||||
s<< ">\n";
|
||||
return s.str();
|
||||
}
|
||||
|
||||
double MetaEvent::timesDiscreteProba(AltaricaModel *am, AltaricaState *as) {
|
||||
proba_ = 1.0;
|
||||
for (std::vector<Event*>::iterator i = events_->begin(); i!= events_->end(); ++i) {
|
||||
if ((*i)->getLaw() != NULL)
|
||||
proba_ *= (*i)->getLaw()->evalParam(am,as);
|
||||
}
|
||||
return proba_;
|
||||
}
|
||||
double MetaEvent::timesDiscreteProba(double p) {
|
||||
proba_ *= p;
|
||||
return proba_;
|
||||
}
|
||||
|
||||
|
||||
void MetaEvent::setMaxContProba(AltaricaModel *am, AltaricaState *as) {
|
||||
proba_ = DBL_MIN;
|
||||
bool printed = true;
|
||||
for (std::vector<Event*>::iterator i = events_->begin(); i!= events_->end(); ++i) {
|
||||
if ((*i)->getLaw() != NULL) {
|
||||
if (proba_ != DBL_MIN) {
|
||||
if (!printed) {
|
||||
std::cerr<< "BIG FAT WARNING: >1 synchronised events have a continuous law: theoretical proba is 0........." << std::endl;
|
||||
std::cerr<< toString() << std::endl;
|
||||
printed = true;
|
||||
}
|
||||
}
|
||||
if ((*i)->getLaw()->evalParam(am,as) > proba_)
|
||||
proba_ = (*i)->getLaw()->evalParam(am,as);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
89
src/grammars/altarica/MetaEvent.hh
Normal file
89
src/grammars/altarica/MetaEvent.hh
Normal file
@@ -0,0 +1,89 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_MEV_HH
|
||||
#define ALTARICA_MEV_HH
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
class Event;
|
||||
|
||||
|
||||
//! meta event class : synchronised atomic events
|
||||
class MetaEvent {
|
||||
|
||||
private:
|
||||
|
||||
std::vector<Event*> *events_;
|
||||
double proba_;
|
||||
double reward_;
|
||||
|
||||
public:
|
||||
|
||||
MetaEvent();
|
||||
~MetaEvent();
|
||||
MetaEvent(std::vector<Event*> *v);
|
||||
void push_back(Event* e);
|
||||
bool containsE(const Event* e) const;
|
||||
unsigned int size();
|
||||
bool add(MetaEvent* m);
|
||||
std::vector<Event*> * getEvents() const {return events_;}
|
||||
int comparePrioTo(MetaEvent* other);
|
||||
bool eventIn(Event *e);
|
||||
double getProba() const {return proba_;}
|
||||
void setProba(double p) {proba_ = p;}
|
||||
double getReward() const {return reward_;}
|
||||
void setReward(double r) {reward_ = r;}
|
||||
double timesDiscreteProba(AltaricaModel *am, AltaricaState *as);
|
||||
double timesDiscreteProba(double p);
|
||||
double complementOthersProba(std::vector<const Event*> * allEvents, AltaricaModel *am, AltaricaState *as);
|
||||
void setMaxContProba(AltaricaModel *am, AltaricaState *as);
|
||||
MetaEvent * clone() const;
|
||||
inline bool isEmpty() {return events_->size() == 0;}
|
||||
|
||||
bool isEnabled(const AltaricaModel *am, AltaricaState *s) const;
|
||||
bool equals(const MetaEvent * mev) const;
|
||||
bool contains(const MetaEvent* mev) const ;
|
||||
|
||||
|
||||
bool isDirac() const;
|
||||
static MetaEvent* unionMetaEvents(std::vector<MetaEvent*> *metavec);
|
||||
static std::vector<MetaEvent*>* combineMetaEvents(std::vector<MetaEvent*> *metavec);
|
||||
static bool addMEV(std::vector<MetaEvent*> *list, MetaEvent *mev);
|
||||
static std::vector<MetaEvent*>* buildVec(std::vector<std::vector<Event*>*>* v);
|
||||
std::string toString();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
836
src/grammars/altarica/Node.cc
Normal file
836
src/grammars/altarica/Node.cc
Normal file
@@ -0,0 +1,836 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Node.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "Parameter.hh"
|
||||
#include "Variable.hh"
|
||||
#include "Event.hh"
|
||||
#include "Transition.hh"
|
||||
#include "Assertion.hh"
|
||||
#include "Synchronisation.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include "Assignment.hh"
|
||||
#include "domains/EnumDomain.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
Node::Node() {
|
||||
// name_ = NULL;
|
||||
ma_ = NULL;
|
||||
typeName_ =NULL;
|
||||
events_by_prio_ = NULL;
|
||||
parent_ = NULL;
|
||||
}
|
||||
|
||||
Node * Node::clone() const {
|
||||
Node * n = new Node();
|
||||
n->setMA(ma_->clone());
|
||||
n->setTypeName(typeName_->clone());
|
||||
n->setParent(parent_);
|
||||
for(std::vector<std::string>::const_iterator it = attributes_.begin();
|
||||
it != attributes_.end(); ++it)
|
||||
n->addAttribute(*it);
|
||||
for(std::vector<Parameter*>::const_iterator it = params_.begin();
|
||||
it != params_.end(); ++it)
|
||||
n->addParam((*it)->clone());
|
||||
for (std::map<std::string, Variable*, ltstr>::const_iterator it = stateVars_.begin();
|
||||
it != stateVars_.end(); ++it) {
|
||||
Variable * v = it->second->clone();
|
||||
n->addVariable(v);
|
||||
}
|
||||
for (std::map<std::string, Variable*, ltstr>::const_iterator it = flowVars_.begin();
|
||||
it != flowVars_.end(); ++it) {
|
||||
Variable * v = it->second->clone();
|
||||
n->addVariable(v);
|
||||
}
|
||||
for(std::map<std::string,Event*,ltstr>::const_iterator it = events_.begin();
|
||||
it != events_.end(); ++it) {
|
||||
n->addEvent(it->second->clone());
|
||||
}
|
||||
for(std::vector<Transition*>::const_iterator it = trans_.begin();
|
||||
it != trans_.end(); ++it) {
|
||||
n->addTransition((*it)->clone());
|
||||
}
|
||||
for(std::vector<Assertion*>::const_iterator it = asserts_.begin();
|
||||
it != asserts_.end(); ++it)
|
||||
n->addAssertion((*it)->clone());
|
||||
for(std::map<std::string, Node*, ltstr>::const_iterator it = subNodes_.begin();
|
||||
it != subNodes_.end(); ++it)
|
||||
n->addSubNode(it->second->clone());
|
||||
for(std::vector<Synchronisation*>::const_iterator it = syncs_.begin();
|
||||
it != syncs_.end(); ++it)
|
||||
n->addSync((*it)->clone());
|
||||
for(std::vector<Assignment*>::const_iterator it = inits_.begin();
|
||||
it != inits_.end(); ++it)
|
||||
n->addInit((*it)->clone());
|
||||
for(std::vector<Assignment*>::const_iterator it = paramSets_.begin();
|
||||
it != paramSets_.end(); ++it)
|
||||
n->addParamsSet((*it)->clone());
|
||||
for(std::vector<std::string>::const_iterator it = externals_.begin();
|
||||
it != externals_.end(); ++it)
|
||||
n->addExternal(*it);
|
||||
// n->finalize(am);
|
||||
return n;
|
||||
}
|
||||
|
||||
void Node::setMA(std::string name, std::vector<int> * idxs) {
|
||||
if (ma_ != NULL)
|
||||
delete ma_;
|
||||
ma_ = new MemberAccess();
|
||||
ma_->addIdBack(name,*idxs);
|
||||
}
|
||||
|
||||
void Node::setMA(std::string name) {
|
||||
if (ma_ != NULL)
|
||||
delete ma_;
|
||||
ma_ = new MemberAccess(name);
|
||||
// ma_->addIdBack(name);
|
||||
}
|
||||
|
||||
void Node::setMA(MemberAccess* ma) {
|
||||
if (ma_ != NULL)
|
||||
delete ma_;
|
||||
ma_ = ma;
|
||||
}
|
||||
|
||||
|
||||
void Node::setParent(Node *n) {
|
||||
parent_ = n;
|
||||
}
|
||||
|
||||
const Node * Node::getParent() const{
|
||||
return parent_;
|
||||
}
|
||||
|
||||
std::vector<const Node*>* Node::getPath() const {
|
||||
if(parent_ == NULL)
|
||||
return new std::vector<const Node*>();
|
||||
auto ret = parent_->getPath();
|
||||
ret->push_back(parent_);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string Node::getFullName() const {
|
||||
if(parent_ == NULL)
|
||||
return this->getMA()->toString();
|
||||
std::ostringstream oss;
|
||||
oss << parent_->getFullName()
|
||||
<< "."
|
||||
<< this->getMA()->toString();
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
void Node::addAttribute(const std::string a) {
|
||||
attributes_.push_back(std::string(a));
|
||||
}
|
||||
|
||||
void Node::addAttributes(const std::vector<std::string>* va) {
|
||||
for (std::vector<std::string>::const_iterator si = va->begin(); si != va->end(); ++si) {
|
||||
addAttribute(*si);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Node::addParam(Parameter* p) {
|
||||
params_.push_back(p);
|
||||
}
|
||||
|
||||
void Node::addParams(std::vector<Parameter*>* p) {
|
||||
for (std::vector<Parameter*>::iterator pit = p->begin();
|
||||
pit != p->end(); ++pit)
|
||||
addParam(*pit);
|
||||
}
|
||||
|
||||
|
||||
void Node::addVariable(Variable* v) {
|
||||
v->setNode(this);
|
||||
EnumDomain * ed = dynamic_cast<EnumDomain*>(v->getDomain());
|
||||
if (ed != NULL) {
|
||||
const std::vector<std::string> * sed = ed->getSymbols();
|
||||
for (std::vector<std::string>::const_iterator i = sed->begin(); i!= sed->end(); ++i)
|
||||
symbolCache_.insert(*i);
|
||||
}
|
||||
|
||||
std::vector<Variable*> *vars = v->flattenDomain();
|
||||
for (std::vector<Variable*>::iterator vi = vars->begin(); vi != vars->end(); ++vi)
|
||||
// vars_.push_back(*vi);
|
||||
if (v->isState())
|
||||
stateVars_[(*vi)->getMA()->toString()] = *vi;
|
||||
else
|
||||
flowVars_[(*vi)->getMA()->toString()] = *vi;
|
||||
delete(vars);
|
||||
}
|
||||
|
||||
void Node::addVariables(std::vector<Variable*>* v) {
|
||||
for (std::vector<Variable*>::iterator vit = v->begin();
|
||||
vit != v->end(); ++vit)
|
||||
addVariable(*vit);
|
||||
}
|
||||
|
||||
|
||||
void Node::addEvent(Event* e) {
|
||||
e->setNode(this);
|
||||
// events_.push_back(e);
|
||||
events_[e->getMA()->toString()] = e;
|
||||
}
|
||||
|
||||
void Node::addEvents(std::vector<Event*>* e) {
|
||||
for (std::vector<Event*>::iterator eit = e->begin();
|
||||
eit != e->end(); ++eit)
|
||||
addEvent(*eit);
|
||||
}
|
||||
|
||||
|
||||
void Node::addTransition(Transition* t) {
|
||||
t->setNode(this);
|
||||
trans_.push_back(t);
|
||||
}
|
||||
|
||||
void Node::addTransitions(std::vector<Transition*>* t) {
|
||||
for (std::vector<Transition*>::iterator tit = t->begin();
|
||||
tit != t->end(); ++tit)
|
||||
addTransition(*tit);
|
||||
}
|
||||
|
||||
|
||||
void Node::addAssertion(Assertion *a) {
|
||||
a->setNode(this);
|
||||
asserts_.push_back(a);
|
||||
}
|
||||
|
||||
void Node::addAssertions(std::vector<Assertion*> *a) {
|
||||
for (std::vector<Assertion*>::iterator ait = a->begin();
|
||||
ait != a->end(); ++ait)
|
||||
addAssertion(*ait);
|
||||
}
|
||||
|
||||
|
||||
void Node::addSubNode(Node* n) {
|
||||
n->setParent(this);
|
||||
subNodes_[n->getMA()->toString()] = n;
|
||||
//subNodes_.push_back(n);
|
||||
}
|
||||
|
||||
void Node::addSubNodes(std::vector<Node*>* n) {
|
||||
for (std::vector<Node*>::iterator nit = n->begin();
|
||||
nit != n->end(); ++nit)
|
||||
addSubNode(*nit);
|
||||
}
|
||||
|
||||
|
||||
// void Node::addSubNode(Node* n, std::vector<int> *tab) {
|
||||
// if (tab == NULL)
|
||||
// subNodes_[n] = new std::vector<int>();
|
||||
// else
|
||||
// subNodes_[n] = new std::vector<int>(*tab);
|
||||
// }
|
||||
|
||||
// void Node::addSubNodes(std::vector<Node*>* n, std::vector<std::vector<int>*> *tab) {
|
||||
// std::vector<std::vector<int> * >::iterator tabit = tab->begin();
|
||||
// for (std::vector<Node*>::iterator nit = n->begin() ;
|
||||
// nit != n->end(); ++nit, ++tabit)
|
||||
// addSubNode(*nit, *tabit);
|
||||
// }
|
||||
|
||||
|
||||
void Node::addInit(Assignment* i) {
|
||||
Variable* var = findStateVariableByName(i->getMA());
|
||||
if(var == NULL) {
|
||||
std::cerr << "\nInit failed, variable not found : "
|
||||
<< i->getMA()->toString()
|
||||
<< std::endl;
|
||||
} else {
|
||||
var->setInit(i);
|
||||
i->setNode(this);
|
||||
inits_.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
void Node::addInits(std::vector<Assignment*>* i) {
|
||||
for (std::vector<Assignment*>::iterator iit = i->begin();
|
||||
iit != i->end(); ++iit)
|
||||
addInit(*iit);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Node::addParamsSet(Assignment* p) {
|
||||
paramSets_.push_back(p);
|
||||
}
|
||||
|
||||
void Node::addParamsSets(std::vector<Assignment*>* p) {
|
||||
for (std::vector<Assignment*>::iterator pit = p->begin();
|
||||
pit != p->end(); ++pit)
|
||||
addParamsSet(*pit);
|
||||
}
|
||||
|
||||
|
||||
void Node::addExternal(std::string e) {
|
||||
externals_.push_back(e);
|
||||
}
|
||||
|
||||
void Node::addExternals(std::vector<std::string>* e) {
|
||||
for (std::vector<std::string>::iterator eit = e->begin();
|
||||
eit != e->end(); ++eit)
|
||||
addExternal(*eit);
|
||||
}
|
||||
|
||||
void Node::addSync(Synchronisation* s) {
|
||||
s->setNode(this);
|
||||
syncs_.push_back(s);
|
||||
}
|
||||
|
||||
void Node::addSyncs(std::vector<Synchronisation*> *s) {
|
||||
for (std::vector<Synchronisation*>::iterator sit = s->begin();
|
||||
sit != s->end(); ++sit)
|
||||
addSync(*sit);
|
||||
}
|
||||
|
||||
void Node::addEventLaw(EventLaw* el) {
|
||||
Event * ev = findEventByName(el->getMA());
|
||||
el->setNode(this);
|
||||
if (ev != NULL)
|
||||
ev->setLaw(el);
|
||||
}
|
||||
|
||||
void Node::addEventLaws(std::vector<EventLaw*>* e) {
|
||||
for (std::vector<EventLaw*>::iterator eli = e->begin();
|
||||
eli != e->end(); ++eli)
|
||||
addEventLaw(*eli);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Node::hasName(std::string n) {
|
||||
MemberAccess * ma = new MemberAccess(n);
|
||||
|
||||
if (ma_->equals(ma)) {
|
||||
delete(ma);
|
||||
return true;
|
||||
} else {
|
||||
delete(ma);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Event * Node::findEventByName(const MemberAccess * eName) const {
|
||||
const MemberAccess * suffix = NULL;
|
||||
if (eName->isGlobal()) {
|
||||
suffix = eName->buildSuffix(ma_);
|
||||
if (suffix == NULL)
|
||||
return NULL;
|
||||
} else {
|
||||
suffix = eName;
|
||||
}
|
||||
|
||||
std::map<std::string, Event*, ltstr>::const_iterator i = events_.find(suffix->toString());
|
||||
if (i != events_.end())
|
||||
return i->second;
|
||||
|
||||
|
||||
|
||||
std::string head = suffix->headToString();
|
||||
std::map<std::string, Node*, ltstr>::const_iterator j = subNodes_.find(head);
|
||||
if (j == subNodes_.end())
|
||||
return NULL;
|
||||
MemberAccess * ma = suffix->buildSuffix(j->second->getMA());
|
||||
Event * e = j->second->findEventByName(ma);
|
||||
delete ma;
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
Variable * Node::findStateVariableByName(const std::string& s) const {
|
||||
MemberAccess ma(s);
|
||||
Variable * v = findStateVariableByName(&ma);
|
||||
return v;
|
||||
}
|
||||
|
||||
Variable * Node::findFlowVariableByName(const std::string& s) const {
|
||||
MemberAccess ma(s);
|
||||
Variable * v = findFlowVariableByName(&ma);
|
||||
return v;
|
||||
}
|
||||
|
||||
Variable * Node::findVariableByName(const std::string& s) const {
|
||||
MemberAccess ma(s);
|
||||
Variable * v = findVariableByName(&ma);
|
||||
return v;
|
||||
}
|
||||
|
||||
bool Node::isSymbol(const MemberAccess *ma) const {
|
||||
std::set<std::string>::iterator si = symbolCache_.find(ma->toString());
|
||||
if (si != symbolCache_.end())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Node::isSymbol(std::string s) const {
|
||||
std::set<std::string>::iterator si = symbolCache_.find(s);
|
||||
if (si != symbolCache_.end())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
Variable * Node::findStateVariableByName(const MemberAccess * eName) const {
|
||||
|
||||
|
||||
const MemberAccess * suffix = NULL;
|
||||
if (eName->isGlobal()) {
|
||||
suffix = eName->buildSuffix(ma_);
|
||||
if (suffix == NULL)
|
||||
return NULL;
|
||||
} else
|
||||
suffix = eName;
|
||||
|
||||
|
||||
std::map<std::string, Variable*, ltstr>::const_iterator i = stateVars_.find(suffix->toString());
|
||||
if (i != stateVars_.end())
|
||||
return i->second;
|
||||
|
||||
if (stateVarsCache_.size() != 0) {
|
||||
i = stateVarsCache_.find(suffix->toString());
|
||||
if (i != stateVarsCache_.end())
|
||||
return i->second;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::map<std::string, Node*, ltstr>::const_iterator j = subNodes_.find(suffix->headToString());
|
||||
if (j == subNodes_.end()) {
|
||||
return NULL;
|
||||
}
|
||||
MemberAccess * ma = suffix->buildSuffix(j->second->getMA());
|
||||
Variable * v = j->second->findStateVariableByName(ma);
|
||||
delete ma;
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Variable * Node::findFlowVariableByName(const MemberAccess * eName) const {
|
||||
|
||||
bool delSuffix = false;
|
||||
|
||||
const MemberAccess * suffix = NULL;
|
||||
if (eName->isGlobal()) {
|
||||
suffix = eName->buildSuffix(ma_);
|
||||
delSuffix = true;
|
||||
if (suffix == NULL)
|
||||
return NULL;
|
||||
} else
|
||||
suffix = eName;
|
||||
|
||||
|
||||
std::map<std::string, Variable*, ltstr>::const_iterator i = flowVars_.find(suffix->toString());
|
||||
if (i != flowVars_.end()) {
|
||||
if (delSuffix)
|
||||
delete suffix;
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
if (flowVarsCache_.size() != 0) {
|
||||
i = flowVarsCache_.find(suffix->toString());
|
||||
if (i != flowVarsCache_.end()) {
|
||||
if (delSuffix)
|
||||
delete suffix;
|
||||
return i->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
std::map<std::string, Node*, ltstr>::const_iterator j = subNodes_.find(suffix->headToString());
|
||||
if (j == subNodes_.end()) {
|
||||
if (delSuffix)
|
||||
delete suffix;
|
||||
return NULL;
|
||||
}
|
||||
MemberAccess * ma = suffix->buildSuffix(j->second->getMA());
|
||||
Variable * v = j->second->findFlowVariableByName(ma);
|
||||
if (delSuffix)
|
||||
delete suffix;
|
||||
delete ma;
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Variable * Node::findVariableByName(const MemberAccess * eName) const {
|
||||
Variable *v = findFlowVariableByName(eName);
|
||||
if (v == NULL)
|
||||
return findStateVariableByName(eName);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
// const std::vector<Variable*>* Node::getVariables() {
|
||||
const std::map<std::string, Variable*, Node::ltstr> *
|
||||
Node::getStateVariables() const {
|
||||
return &stateVars_;
|
||||
}
|
||||
|
||||
|
||||
const std::map<std::string, Variable*, Node::ltstr> *
|
||||
Node::getFlowVariables() const {
|
||||
return &flowVars_;
|
||||
}
|
||||
|
||||
|
||||
// const std::vector<Event*>* Node::getEvents() {
|
||||
const std::map<std::string, Event*, Node::ltstr> *
|
||||
Node::getEvents() const {
|
||||
return &events_;
|
||||
}
|
||||
|
||||
const std::vector<Synchronisation*>* Node::getSyncs() const {
|
||||
return &syncs_;
|
||||
}
|
||||
const std::vector<Assertion*> *Node::getAsserts() const {
|
||||
return &asserts_;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<Transition*>* Node::getTransitions() const {
|
||||
return &trans_;
|
||||
}
|
||||
|
||||
const std::map<std::string,Node*,Node::ltstr>* Node::getSubNodes() const {
|
||||
return &subNodes_;
|
||||
}
|
||||
|
||||
const MemberAccess * Node::getMA() const {
|
||||
return ma_;
|
||||
}
|
||||
|
||||
|
||||
void Node::buildEventsByPrio() {
|
||||
if (events_.size() == 0)
|
||||
return;
|
||||
std::vector<Event*> ev;
|
||||
if (events_by_prio_ == NULL)
|
||||
events_by_prio_ = new std::vector<std::vector<Event*>* >();
|
||||
for (std::map<std::string, Event*,ltstr>::iterator i = events_.begin(); i!=events_.end(); ++i)
|
||||
ev.push_back(i->second);
|
||||
// ev.insert(ev.begin(), events_.begin(), events_.end());
|
||||
|
||||
std::vector<Event*> *p0 = new std::vector<Event*>();
|
||||
std::vector<Event*>::iterator i = ev.begin();
|
||||
|
||||
while (i!= ev.end()) {
|
||||
if ((*i)->getUppers()->size() == 0) {
|
||||
p0->push_back(*i);
|
||||
i = ev.erase(i);
|
||||
} else
|
||||
++i;
|
||||
}
|
||||
events_by_prio_->push_back(p0);
|
||||
|
||||
while (ev.size() > 0) {
|
||||
std::vector<Event*> *pi = new std::vector<Event*>();
|
||||
i = ev.begin();
|
||||
while (i!=ev.end()) {
|
||||
if (notInEv((*i)->getUppers(),&events_)) {
|
||||
pi->push_back(*i);
|
||||
i = ev.erase(i);
|
||||
} else
|
||||
++i;
|
||||
}
|
||||
events_by_prio_->push_back(pi);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// bool Node::notInEv(std::set<Event*>const *up, std::vector<Event*> * ev) {
|
||||
bool Node::notInEv(std::set<Event*>const *up, std::map<std::string, Event*, Node::ltstr> * ev) {
|
||||
for (std::set<Event*>::iterator upi = up->begin(); upi != up->end(); ++upi) {
|
||||
// for (std::vector<Event*>::iterator evi = ev->begin(); evi != ev->end(); evi++)
|
||||
for (std::map<std::string, Event*, Node::ltstr>::iterator evi = ev->begin(); evi != ev->end(); evi++)
|
||||
if (*upi == evi->second)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Node::matchEventsInTransitions() {
|
||||
for (std::vector<Transition*>::iterator i = trans_.begin(); i!= trans_.end(); ++i) {
|
||||
(*i)->matchEvents();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Node::matchEventsInSynchros() {
|
||||
for (std::vector<Synchronisation*>::iterator i = syncs_.begin(); i!= syncs_.end(); ++i) {
|
||||
(*i)->matchEvents();
|
||||
}
|
||||
}
|
||||
|
||||
// void Node::matchVariablesInInits() {
|
||||
// for (std::vector<Variable*>::iterator i = vars_.begin(); i!= vars_.end(); ++i) {
|
||||
// std::cerr << "var: " << *((*i)->getMA()->toString()) << std::endl;
|
||||
// }
|
||||
// for (std::vector<Assignment*>::iterator i = inits_.begin(); i!= inits_.end(); ++i) {
|
||||
// (*i)->matchVariable(true);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// To each variable is added the vector of the asserts that update its value
|
||||
void Node::matchVariablesInAsserts(const AltaricaModel* am) {
|
||||
for (std::vector<Assertion*>::iterator i = asserts_.begin(); i!= asserts_.end(); ++i) {
|
||||
std::vector<Variable*> * fv = (*i)->infoVars(am, true, true);
|
||||
for (std::vector<Variable*>::iterator j = fv->begin(); j!= fv->end(); ++j) {
|
||||
std::cerr << "adding one assertion for node "<< toString() << " var: " << (*j)->getFullName() <<std::endl;
|
||||
(*j)->addAssert(*i);
|
||||
}
|
||||
delete fv;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Node::toString(bool withTypes) const {
|
||||
std::string s;
|
||||
if (parent_ != NULL)
|
||||
s += parent_->toString(withTypes) + ".";
|
||||
if (typeName_ != NULL && withTypes)
|
||||
s+= "(";
|
||||
s+= ma_->toString();
|
||||
if (typeName_!=NULL && withTypes)
|
||||
s+= ":" + typeName_->toString() + ")";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string Node::toFiacre() const {
|
||||
std::string s;
|
||||
if (parent_ != NULL)
|
||||
s += parent_->toFiacre() + "_";
|
||||
s+= ma_->toString();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string Node::printTrans() const {
|
||||
std::string s;
|
||||
s += "TRANSITIONS:\n";
|
||||
for (std::vector<Transition*>::const_iterator i = trans_.begin(); i!= trans_.end(); ++i) {
|
||||
s+= (*i)->toString() + "\n";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
void Node::finalize(const AltaricaModel *am) {
|
||||
buildEventsByPrio();
|
||||
matchEventsInTransitions();
|
||||
matchEventsInSynchros();
|
||||
// matchVariablesInInits();
|
||||
matchVariablesInAsserts(am);
|
||||
|
||||
}
|
||||
|
||||
void Node::compactSimpleAsserts(const AltaricaModel *am) {
|
||||
for (std::vector<Assertion*>::iterator i = asserts_.begin(); i!=asserts_.end();++i) {
|
||||
std::pair<Variable*,Variable*> * aff = (*i)->isSimpleAffect(am);
|
||||
if (aff != NULL) {
|
||||
// ++i;
|
||||
// else {
|
||||
// in this case, this assert is aff->first = aff->second
|
||||
// both being flow vars
|
||||
// std::cerr << "REMOVING ASSERTION:::: " <<aff->first->toString() << " = " << aff->second->toString()<< std::endl;
|
||||
aff->first->removeAssert(*i);
|
||||
// i = asserts_.erase(i);
|
||||
// ++i;
|
||||
std::vector<Node *> *n = (std::vector<Node *>*)aff->first->getNodes();
|
||||
aff->second->mergeVariable(aff->first);
|
||||
// Node * n = (Node*)aff->first->getNode();
|
||||
for (std::vector<Node*>::iterator j = n->begin(); j!=n->end(); ++j)
|
||||
(*j)->aliasVar(aff->first,aff->second);
|
||||
delete n;
|
||||
delete(aff->first);
|
||||
delete aff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Node::aliasVar(Variable* toRemove, Variable *mergedVar) {
|
||||
//std::vector<Variable*>::iterator i;
|
||||
std::map<std::string, Variable*, ltstr>::iterator i;
|
||||
|
||||
for (i = flowVars_.begin(); i!=flowVars_.end() && i->second != toRemove; ++i) ;
|
||||
if (i == flowVars_.end())
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("unable to find var toremove!!!!!!!")));
|
||||
// *i = mergedVar;
|
||||
flowVars_[i->first] = mergedVar;
|
||||
// std::cerr << "AFTER: node var of node:" << this->toString() << std::endl;
|
||||
// for (std::vector<Variable*>::iterator j = vars_.begin(); j!=vars_.end(); ++j) {
|
||||
// std::cerr<< (*j)->toString() << std::endl;
|
||||
// }
|
||||
}
|
||||
|
||||
void Node::deleteExprs() {
|
||||
for (std::vector<Transition*>::iterator i = trans_.begin(); i!= trans_.end(); ++i)
|
||||
(*i)->deleteExprs();
|
||||
for (std::vector<Assertion*>::iterator i = asserts_.begin(); i!= asserts_.end(); ++i)
|
||||
(*i)->deleteExpr();
|
||||
for (std::vector<Assignment*>::iterator i = inits_.begin(); i!= inits_.end(); ++i)
|
||||
(*i)->deleteExprs();
|
||||
for (std::vector<Assignment*>::iterator i = paramSets_.begin(); i!= paramSets_.end(); ++i)
|
||||
(*i)->deleteExprs();
|
||||
for (std::map<std::string, Event*, ltstr>::iterator i = events_.begin(); i!= events_.end(); ++i)
|
||||
(*i).second->deleteExprs();
|
||||
}
|
||||
|
||||
Node::~Node() {
|
||||
// std::cerr << "\ndeleting node " << ma_->toString() << std::endl;
|
||||
for (std::map<std::string, Node*, ltstr>::iterator i = subNodes_.begin();
|
||||
i!= subNodes_.end(); ++i)
|
||||
delete i->second;
|
||||
delete ma_;
|
||||
delete typeName_;
|
||||
|
||||
|
||||
|
||||
for (std::map<std::string,Variable*,ltstr*>::iterator i = flowVars_.begin(); i!= flowVars_.end(); ++i) {
|
||||
if (i->second->removeOwner(this)) {
|
||||
delete i->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (std::map<std::string,Variable*,ltstr>::iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
delete i->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// for (std::vector<Event*>::iterator i = events_.begin(); i!= events_.end(); ++i)
|
||||
// delete *i;
|
||||
for (std::map<std::string,Event*,ltstr>::iterator i = events_.begin(); i!= events_.end(); ++i)
|
||||
delete i->second;
|
||||
for (std::vector<Transition*>::iterator i = trans_.begin(); i!= trans_.end(); ++i)
|
||||
delete *i;
|
||||
for (std::vector<Assertion*>::iterator i = asserts_.begin(); i!= asserts_.end(); ++i)
|
||||
delete *i;
|
||||
for (std::vector<Assignment*>::iterator i = inits_.begin();
|
||||
i!= inits_.end(); ++i)
|
||||
delete *i;
|
||||
for (std::vector<Assignment*>::iterator i = paramSets_.begin();
|
||||
i!= paramSets_.end(); ++i)
|
||||
delete *i;
|
||||
|
||||
for (std::vector<Synchronisation*>::iterator i = syncs_.begin();
|
||||
i!= syncs_.end(); ++i)
|
||||
delete *i;
|
||||
|
||||
attributes_.clear();
|
||||
externals_.clear();
|
||||
for (std::vector<Parameter*>::iterator i = params_.begin();
|
||||
i!= params_.end(); ++i)
|
||||
delete *i;
|
||||
|
||||
if (events_by_prio_ != NULL)
|
||||
for (std::vector<std::vector<Event*>* >::iterator i = events_by_prio_->begin();
|
||||
i!= events_by_prio_->end(); ++i)
|
||||
delete (*i);
|
||||
|
||||
delete(events_by_prio_);
|
||||
}
|
||||
|
||||
void Node::addFlowVarToCache(Variable * v, MemberAccess *subMA, std::string vName) const {
|
||||
std::string s = subMA->toString() + "." + vName;
|
||||
// std::cout << "adding var " << s << " to node " << ma_->toString() << std::endl;
|
||||
flowVarsCache_[s] = v;
|
||||
if (parent_ != NULL) {
|
||||
subMA->addMemberAccessFront(ma_);
|
||||
parent_->addFlowVarToCache(v,subMA,vName);
|
||||
}
|
||||
}
|
||||
|
||||
void Node::addStateVarToCache(Variable * v, MemberAccess *subMA, std::string vName) const {
|
||||
std::string s = subMA->toString() + "." + vName;
|
||||
// std::cout << "adding var " << s << " to node " << ma_->toString() << std::endl;
|
||||
stateVarsCache_[s] = v;
|
||||
if (parent_ != NULL) {
|
||||
subMA->addMemberAccessFront(ma_);
|
||||
parent_->addStateVarToCache(v,subMA,vName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Node::populateVarCache() const {
|
||||
for (std::map<std::string, Variable*, ltstr>::const_iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
if (parent_ != NULL) {
|
||||
MemberAccess *ma = ma_->clone();
|
||||
parent_->addStateVarToCache(i->second, ma, i->first);
|
||||
delete ma;
|
||||
}
|
||||
const std::vector<std::pair<const Node*, const MemberAccess*>*> * aliases =
|
||||
i->second->getAliases();
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::const_iterator j = aliases->begin();
|
||||
j!= aliases->end(); ++j) {
|
||||
MemberAccess * ma = (*j)->first->getMA()->clone();
|
||||
const Node * p = (*j)->first->getParent();
|
||||
p->addStateVarToCache(i->second,ma,(*j)->second->toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (std::map<std::string, Variable*, ltstr>::const_iterator i = flowVars_.begin(); i!= flowVars_.end(); ++i) {
|
||||
if (parent_ != NULL) {
|
||||
MemberAccess *ma = ma_->clone();
|
||||
parent_->addFlowVarToCache(i->second, ma, i->first);
|
||||
delete ma;
|
||||
}
|
||||
const std::vector<std::pair<const Node*, const MemberAccess*>*> * aliases =
|
||||
i->second->getAliases();
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::const_iterator j = aliases->begin();
|
||||
j!= aliases->end(); ++j) {
|
||||
MemberAccess * ma = (*j)->first->getMA()->clone();
|
||||
const Node * p = (*j)->first->getParent();
|
||||
if (p!=NULL)
|
||||
p->addFlowVarToCache(i->second,ma,(*j)->second->toString());
|
||||
delete ma;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
206
src/grammars/altarica/Node.hh
Normal file
206
src/grammars/altarica/Node.hh
Normal file
@@ -0,0 +1,206 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_NODE_H_
|
||||
#define ALTA_NODE_H_
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Parameter;
|
||||
class Variable;
|
||||
class Event;
|
||||
class EventLaw;
|
||||
class Transition;
|
||||
class Expression;
|
||||
class Assignment;
|
||||
class Synchronisation;
|
||||
class Value;
|
||||
class Assertion;
|
||||
class MemberAccess;
|
||||
class AltaricaModel;
|
||||
|
||||
class Node {
|
||||
|
||||
public :
|
||||
struct ltstr {
|
||||
bool operator() (const std::string s1, const std::string s2) const {
|
||||
return s1.compare(s2) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//!
|
||||
// std::string * name_;
|
||||
Node * parent_;
|
||||
MemberAccess* ma_;
|
||||
MemberAccess* typeName_;
|
||||
std::vector<std::string> attributes_;
|
||||
std::vector<Parameter*> params_;
|
||||
|
||||
// std::vector<Variable*> vars_;
|
||||
std::map<std::string,Variable*, ltstr> stateVars_;
|
||||
std::map<std::string,Variable*, ltstr> flowVars_;
|
||||
mutable std::map<std::string,Variable*, ltstr> stateVarsCache_;
|
||||
mutable std::map<std::string,Variable*, ltstr> flowVarsCache_;
|
||||
mutable std::set<std::string> symbolCache_;
|
||||
|
||||
// std::vector<Event*> events_;
|
||||
std::map<std::string, Event*, ltstr> events_;
|
||||
|
||||
std::vector<Transition*> trans_;
|
||||
std::vector<Assertion*> asserts_;
|
||||
//std::vector<Expression<OpenValue>*> asserts_;
|
||||
|
||||
std::map<std::string, Node*, ltstr> subNodes_;
|
||||
// std::vector<Node*> subNodes_;
|
||||
std::vector<Synchronisation*> syncs_;
|
||||
std::vector<Assignment*> inits_;
|
||||
std::vector<Assignment*> paramSets_;
|
||||
std::vector<std::string> externals_;
|
||||
|
||||
std::vector<std::vector<Event*>* > *events_by_prio_;
|
||||
|
||||
// bool notInEv(std::set<Event*>const *up, std::vector<Event*> * ev);
|
||||
bool notInEv(std::set<Event*>const *up, std::map<std::string,Event*,ltstr> * ev);
|
||||
void buildEventsByPrio();
|
||||
void matchEventsInTransitions();
|
||||
void matchEventsInSynchros();
|
||||
// void matchVariablesInInits();
|
||||
void matchVariablesInAsserts(const AltaricaModel *am);
|
||||
|
||||
unsigned int index_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//!
|
||||
Node();
|
||||
~Node();
|
||||
|
||||
// void setName(std::string * name);
|
||||
void setMA(std::string name, std::vector<int> * idxs);
|
||||
void setMA(std::string name);
|
||||
void setMA(MemberAccess* ma);
|
||||
|
||||
void setTypeName(MemberAccess *ma) {typeName_ = ma;}
|
||||
const MemberAccess * getTypeName() const {return typeName_;}
|
||||
|
||||
void setParent(Node *n);
|
||||
const Node * getParent() const;
|
||||
std::vector<const Node*>* getPath() const;
|
||||
std::string getFullName() const;
|
||||
|
||||
void addAttribute(const std::string a);
|
||||
void addAttributes(const std::vector<std::string>* va);
|
||||
|
||||
Node* clone() const;
|
||||
|
||||
void addParam(Parameter* p);
|
||||
void addParams(std::vector<Parameter*>* p);
|
||||
void addVariable(Variable* v);
|
||||
void addVariables(std::vector<Variable*>* v);
|
||||
void addEvent(Event* e);
|
||||
void addEvents(std::vector<Event*>* e);
|
||||
void addTransition(Transition* t);
|
||||
void addTransitions(std::vector<Transition*>* t);
|
||||
void addAssertion(Assertion *e);
|
||||
void addAssertions(std::vector<Assertion*> *e);
|
||||
void addSubNode(Node* n);
|
||||
void addSubNodes(std::vector<Node*>* n);
|
||||
// void addSubNode(Node* n, std::vector<int> * v);
|
||||
// void addSubNodes(std::vector<Node*>* n, std::vector<std::vector<int>* > * v);
|
||||
void addSync(Synchronisation* s);
|
||||
void addSyncs(std::vector<Synchronisation*> *s);
|
||||
void addInit(Assignment* i);
|
||||
void addInits(std::vector<Assignment*>* i);
|
||||
void addParamsSet(Assignment* p);
|
||||
void addParamsSets(std::vector<Assignment*>* p);
|
||||
void addExternal(std::string e);
|
||||
void addExternals(std::vector<std::string>* e);
|
||||
void addEventLaw(EventLaw* e);
|
||||
void addEventLaws(std::vector<EventLaw*>* e);
|
||||
|
||||
|
||||
// const std::vector<Variable*> *getVariables();
|
||||
const std::map<std::string, Variable*, ltstr> * getStateVariables() const;
|
||||
const std::map<std::string, Variable*, ltstr> * getFlowVariables() const;
|
||||
const std::vector<Transition*> *getTransitions() const;
|
||||
// const std::vector<Node*> *getSubNodes();
|
||||
const std::map<std::string, Node*, ltstr> *getSubNodes() const;
|
||||
// const std::vector<Event*> *getEvents();
|
||||
const std::map<std::string, Event*, ltstr> *getEvents() const;
|
||||
const std::vector<Synchronisation*> *getSyncs() const;
|
||||
const std::vector<Assertion*> *getAsserts() const;
|
||||
const MemberAccess * getMA() const;
|
||||
|
||||
|
||||
bool hasName(std::string name);
|
||||
|
||||
Event* findEventByName(const MemberAccess* eName) const;
|
||||
Variable * findStateVariableByName(const MemberAccess * eName) const;
|
||||
Variable * findStateVariableByName(const std::string& s) const;
|
||||
Variable * findFlowVariableByName(const MemberAccess * eName) const;
|
||||
Variable * findFlowVariableByName(const std::string& s) const;
|
||||
Variable * findVariableByName(const MemberAccess * eName) const;
|
||||
Variable * findVariableByName(const std::string& s) const;
|
||||
|
||||
std::string toString(bool withTypes=false) const;
|
||||
std::string toFiacre() const ;
|
||||
std::string printTrans() const;
|
||||
|
||||
|
||||
void finalize(const AltaricaModel *am);
|
||||
|
||||
void deleteExprs();
|
||||
|
||||
void aliasVar(Variable* toRemove, Variable *mergedVar) ;
|
||||
void compactSimpleAsserts(const AltaricaModel *am);
|
||||
|
||||
void populateVarCache() const ;
|
||||
void addStateVarToCache(Variable*v, MemberAccess *subMA, std::string vName) const;
|
||||
void addFlowVarToCache(Variable*v, MemberAccess *subMA, std::string vName) const;
|
||||
bool isSymbol(const MemberAccess *ma) const;
|
||||
bool isSymbol(std::string s) const;
|
||||
|
||||
inline void setIndex(unsigned int i) { index_ = i;}
|
||||
inline unsigned int getIndex() const { return index_;}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
62
src/grammars/altarica/Parameter.cc
Normal file
62
src/grammars/altarica/Parameter.cc
Normal file
@@ -0,0 +1,62 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Parameter.hh"
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
Parameter::Parameter(std::string name) {
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
Parameter::Parameter(std::string name, Domain* d) {
|
||||
name_ = name;
|
||||
domain_ = d;
|
||||
}
|
||||
|
||||
void Parameter::setDomain(Domain *d) {
|
||||
domain_ = d;
|
||||
}
|
||||
|
||||
Domain *Parameter::getDomain() {
|
||||
return domain_;
|
||||
}
|
||||
|
||||
std::string Parameter::getName() {
|
||||
return name_;
|
||||
}
|
||||
|
||||
Parameter * Parameter::clone() {
|
||||
return new Parameter(name_, domain_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
65
src/grammars/altarica/Parameter.hh
Normal file
65
src/grammars/altarica/Parameter.hh
Normal file
@@ -0,0 +1,65 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#ifndef ALTA_PARAMETER_H_
|
||||
#define ALTA_PARAMETER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Domain;
|
||||
|
||||
class Parameter {
|
||||
|
||||
protected:
|
||||
|
||||
//!
|
||||
std::string name_;
|
||||
Domain * domain_;
|
||||
|
||||
public:
|
||||
|
||||
//!
|
||||
Parameter(std::string name);
|
||||
|
||||
Parameter(std::string name, Domain* d);
|
||||
|
||||
void setDomain(Domain *d);
|
||||
|
||||
Parameter * clone();
|
||||
|
||||
Domain * getDomain();
|
||||
|
||||
std::string getName();
|
||||
~Parameter() {};
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
276
src/grammars/altarica/Synchronisation.cc
Normal file
276
src/grammars/altarica/Synchronisation.cc
Normal file
@@ -0,0 +1,276 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Synchronisation.hh"
|
||||
#include "Node.hh"
|
||||
#include <limits.h>
|
||||
#include <iostream>
|
||||
#include "AltaricaModel.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "Event.hh"
|
||||
#include "MetaEvent.hh"
|
||||
#include <sstream>
|
||||
#include <limits>
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
Synchronisation::Synchronisation() {
|
||||
max_ = 0;
|
||||
ma_ = NULL;
|
||||
numerical_constant_ = -1;
|
||||
};
|
||||
|
||||
|
||||
Synchronisation::Synchronisation(MemberAccess *ma) {
|
||||
max_ = 0;
|
||||
ma_ = ma;
|
||||
numerical_constant_ = -1;
|
||||
};
|
||||
|
||||
void Synchronisation::addEvent(MemberAccess*e, bool optional) {
|
||||
broadcastList_.push_back(e);
|
||||
optionalBcast_.push_back(optional);
|
||||
}
|
||||
|
||||
void Synchronisation::setConstraintType(short ct) {
|
||||
constraint_type_ = ct;
|
||||
}
|
||||
|
||||
void Synchronisation::setNumConstant(int n) {
|
||||
numerical_constant_ = n;
|
||||
}
|
||||
|
||||
void Synchronisation::setMax() {
|
||||
max_ = 1;
|
||||
}
|
||||
|
||||
void Synchronisation::setMin() {
|
||||
max_ = -1;
|
||||
}
|
||||
|
||||
|
||||
Synchronisation * Synchronisation::clone() {
|
||||
Synchronisation * n;
|
||||
if (ma_ != NULL)
|
||||
n = new Synchronisation(ma_->clone());
|
||||
else
|
||||
n = new Synchronisation();
|
||||
n->setConstraintType(constraint_type_);
|
||||
n->setNumConstant(numerical_constant_);
|
||||
if (max_ == 1)
|
||||
n->setMax();
|
||||
else if (max_ == -1)
|
||||
n->setMin();
|
||||
std::vector<MemberAccess*>::iterator itma = broadcastList_.begin();
|
||||
std::vector<bool>::iterator ito = optionalBcast_.begin();
|
||||
for (; itma != broadcastList_.end(); ++itma) {
|
||||
n->addEvent((*itma)->clone(), *ito);
|
||||
++ito;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
void Synchronisation::setNode(Node * n) {
|
||||
node_ = n;
|
||||
}
|
||||
|
||||
void Synchronisation::matchEvents() {
|
||||
broadcastListOptionalEvents_.clear();
|
||||
broadcastListMandatoryEvents_.clear();
|
||||
for (unsigned int i = 0; i < broadcastList_.size(); ++i) {
|
||||
Event * e = node_->findEventByName(broadcastList_[i]);
|
||||
if(e == NULL)
|
||||
std::cerr << "\nSync failed, unknown event : "
|
||||
<< broadcastList_[i]->toString()
|
||||
<< std::endl;
|
||||
else {
|
||||
e->addSync(this);
|
||||
if (optionalBcast_[i])
|
||||
broadcastListOptionalEvents_.push_back(e);
|
||||
else
|
||||
broadcastListMandatoryEvents_.push_back(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const std::vector<Event*> * Synchronisation::getOptionalEvents() {
|
||||
if (broadcastListOptionalEvents_.size() == 0 && broadcastListMandatoryEvents_.size() ==0)
|
||||
matchEvents();
|
||||
return &broadcastListOptionalEvents_;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<Event*> * Synchronisation::getMandatoryEvents() {
|
||||
if (broadcastListOptionalEvents_.size() == 0 && broadcastListMandatoryEvents_.size() ==0)
|
||||
matchEvents();
|
||||
return &broadcastListMandatoryEvents_;
|
||||
}
|
||||
|
||||
std::string Synchronisation::toString() const {
|
||||
std::stringstream ss;
|
||||
ss << "blist: ";
|
||||
for (std::vector<MemberAccess*>::const_iterator i = broadcastList_.begin(); i!= broadcastList_.end(); ++i) {
|
||||
ss << (*i)->toString() << ",";
|
||||
}
|
||||
ss << "\n mandatoryEv: ";
|
||||
for (std::vector<Event*>::const_iterator i = broadcastListMandatoryEvents_.begin(); i!= broadcastListMandatoryEvents_.end(); ++i) {
|
||||
ss << (*i)->toString() << ",";
|
||||
}
|
||||
ss << "\n optionalEv: ";
|
||||
for (std::vector<Event*>::const_iterator i = broadcastListOptionalEvents_.begin(); i!= broadcastListOptionalEvents_.end(); ++i) {
|
||||
ss << (*i)->toString() << ",";
|
||||
}
|
||||
return ss.str();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<MetaEvent*> * Synchronisation::buildSynchronisedEvents(const AltaricaModel *am, AltaricaState *s) {
|
||||
// if (ma_ != NULL)
|
||||
// std::cerr << "building sync events for sync "<< *(ma_->toString()) << " of node: " << *(node_->getMA()->toString()) << std::endl;
|
||||
// else
|
||||
// std::cerr << "building sync events for node: " << *(node_->getMA()->toString()) << std::endl;
|
||||
|
||||
std::vector<MetaEvent*> * ret = NULL;
|
||||
|
||||
for (std::vector<Event*>::iterator j = broadcastListMandatoryEvents_.begin();
|
||||
j!=broadcastListMandatoryEvents_.end() ; ++j)
|
||||
if (!(*j)->isEnabled(am, s)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = new std::vector<MetaEvent*>();
|
||||
|
||||
MetaEvent * me = new MetaEvent();
|
||||
for (std::vector<Event*>::iterator j = broadcastListMandatoryEvents_.begin(); j!=broadcastListMandatoryEvents_.end(); ++j)
|
||||
me->push_back(*j);
|
||||
ret->push_back(me);
|
||||
|
||||
for ( std::vector<Event*>::iterator i = broadcastListOptionalEvents_.begin();
|
||||
i!= broadcastListOptionalEvents_.end(); ++i) {
|
||||
if ((*i)->isEnabled(am, s)) {
|
||||
int nvec = ret->size();
|
||||
std::vector<MetaEvent*> *temp = new std::vector<MetaEvent*>();
|
||||
for (std::vector<MetaEvent*>::iterator k = ret->begin(); k!=ret->end(); ++k)
|
||||
temp->push_back((*k)->clone());
|
||||
ret->insert(ret->begin(), temp->begin(), temp->end());
|
||||
delete temp;
|
||||
for (int j = 0; j<nvec; ++j) {
|
||||
(*ret)[j]->push_back(*i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now apply constraints
|
||||
|
||||
std::vector<MetaEvent*>::iterator iret;
|
||||
if (numerical_constant_ != -1) {
|
||||
iret = ret->begin();
|
||||
while (iret != ret->end()) {
|
||||
int s = (*iret)->size();
|
||||
bool removed = false;
|
||||
switch (constraint_type_) {
|
||||
case -2: // INF
|
||||
if (s >= numerical_constant_) {
|
||||
iret = ret->erase(iret);
|
||||
removed = true;
|
||||
}
|
||||
break;
|
||||
case -1: // INFEQ
|
||||
if (s > numerical_constant_) {
|
||||
iret = ret->erase(iret);
|
||||
removed = true;
|
||||
}
|
||||
break;
|
||||
case 0: // EQ
|
||||
if (s != numerical_constant_) {
|
||||
iret = ret->erase(iret);
|
||||
removed = true;
|
||||
}
|
||||
break;
|
||||
case 1: // SUPEQ
|
||||
if (s < numerical_constant_) {
|
||||
iret = ret->erase(iret);
|
||||
removed = true;
|
||||
}
|
||||
break;
|
||||
case 2: // SUP
|
||||
if (s <= numerical_constant_) {
|
||||
iret = ret->erase(iret);
|
||||
removed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!removed)
|
||||
++iret;
|
||||
}
|
||||
}
|
||||
|
||||
// if min then select only minimal size among remaining
|
||||
if (max_ == -1) {
|
||||
unsigned int min_size = UINT_MAX;
|
||||
for (iret = ret->begin(); iret != ret->end(); ++iret) {
|
||||
if ((*iret)->size()<min_size)
|
||||
min_size = (*iret)->size();
|
||||
}
|
||||
iret = ret->begin();
|
||||
while (iret != ret->end()) {
|
||||
if ((*iret)->size() != min_size) {
|
||||
iret = ret->erase(iret);
|
||||
} else
|
||||
++iret;
|
||||
}
|
||||
} else if (max_ == 1) { // if max select only max size among remaining
|
||||
unsigned int max_size = std::numeric_limits<unsigned int>::min();
|
||||
for (iret = ret->begin(); iret != ret->end(); ++iret) {
|
||||
if ((*iret)->size()>max_size)
|
||||
max_size = (*iret)->size();
|
||||
}
|
||||
iret = ret->begin();
|
||||
while (iret != ret->end()) {
|
||||
if ((*iret)->size() != max_size) {
|
||||
iret = ret->erase(iret);
|
||||
} else
|
||||
++iret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// finally send stuff
|
||||
return ret;
|
||||
}
|
||||
|
||||
Synchronisation::~Synchronisation() {
|
||||
for (std::vector<MemberAccess*>::iterator i = broadcastList_.begin();
|
||||
i!= broadcastList_.end(); ++i)
|
||||
delete *i;
|
||||
delete ma_;
|
||||
}
|
||||
}
|
||||
}
|
||||
88
src/grammars/altarica/Synchronisation.hh
Normal file
88
src/grammars/altarica/Synchronisation.hh
Normal file
@@ -0,0 +1,88 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_SYNC_H_
|
||||
#define ALTA_SYNC_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Node;
|
||||
class MetaEvent;
|
||||
class Event;
|
||||
class MemberAccess;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
|
||||
class Synchronisation {
|
||||
protected:
|
||||
std::vector<MemberAccess*> broadcastList_;
|
||||
std::vector<Event*> broadcastListMandatoryEvents_;
|
||||
std::vector<Event*> broadcastListOptionalEvents_;
|
||||
std::vector<bool> optionalBcast_;
|
||||
short constraint_type_;
|
||||
int numerical_constant_;
|
||||
short max_;
|
||||
MemberAccess *ma_;
|
||||
Node * node_;
|
||||
public:
|
||||
Synchronisation();
|
||||
~Synchronisation();
|
||||
Synchronisation(MemberAccess *ma);
|
||||
|
||||
void addEvent(MemberAccess* e, bool optional);
|
||||
void setConstraintType(short ct);
|
||||
void setNumConstant(int n);
|
||||
void setMax();
|
||||
void setMin();
|
||||
|
||||
void setNode(Node *n);
|
||||
|
||||
Synchronisation* clone();
|
||||
|
||||
void matchEvents();
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
bool syncEvent(Event* e);
|
||||
|
||||
const std::vector<Event*> * getOptionalEvents();
|
||||
const std::vector<Event*> * getMandatoryEvents();
|
||||
|
||||
std::vector<MetaEvent*> * buildSynchronisedEvents(const AltaricaModel *am,
|
||||
AltaricaState *s);
|
||||
|
||||
const MemberAccess* getMA() const { return ma_; }
|
||||
short getConstraintType() const { return constraint_type_; }
|
||||
int getNumericalConstant() const { return numerical_constant_; }
|
||||
short getMinMaxType() const { return max_; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
194
src/grammars/altarica/Transition.cc
Normal file
194
src/grammars/altarica/Transition.cc
Normal file
@@ -0,0 +1,194 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Transition.hh"
|
||||
#include "Node.hh"
|
||||
#include "AltaricaState.hh"
|
||||
#include "Values.hh"
|
||||
#include "Event.hh"
|
||||
#include "Assignment.hh"
|
||||
#include "expressions/Expression.hh"
|
||||
#include "AltaricaException.hh"
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
Transition::Transition(Expression *precond) {
|
||||
precond_ = precond;
|
||||
node_ = NULL;
|
||||
// stateVarsInPrecond = NULL;
|
||||
}
|
||||
|
||||
Transition::Transition() {
|
||||
node_ = NULL;
|
||||
// stateVarsInPrecond = NULL;
|
||||
}
|
||||
|
||||
void Transition::setPrecond(Expression *precond) {
|
||||
precond_ = precond;
|
||||
}
|
||||
|
||||
void Transition::addEvent(Event* e) {
|
||||
eventList_.push_back(e);
|
||||
e->addTrans(this);
|
||||
}
|
||||
|
||||
void Transition::addEvents(std::vector<Event*>* ve) {
|
||||
for (std::vector<Event*>::iterator i = ve->begin(); i != ve->end(); ++i)
|
||||
eventList_.push_back(*i);
|
||||
}
|
||||
|
||||
void Transition::addAssignment(Assignment *a) {
|
||||
assignmentList_.push_back(a);
|
||||
a->setNode(node_);
|
||||
}
|
||||
|
||||
void Transition::addAssignments(std::vector<Assignment*> *va) {
|
||||
for (std::vector<Assignment*>::iterator i = va->begin();
|
||||
i != va->end(); ++i)
|
||||
assignmentList_.push_back(*i);
|
||||
}
|
||||
|
||||
|
||||
Transition * Transition::clone() {
|
||||
Transition * n = new Transition(precond_);
|
||||
for (std::vector<Event*>::iterator it = eventList_.begin();
|
||||
it != eventList_.end(); ++it)
|
||||
n->addEvent(*it);
|
||||
|
||||
for (std::vector<Assignment*>::iterator it = assignmentList_.begin();
|
||||
it != assignmentList_.end(); ++it)
|
||||
n->addAssignment((*it)->clone());
|
||||
|
||||
for (std::vector<MemberAccess*>::iterator it = eventNames_.begin();
|
||||
it != eventNames_.end(); ++it)
|
||||
n->addEventName((*it)->clone());
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void Transition::addEventName(MemberAccess*ma) {
|
||||
eventNames_.push_back(ma);
|
||||
}
|
||||
|
||||
void Transition::addEventNames(std::vector<MemberAccess *> *mav) {
|
||||
for (std::vector<MemberAccess*>::iterator i = mav->begin(); i!= mav->end(); ++i)
|
||||
eventNames_.push_back(*i);
|
||||
}
|
||||
|
||||
void Transition::setNode(Node*n) {
|
||||
node_ = n;
|
||||
for (std::vector<Assignment*>::iterator i = assignmentList_.begin(); i!=assignmentList_.end(); ++i)
|
||||
(*i)->setNode(n);
|
||||
for (std::vector<Event*>::iterator i = eventList_.begin(); i!=eventList_.end(); ++i)
|
||||
(*i)->setNode(n);
|
||||
|
||||
}
|
||||
|
||||
void Transition::matchEvents() {
|
||||
// if (eventList_.size() != 0)
|
||||
// eventList_.clear();
|
||||
// we have only events names for now, we need to add corresponding events in node
|
||||
for (std::vector<MemberAccess*>::const_iterator i = eventNames_.begin();
|
||||
i!=eventNames_.end(); ++i) {
|
||||
Event *e = node_->findEventByName(*i);
|
||||
if (e == NULL) {
|
||||
std::string s = "cannot find event: ";
|
||||
s+= (*i)->toString();
|
||||
throw AltaricaException(s, "epoch::altarica::Transition::matchEvents()");
|
||||
|
||||
}
|
||||
addEvent(e);
|
||||
// e->addTrans(this);
|
||||
}
|
||||
}
|
||||
|
||||
// void Transition::cachePrecond() {
|
||||
// stateVarsInPrecond = precond_->infoVars(node_,false,false);
|
||||
// }
|
||||
|
||||
bool Transition::precondOK(const AltaricaModel *am, AltaricaState *s) const {
|
||||
ValueBool * fv = (ValueBool*) precond_->evaluate(am, s,node_);
|
||||
bool res = fv->allowedTop();
|
||||
Value::deleteIfPossible(fv);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void Transition::doTransition(const AltaricaModel *am, AltaricaState *ps, AltaricaState *ns) {
|
||||
// if (!ps->isMacro()) {
|
||||
for (std::vector<Assignment*>::iterator ai = assignmentList_.begin();
|
||||
ai != assignmentList_.end(); ++ai)
|
||||
ns->setValue((*ai)->getVar(), (*ai)->evaluate(am, ps));
|
||||
// } else {
|
||||
// for (std::vector<Assignment*>::iterator ai = assignmentList_.begin();
|
||||
// ai != assignmentList_.end(); ++ai)
|
||||
// ns->addValue((*ai)->getVar(), (*ai)->evaluate(ps));
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Transition::deleteExprs() {
|
||||
delete precond_ ;
|
||||
for (std::vector<Assignment*>::iterator i = assignmentList_.begin(); i != assignmentList_.end(); ++i)
|
||||
(*i)->deleteExprs();
|
||||
}
|
||||
|
||||
Transition::~Transition() {
|
||||
for (std::vector<MemberAccess*>::iterator i = eventNames_.begin();
|
||||
i!= eventNames_.end(); ++i)
|
||||
delete *i;
|
||||
for (std::vector<Assignment*>::iterator i = assignmentList_.begin(); i != assignmentList_.end(); ++i) {
|
||||
delete (*i);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Transition::toString() const {
|
||||
std::string s;
|
||||
s += "NODE "+ node_->toString() + "\n";
|
||||
for (std::vector<MemberAccess*>::const_iterator i = eventNames_.begin(); i!=eventNames_.end(); ++i) {
|
||||
s+= (*i)->toString() + "; ";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string Transition::toFiacre() const {
|
||||
std::string s;
|
||||
s += "NODE "+ node_->toString() + "\n";
|
||||
for (std::vector<MemberAccess*>::const_iterator i = eventNames_.begin(); i!=eventNames_.end(); ++i) {
|
||||
s+= (*i)->toString() + "; "; //node_
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
106
src/grammars/altarica/Transition.hh
Normal file
106
src/grammars/altarica/Transition.hh
Normal file
@@ -0,0 +1,106 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_TRANSITION_H_
|
||||
#define ALTA_TRANSITION_H_
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Node;
|
||||
class Assignment;
|
||||
class MemberAccess;
|
||||
class Event;
|
||||
class Expression;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
|
||||
class Transition {
|
||||
|
||||
protected:
|
||||
|
||||
//! precondition associee a la transition
|
||||
Expression *precond_;
|
||||
|
||||
//! liste des evenements concernes
|
||||
std::vector<Event*> eventList_;
|
||||
|
||||
std::vector<Assignment*> assignmentList_;
|
||||
|
||||
std::vector<MemberAccess*> eventNames_;
|
||||
|
||||
|
||||
Node * node_;
|
||||
|
||||
// std::vector<Variable*> * stateVarsInPrecond;
|
||||
// std::map<int, int> indexVarTranslator;
|
||||
public:
|
||||
|
||||
//!
|
||||
Transition(Expression *precond);
|
||||
Transition();
|
||||
~Transition();
|
||||
|
||||
void setPrecond(Expression *precond);
|
||||
const Expression * getPrecond() const {return precond_; }
|
||||
void addEvent(Event* e);
|
||||
void addEvents(std::vector<Event*>* ve);
|
||||
void addAssignment(Assignment* a);
|
||||
void addAssignments(std::vector<Assignment*> * va);
|
||||
const std::vector<Assignment*> * getAssigns() const {return &assignmentList_;}
|
||||
void addEventName(MemberAccess *ma);
|
||||
void addEventNames(std::vector<MemberAccess*> *mav);
|
||||
Transition * clone();
|
||||
|
||||
void setNode(Node*n);
|
||||
const Node* getNode() const {return node_;}
|
||||
|
||||
void matchEvents();
|
||||
|
||||
bool precondOK(const AltaricaModel *am, AltaricaState *s) const;
|
||||
|
||||
void doTransition(const AltaricaModel *am, AltaricaState *s, AltaricaState *ns);
|
||||
|
||||
// void cachePrecond();
|
||||
|
||||
|
||||
void deleteExprs();
|
||||
|
||||
std::string toString() const;
|
||||
std::string toFiacre() const;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
33
src/grammars/altarica/Values.hh
Normal file
33
src/grammars/altarica/Values.hh
Normal file
@@ -0,0 +1,33 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef VALUES_HH
|
||||
#define VALUES_HH
|
||||
#include "values/Value.hh"
|
||||
#include "values/ValueBool.hh"
|
||||
#include "values/ValueSymbol.hh"
|
||||
#include "values/ValueInt.hh"
|
||||
#include "values/ValueReal.hh"
|
||||
#endif
|
||||
529
src/grammars/altarica/Variable.cc
Normal file
529
src/grammars/altarica/Variable.cc
Normal file
@@ -0,0 +1,529 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <limits.h>
|
||||
|
||||
#include "MemberAccess.hh"
|
||||
#include "Variable.hh"
|
||||
#include "AltaricaState.hh"
|
||||
#include "Assertion.hh"
|
||||
#include "Node.hh"
|
||||
#include "domains/Domains.hh"
|
||||
#include "Values.hh"
|
||||
#include "LandmarkState.hh"
|
||||
#include "AltaricaException.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
Variable::Variable(std::string name) {
|
||||
ma_= new MemberAccess(name);
|
||||
domain_ = NULL;
|
||||
asserts_ = NULL;
|
||||
init_ = NULL;
|
||||
loop_status_ = 0;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
Variable::Variable(MemberAccess *ma) {
|
||||
ma_= ma;
|
||||
domain_ = NULL;
|
||||
asserts_ = NULL;
|
||||
init_ = NULL;
|
||||
loop_status_ = 0;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
|
||||
Variable::Variable(std::string name, Domain* d) {
|
||||
domain_ = d;
|
||||
ma_=new MemberAccess(name);
|
||||
asserts_ = NULL;
|
||||
init_ = NULL;
|
||||
loop_status_ = 0;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
Variable::Variable(MemberAccess *ma, Domain* d) {
|
||||
domain_ = d;
|
||||
ma_=ma;
|
||||
asserts_ = NULL;
|
||||
loop_status_ = 0;
|
||||
init_ = NULL;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
|
||||
Variable::Variable(std::string name, Domain* d, bool isState) {
|
||||
domain_ = d;
|
||||
ma_ = new MemberAccess(name);
|
||||
state_ = isState;
|
||||
asserts_ = NULL;
|
||||
loop_status_ = 0;
|
||||
init_ = NULL;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
Variable::Variable(MemberAccess *ma, Domain* d, bool isState) {
|
||||
domain_ = d;
|
||||
ma_ = ma;
|
||||
state_ = isState;
|
||||
loop_status_ = 0;
|
||||
asserts_ = NULL;
|
||||
init_ = NULL;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
|
||||
Variable::Variable(std::string name, bool isState) {
|
||||
state_ = isState;
|
||||
ma_ = new MemberAccess(name);
|
||||
asserts_ = NULL;
|
||||
loop_status_ = 0;
|
||||
init_ = NULL;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
Variable::Variable(MemberAccess *ma, bool isState) {
|
||||
state_ = isState;
|
||||
ma_ = ma;
|
||||
asserts_ = NULL;
|
||||
init_ = NULL;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
loop_status_ = 0;
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
Domain * Variable::getDomain() const {
|
||||
return domain_;
|
||||
}
|
||||
|
||||
void Variable::setDomain(Domain *d) {
|
||||
domain_ = d;
|
||||
}
|
||||
|
||||
void Variable::setState(bool s) {
|
||||
state_ = s;
|
||||
}
|
||||
|
||||
void Variable::setState() {
|
||||
state_ = true;
|
||||
}
|
||||
|
||||
void Variable::setFlow() {
|
||||
state_ = false;
|
||||
}
|
||||
|
||||
|
||||
void Variable::addAttribute(const std::string a) {
|
||||
attributes_.push_back(std::string(a));
|
||||
}
|
||||
|
||||
void Variable::addAttributes(const std::vector<std::string> *va) {
|
||||
if (va != NULL)
|
||||
for (std::vector<std::string>::const_iterator si = va->begin(); si != va->end(); ++si) {
|
||||
addAttribute(*si);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Variable::setMemberAccess(MemberAccess *ma) {
|
||||
ma_ = ma;
|
||||
}
|
||||
|
||||
Variable * Variable::clone() const {
|
||||
Variable * n = new Variable(ma_->clone(), domain_, state_);
|
||||
// if (ma_!=NULL)
|
||||
// n->setMemberAccess(ma_->clone());
|
||||
n->addAttributes(&attributes_);
|
||||
n->setNode(node_);
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::iterator i =
|
||||
aliases_->begin(); i!=aliases_->end(); ++i)
|
||||
n->addAlias((*i)->first, (*i)->second->clone());
|
||||
// if (init_ != NULL)
|
||||
n->setInit(init_);
|
||||
return n;
|
||||
}
|
||||
|
||||
// bool Variable::isState() const {
|
||||
// return state_;
|
||||
// }
|
||||
|
||||
|
||||
// bool Variable::isFlow() const {
|
||||
// return !state_;
|
||||
// }
|
||||
|
||||
void Variable::setNode(const Node*n) {
|
||||
node_ = n;
|
||||
}
|
||||
|
||||
const Node * Variable::getNode() const{
|
||||
return node_;
|
||||
}
|
||||
|
||||
const std::vector<Node *> * Variable::getNodes() const {
|
||||
std::vector<Node*>* ret = new std::vector<Node*>();
|
||||
ret->push_back((Node*)node_);
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::iterator i =
|
||||
aliases_->begin(); i!=aliases_->end(); ++i) {
|
||||
ret->push_back((Node*)(*i)->first);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<const Node *>* Variable::getPath() const {
|
||||
std::vector<const Node*>* ret = node_->getPath();
|
||||
ret->push_back(node_);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string Variable::getFullName() const {
|
||||
std::ostringstream ss;
|
||||
ss << node_->getFullName()
|
||||
<< "."
|
||||
<< getMA()->toString();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void Variable::setInit(Assignment* n) {
|
||||
init_ = n;
|
||||
}
|
||||
|
||||
const Assignment * Variable::getInit() {
|
||||
return init_;
|
||||
}
|
||||
|
||||
|
||||
const MemberAccess * Variable::getMA() const{
|
||||
return ma_;
|
||||
}
|
||||
|
||||
std::vector<Variable*> * Variable::flattenDomain() {
|
||||
return domain_->flatten(this);
|
||||
}
|
||||
|
||||
void Variable::addToMASecond(int i) {
|
||||
ma_->addIndexSecond(i);
|
||||
}
|
||||
|
||||
|
||||
void Variable::addToMASecond(std::string s) {
|
||||
ma_->addIdSecond(s);
|
||||
}
|
||||
|
||||
void Variable::addAssert(Assertion* a) {
|
||||
if (asserts_ == NULL)
|
||||
asserts_ = new std::vector<Assertion*>();
|
||||
asserts_->push_back(a);
|
||||
}
|
||||
|
||||
void Variable::addAsserts(const std::vector<Assertion*> * a) {
|
||||
if (a == NULL)
|
||||
return;
|
||||
for (std::vector<Assertion*>::const_iterator i = a->begin(); i!= a->end(); ++i)
|
||||
addAssert(*i);
|
||||
}
|
||||
|
||||
const std::vector<Assertion*> * Variable::getAsserts() const {
|
||||
return asserts_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// unsigned int Variable::nbUnComputedOpen(std::vector<Variable*> * vv, AltaricaState *s) {
|
||||
// unsigned int c = 0;
|
||||
// for (std::vector<Variable*>::iterator i = vv->begin(); i!= vv->end(); ++i) {
|
||||
// if (!s->hasValue(*i))
|
||||
// ++c;
|
||||
// }
|
||||
// return c;
|
||||
// }
|
||||
|
||||
void Variable::forceEvaluate(const AltaricaModel *am, AltaricaState *s) const {
|
||||
s->setValue(this, getDomain()->toValue());
|
||||
s->getValue(this)->unConstrain();
|
||||
|
||||
// if (asserts_->size() > 1) {
|
||||
// std::cerr << "more than one assert possible to compute" << std::endl;
|
||||
// }
|
||||
if (asserts_->size() == 0) {
|
||||
std::string s = "cannot compute: " + toString();
|
||||
std::cerr << "\nError " << s << std::endl;
|
||||
throw new AltaricaException(s, "Variable::evaluate");
|
||||
}
|
||||
|
||||
for (std::vector<Assertion*>::iterator ai = asserts_->begin(); ai != asserts_->end(); ++ai) {
|
||||
(*ai)->evaluate(am, s);
|
||||
}
|
||||
s->getValue(this)->constrain();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Variable::evaluate(const AltaricaModel *am, AltaricaState *s) const {
|
||||
// if (index_ == 717 || index_ == 1411 || index_ == 2125 || index_ == 2841) {
|
||||
// std::cout << "blah\n";
|
||||
// std::cout << s->toString(true,true,false,false) << std::endl;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
if (s->getFlowValue(index_) != NULL) {
|
||||
loop_status_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch (loop_status_) {
|
||||
case 0: loop_status_ = 1;
|
||||
break;
|
||||
case 1: loop_status_ = 2;
|
||||
std::cerr << ">>>>>>>>>>>>>>>>>>>>>>>>> loop detected, into loop for debug\n";
|
||||
std::cerr << ">>>>>>>>>>>>>>>>>>>>>>>>> evaluating var: " << this->toString() << " \n";
|
||||
break;
|
||||
case 2:
|
||||
std::cerr << "<<<<<<<<<<<<<<<<<<<<<<<< end of loop, assuming all possible values, you should check your model\n";
|
||||
s->setValue(this, getDomain()->toValue());
|
||||
s->getValue(this)->unConstrain();
|
||||
// loop_status_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
s->setValue(this, NULL);
|
||||
|
||||
// s->setValue(this, getDomain()->toValue(), false);
|
||||
// s->getValue(this)->unConstrain();
|
||||
if ((asserts_ == NULL) || (asserts_->size() == 0)) {
|
||||
std::string s = "cannot compute: " + toString();
|
||||
std::cerr << "\nError " << s << std::endl;
|
||||
throw new AltaricaException(s, "Variable::evaluate");
|
||||
}
|
||||
|
||||
for (std::vector<Assertion*>::iterator ai = asserts_->begin(); ai != asserts_->end(); ++ai) {
|
||||
if (loop_status_ == 2)
|
||||
std::cerr << ">>>>>>>>>>>>>>>>>>> using assertion\n" << (*ai)->getExpr()->toString() << "\n";
|
||||
|
||||
(*ai)->evaluate(am, s);
|
||||
}
|
||||
s->getValue(this)->constrain();
|
||||
loop_status_ = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Variable::evaluateLM(const AltaricaModel *am, LandmarkState *lms) const {
|
||||
if (lms->getState()->hasValue(this))
|
||||
return;
|
||||
lms->getState()->setValue(this, getDomain()->toValue());
|
||||
lms->getState()->getValue(this)->unConstrain();
|
||||
|
||||
// int bidon = this->toString().find("MMEL_status^applicable");
|
||||
// if (bidon!=-1) {
|
||||
// std::cerr << "blah";
|
||||
// }
|
||||
|
||||
if (asserts_->size() > 1) {
|
||||
std::cerr << "more than one assert possible to compute" << std::endl;
|
||||
}
|
||||
|
||||
for (std::vector<Assertion*>::iterator ai = asserts_->begin(); ai != asserts_->end(); ++ai) {
|
||||
(*ai)->evaluateLM(am, lms);
|
||||
}
|
||||
lms->getState()->getValue(this)->constrain();
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string Variable::toString() const {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << index_ << ": " << node_->toString() << "."+ma_->toString();
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::iterator i = aliases_->begin();
|
||||
i!= aliases_->end(); ++i)
|
||||
ss << " / " << (*i)->first->toString() << "." << (*i)->second->toString();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string Variable::toFiacre(const bool print_head) const {
|
||||
std::ostringstream ss;
|
||||
|
||||
if (print_head) {
|
||||
if (node_->findStateVariableByName(ma_->toString()))
|
||||
ss << "y.";
|
||||
if (node_->findFlowVariableByName(ma_->toString()))
|
||||
ss << "x.";
|
||||
}
|
||||
ss << node_->toFiacre() << "_" << ma_->toString();
|
||||
|
||||
// for (std::vector<std::pair<const Node*, const MemberAccess*>*>::iterator i = aliases_->begin(); i!= aliases_->end(); ++i)
|
||||
// ss << " / " << (*i)->first->toString() << "_" << (*i)->second->toString();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool Variable::equals(std::vector<Variable*> *v1, std::vector<Variable*> *v2) {
|
||||
if (v1->size() != v2->size())
|
||||
return false;
|
||||
for (std::vector<Variable*>::iterator v1it = v1->begin(); v1it != v1->end(); ++v1it) {
|
||||
bool isIn = false;
|
||||
for (std::vector<Variable*>::iterator v2it = v2->begin();
|
||||
v2it != v2->end() && ! isIn; ++v2it) {
|
||||
if (*v2it == *v1it)
|
||||
isIn = true;
|
||||
}
|
||||
if (!isIn)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<Variable*> *Variable::removeFromVec(std::vector<Variable*> *toRemove, std::vector<Variable*> *all) {
|
||||
for (std::vector<Variable*>::iterator i = toRemove->begin(); i!=toRemove->end(); ++i) {
|
||||
bool removed = false;
|
||||
for (std::vector<Variable*>::iterator j = all->begin(); j!=all->end() && !removed; ++j) {
|
||||
if (*i == *j) {
|
||||
all->erase(j);
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
Variable::~Variable() {
|
||||
delete ma_;
|
||||
attributes_.clear();
|
||||
delete asserts_;
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::iterator i =aliases_->begin();
|
||||
i!= aliases_->end(); ++i) {
|
||||
delete (*i)->second;
|
||||
delete *i;
|
||||
}
|
||||
delete aliases_;
|
||||
}
|
||||
|
||||
void Variable::addAlias(const Node *n, const MemberAccess*ma) {
|
||||
aliases_->push_back(new std::pair<const Node*, const MemberAccess*>(n,ma));
|
||||
}
|
||||
|
||||
bool Variable::hasName(const Node* n, const MemberAccess* ma) const {
|
||||
if (node_ == n && ma_->equals(ma))
|
||||
return true;
|
||||
for (std::vector<std::pair<const Node*,const MemberAccess*>*>::const_iterator i = aliases_->begin();
|
||||
i!= aliases_->end(); ++i)
|
||||
if ((*i)->first == n && (*i)->second->equals(ma))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Variable::mergeVariable(const Variable *v) {
|
||||
std::cerr << "Merging variable " << getFullName() << " : " << getAsserts()->size() << " with " << v->getFullName() << " : " << v->getAsserts()->size() << std::endl;
|
||||
|
||||
if (state_ || v->isState())
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("trying to merge varibles that are not flow vars!!!!!!!")));
|
||||
addAttributes(v->getAttributes());
|
||||
addAsserts(v->getAsserts());
|
||||
addAlias(v->getNode(), v->getMA()->clone());
|
||||
const std::vector<std::pair<const Node*, const MemberAccess*>*> * valiases = v->getAliases();
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::const_iterator i = valiases->begin();
|
||||
i!= valiases->end(); ++i) {
|
||||
addAlias((*i)->first, (*i)->second->clone());
|
||||
}
|
||||
|
||||
std::cerr << " merged variable " << getFullName() << " : " << getAsserts()->size()<< std::endl;
|
||||
}
|
||||
|
||||
const std::vector<std::pair<const Node*, const MemberAccess*>*> * Variable::getAliases() const {
|
||||
return aliases_;
|
||||
}
|
||||
|
||||
const std::vector<std::string> *Variable::getAttributes() const {
|
||||
return &attributes_;
|
||||
}
|
||||
|
||||
void Variable::removeAssert(Assertion*a) {
|
||||
for (std::vector<Assertion*>::iterator i = asserts_->begin(); i != asserts_->end(); ++i)
|
||||
if (*i == a) {
|
||||
asserts_->erase(i);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Variable::removeOwner(Node *n) {
|
||||
if (node_ == n) {
|
||||
node_ = NULL;
|
||||
if (aliases_->size() == 0)
|
||||
return true;
|
||||
} else {
|
||||
std::vector<std::pair<const Node*, const MemberAccess*>*>::iterator i;
|
||||
for (i = aliases_->begin(); i!= aliases_->end() && (*i)->first!=n; ++i);
|
||||
if (i == aliases_->end())
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("unable to find owner!!!!!!!")));
|
||||
delete (*i)->second;
|
||||
delete *i;
|
||||
aliases_->erase(i);
|
||||
if (aliases_->size() == 0 && node_ == NULL)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Variable*> * Variable::infoVars(const AltaricaModel *am, const Node *n, bool flow, bool computed) {
|
||||
if (state_)
|
||||
return NULL;
|
||||
std::vector<Variable*>* vv = new std::vector<Variable*>();
|
||||
for (std::vector<Assertion*>::iterator i = asserts_->begin(); i!= asserts_->end(); ++i) {
|
||||
std::vector<Variable*> *vvv = (*i)->infoVars(am, flow, computed);
|
||||
vv->insert(vv->end(), vvv->begin(), vvv->end());
|
||||
delete vvv;
|
||||
}
|
||||
return vv;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
182
src/grammars/altarica/Variable.hh
Normal file
182
src/grammars/altarica/Variable.hh
Normal file
@@ -0,0 +1,182 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_VARIABLE_H_
|
||||
#define ALTA_VARIABLE_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Node;
|
||||
class Assignment;
|
||||
class Assertion;
|
||||
class MemberAccess;
|
||||
class Value;
|
||||
class Expression;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
class Domain;
|
||||
class LandmarkState;
|
||||
|
||||
class Variable {
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int index_;
|
||||
mutable unsigned int loop_status_; // 0 means nothing
|
||||
// 1 for evaluating
|
||||
// 2 for in_loop debug
|
||||
|
||||
|
||||
//! full qualified name
|
||||
MemberAccess *ma_;
|
||||
//! variable type
|
||||
Domain * domain_;
|
||||
//! state or flow variable
|
||||
bool state_;
|
||||
//! attributes (tool-dependant)
|
||||
std::vector<std::string> attributes_;
|
||||
const Node * node_;
|
||||
Assignment * init_;
|
||||
|
||||
std::vector<Assertion*> * asserts_; // Assertions that change its value
|
||||
|
||||
std::vector<std::pair<const Node*, const MemberAccess*>*> *aliases_;
|
||||
|
||||
static int nbUnComputedOpen(std::vector<Variable*> * vv, AltaricaState *s);
|
||||
|
||||
public:
|
||||
|
||||
inline unsigned int getIndex() const {return index_;}
|
||||
inline void setIndex(unsigned int i) {index_ = i;}
|
||||
|
||||
//! constructeur minimal
|
||||
Variable(std::string name);
|
||||
Variable(MemberAccess* ma);
|
||||
|
||||
//! constructeur un peu plus evolué
|
||||
Variable(std::string name, bool isState);
|
||||
Variable(MemberAccess *ma, bool isState);
|
||||
|
||||
//! encore un autre
|
||||
Variable(std::string name, Domain* d);
|
||||
Variable(MemberAccess *ma, Domain* d);
|
||||
|
||||
//! constructeur quasi-complet
|
||||
Variable(std::string name, Domain* d, bool isState);
|
||||
Variable(MemberAccess *ma, Domain* d, bool isState);
|
||||
|
||||
void setMemberAccess(MemberAccess * ma);
|
||||
const MemberAccess * getMA() const;
|
||||
|
||||
|
||||
void addToMASecond(int i);
|
||||
void addToMASecond(std::string s);
|
||||
|
||||
//! State or flow
|
||||
void setState(bool s);
|
||||
|
||||
//! variable domain
|
||||
void setDomain(Domain *d);
|
||||
|
||||
//! State attribute variable
|
||||
void setState();
|
||||
|
||||
//! Flow attribute
|
||||
void setFlow();
|
||||
|
||||
//! attributs externes a altarica
|
||||
void addAttribute(const std::string a);
|
||||
|
||||
|
||||
//! attributs externes a altarica
|
||||
void addAttributes(const std::vector<std::string> *va);
|
||||
const std::vector<std::string> *getAttributes() const;
|
||||
|
||||
void addAssert(Assertion* a);
|
||||
void addAsserts(const std::vector<Assertion*> * a);
|
||||
const std::vector<Assertion*> * getAsserts() const;
|
||||
|
||||
|
||||
void setNode(const Node* n);
|
||||
const Node * getNode() const;
|
||||
const std::vector<Node *>* getNodes() const;
|
||||
void setParentNode(const Node* n);
|
||||
const Node * getParentNode();
|
||||
|
||||
std::vector<const Node *>* getPath() const;
|
||||
std::string getFullName() const;
|
||||
|
||||
void setInit(Assignment* n);
|
||||
const Assignment * getInit();
|
||||
|
||||
std::vector<Variable*> * flattenDomain();
|
||||
|
||||
Variable * clone() const;
|
||||
|
||||
// std::string* getName();
|
||||
|
||||
Domain * getDomain() const;
|
||||
|
||||
inline bool isState() const {return state_;}
|
||||
inline bool isFlow() const {return !state_;}
|
||||
|
||||
// Value * getInitialValue(); // defined for Prism
|
||||
|
||||
static bool equals(std::vector<Variable*> *v1, std::vector<Variable*> *v2);
|
||||
static std::vector<Variable*> *removeFromVec(std::vector<Variable*> *toRemove, std::vector<Variable*> *all);
|
||||
|
||||
void evaluate(const AltaricaModel* am, AltaricaState *s) const;
|
||||
void forceEvaluate(const AltaricaModel* am, AltaricaState *s) const;
|
||||
void evaluateLM(const AltaricaModel* am, LandmarkState *lms) const;
|
||||
|
||||
|
||||
bool hasName(const Node* n, const MemberAccess* ma) const;
|
||||
void addAlias(const Node* n, const MemberAccess* ma);
|
||||
const std::vector<std::pair<const Node*, const MemberAccess*>*> * getAliases() const;
|
||||
|
||||
std::string toString() const;
|
||||
std::string toFiacre(const bool print_head = true) const ;
|
||||
~Variable();
|
||||
|
||||
void mergeVariable(const Variable *v);
|
||||
|
||||
void removeAssert(Assertion*a);
|
||||
|
||||
bool removeOwner(Node *n);
|
||||
|
||||
std::vector<Variable*> * infoVars(const AltaricaModel*am, const Node *n, bool flow, bool computed);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
202
src/grammars/altarica/altarica.l
Normal file
202
src/grammars/altarica/altarica.l
Normal file
@@ -0,0 +1,202 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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:
|
||||
* Florent Teichteil-Königsbuch (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
%{
|
||||
#include <cstdlib>
|
||||
#include <cerrno>
|
||||
#include <climits>
|
||||
#include <string>
|
||||
#include "altarica_driver.hh"
|
||||
#include "altarica_parser.hh"
|
||||
#undef yywrap
|
||||
#define yywrap(yyscanner) 1
|
||||
//#define yyterminate() yy_delete_buffer(YY_CURRENT_BUFFER); return token::ALTARICA_END
|
||||
#define yyterminate() return token::ALTARICA_END
|
||||
%}
|
||||
|
||||
%option noyywrap nounput batch debug reentrant
|
||||
|
||||
|
||||
|
||||
blank [ \t]
|
||||
|
||||
%{
|
||||
#define YY_USER_ACTION yylloc->columns (yyleng);
|
||||
%}
|
||||
|
||||
%s IN_COMMENT
|
||||
|
||||
%%
|
||||
%{
|
||||
/* Location handling */
|
||||
yylloc->step ();
|
||||
%}
|
||||
|
||||
%{
|
||||
typedef epoch::altarica::altarica_parser::token token;
|
||||
%}
|
||||
|
||||
"," return token::ALTARICA_COMMA;
|
||||
: return token::ALTARICA_COLON;
|
||||
; return token::ALTARICA_SEMICOLON;
|
||||
= return token::ALTARICA_EQUAL;
|
||||
"[" return token::ALTARICA_LEFTBRACKET;
|
||||
"]" return token::ALTARICA_RIGHTBRACKET;
|
||||
"{" return token::ALTARICA_LEFTEMBRACE;
|
||||
"}" return token::ALTARICA_RIGHTEMBRACE;
|
||||
"const" return token::ALTARICA_CONST;
|
||||
CONST return token::ALTARICA_CONST;
|
||||
domain return token::ALTARICA_DOMAIN;
|
||||
DOMAIN return token::ALTARICA_DOMAIN;
|
||||
|
||||
|
||||
"(" return token::ALTARICA_OPAREN;
|
||||
")" return token::ALTARICA_CPAREN;
|
||||
"?" return token::ALTARICA_IMARK;
|
||||
|
||||
SORT return token::ALTARICA_SORT;
|
||||
sort return token::ALTARICA_SORT;
|
||||
SIG return token::ALTARICA_SIG;
|
||||
sig return token::ALTARICA_SIG;
|
||||
"->" return token::ALTARICA_TO;
|
||||
"*" return token::ALTARICA_STAR;
|
||||
if return token::ALTARICA_IF;
|
||||
then return token::ALTARICA_THEN;
|
||||
else return token::ALTARICA_ELSE;
|
||||
case return token::ALTARICA_CASE;
|
||||
or return token::ALTARICA_OR;
|
||||
"|" return token::ALTARICA_LOR;
|
||||
and return token::ALTARICA_AND;
|
||||
"&" return token::ALTARICA_LAND;
|
||||
"!=" return token::ALTARICA_DIF;
|
||||
"#" return token::ALTARICA_CARD;
|
||||
"=>" return token::ALTARICA_IMPLIES;
|
||||
"<" return token::ALTARICA_INF;
|
||||
">" return token::ALTARICA_SUP;
|
||||
"<=" return token::ALTARICA_INFEQ;
|
||||
">=" return token::ALTARICA_SUPEQ;
|
||||
"+" return token::ALTARICA_PLUS;
|
||||
"-" return token::ALTARICA_MINUS;
|
||||
"/" return token::ALTARICA_DIV;
|
||||
MOD return token::ALTARICA_MOD;
|
||||
mod return token::ALTARICA_MOD;
|
||||
"~" return token::ALTARICA_TILDE;
|
||||
NOT return token::ALTARICA_NOT;
|
||||
not return token::ALTARICA_NOT;
|
||||
"." return token::ALTARICA_DOT;
|
||||
MIN return token::ALTARICA_MIN;
|
||||
min return token::ALTARICA_MIN;
|
||||
MAX return token::ALTARICA_MAX;
|
||||
max return token::ALTARICA_MAX;
|
||||
TRUE return token::ALTARICA_TRUE;
|
||||
"true" return token::ALTARICA_TRUE;
|
||||
FALSE return token::ALTARICA_FALSE;
|
||||
"false" return token::ALTARICA_FALSE;
|
||||
NODE return token::ALTARICA_NODE;
|
||||
node return token::ALTARICA_NODE;
|
||||
EDON return token::ALTARICA_EDON;
|
||||
edon return token::ALTARICA_EDON;
|
||||
PARAM return token::ALTARICA_PARAM;
|
||||
param return token::ALTARICA_PARAM;
|
||||
FLOW return token::ALTARICA_FLOW;
|
||||
flow return token::ALTARICA_FLOW;
|
||||
STATE return token::ALTARICA_STATE;
|
||||
state return token::ALTARICA_STATE;
|
||||
EVENT return token::ALTARICA_EVENT;
|
||||
event return token::ALTARICA_EVENT;
|
||||
SUB return token::ALTARICA_SUB;
|
||||
sub return token::ALTARICA_SUB;
|
||||
ASSERT return token::ALTARICA_ASSERT;
|
||||
assert return token::ALTARICA_ASSERT;
|
||||
TRANS return token::ALTARICA_TRANS;
|
||||
trans return token::ALTARICA_TRANS;
|
||||
"|-" return token::ALTARICA_TR;
|
||||
":=" return token::ALTARICA_AFFECT;
|
||||
SYNC return token::ALTARICA_SYNC;
|
||||
sync return token::ALTARICA_SYNC;
|
||||
INIT return token::ALTARICA_INIT;
|
||||
init return token::ALTARICA_INIT;
|
||||
PARAM_SET return token::ALTARICA_PARAM_SET;
|
||||
param_set return token::ALTARICA_PARAM_SET;
|
||||
EXTERN return token::ALTARICA_EXTERN;
|
||||
"extern" return token::ALTARICA_EXTERN;
|
||||
ccf return token::ALTARICA_CCF;
|
||||
withCCF return token::ALTARICA_WITHCCF;
|
||||
nodeproperty return token::ALTARICA_NODEPROPERTY;
|
||||
Dirac return token::ALTARICA_LAW_DIRAC;
|
||||
constant return token::ALTARICA_LAW_DISCRETE;
|
||||
exponential return token::ALTARICA_LAW_EXP;
|
||||
exp return token::ALTARICA_LAW_EXP;
|
||||
time return token::ALTARICA_LAW_TIMED;
|
||||
|
||||
|
||||
|
||||
|
||||
BOOL return token::ALTARICA_BOOL;
|
||||
bool return token::ALTARICA_BOOL;
|
||||
INTEGER return token::ALTARICA_INTEGER;
|
||||
integer return token::ALTARICA_INTEGER;
|
||||
real return token::ALTARICA_REAL;
|
||||
REAL return token::ALTARICA_REAL;
|
||||
int return token::ALTARICA_INTEGER;
|
||||
INT return token::ALTARICA_INTEGER;
|
||||
STRUCT return token::ALTARICA_STRUCT;
|
||||
"struct" return token::ALTARICA_STRUCT;
|
||||
TCURTS return token::ALTARICA_TCURTS;
|
||||
tcurts return token::ALTARICA_TCURTS;
|
||||
law return token::ALTARICA_LAW;
|
||||
remark return token::ALTARICA_REMARK;
|
||||
attribute return token::ALTARICA_ATTRIBUTE;
|
||||
global return token::ALTARICA_GLOBAL;
|
||||
|
||||
[-+]?[0-9]*"."[0-9]+([eE][+-]?[0-9]+)? yylval->fl = atof(yytext); return token::ALTARICA_FLOAT;
|
||||
[1-9][0-9]*|0 yylval->ui = atoi(yytext) ; return token::ALTARICA_UNSIGNED_INTEGER;
|
||||
[a-zA-Z_][a-zA-Z_0-9"^"]* yylval->st = new std::string (yytext); return token::ALTARICA_IDENTIFIER;
|
||||
\".*\" return token::ALTARICA_STRING;
|
||||
|
||||
|
||||
|
||||
"//".* { /* ignore comments */ }
|
||||
<INITIAL>{
|
||||
"/*" BEGIN(IN_COMMENT);
|
||||
}
|
||||
<IN_COMMENT>{
|
||||
"*"+"/" BEGIN(INITIAL);
|
||||
[^*\n]* { /* eat comment in chunks */ }
|
||||
"*"+[^*/\n]* { /* eat the lone star */ }
|
||||
\n yylineno++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
{blank}+ yylloc->step();
|
||||
[\n\r]+ yylloc->lines(yyleng); yylloc->step(); yylineno += yyleng;
|
||||
|
||||
%%
|
||||
|
||||
|
||||
2303
src/grammars/altarica/altarica.yy
Normal file
2303
src/grammars/altarica/altarica.yy
Normal file
File diff suppressed because it is too large
Load Diff
58
src/grammars/altarica/altarica_driver.cc
Normal file
58
src/grammars/altarica/altarica_driver.cc
Normal file
@@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "altarica_driver.hh"
|
||||
#include "altarica_parser.hh"
|
||||
#include "altarica_lexer.h"
|
||||
#include "grammars/details/parsingdriverbaseimpl.hh"
|
||||
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
altarica_driver::altarica_driver(epoch::ParsingDriverReporter& reporter, const std::string& parsedRessource,
|
||||
bool traceScanning, bool traceParsing)
|
||||
: epoch::ParsingDriverBase(reporter, parsedRessource, traceScanning, traceParsing)
|
||||
{
|
||||
amodel = new epoch::altarica::AltaricaModel();
|
||||
}
|
||||
|
||||
|
||||
altarica_driver::~altarica_driver() {}
|
||||
|
||||
|
||||
|
||||
int altarica_driver::Parse () {
|
||||
int parsingResult = epoch::ParsingDriverBase::ParseFile(*this);
|
||||
ClearRuleStack();
|
||||
return parsingResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void altarica_driver::DeleteRule(boost::any& rule) {
|
||||
if (DeleteRuleHelper<std::string>(rule)) return;
|
||||
// No match: memory leak!
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Rule with type ") + rule.type().name() + " not deleted!"));
|
||||
}
|
||||
77
src/grammars/altarica/altarica_driver.hh
Normal file
77
src/grammars/altarica/altarica_driver.hh
Normal file
@@ -0,0 +1,77 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_DRIVER_H
|
||||
#define ALTARICA_DRIVER_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "grammars/altarica/altarica_parser.hh"
|
||||
#include "grammars/parsingdriverbase.hh"
|
||||
#include "grammars/altarica/AltaricaModel.hh"
|
||||
|
||||
|
||||
|
||||
#undef YY_DECL
|
||||
#define YY_DECL epoch::altarica::altarica_parser::token_type yylex (epoch::altarica::altarica_parser::semantic_type * yylval, epoch::altarica::altarica_parser::location_type * yylloc, altarica_driver & driver, void* yyscanner)
|
||||
|
||||
YY_DECL;
|
||||
|
||||
|
||||
|
||||
class altarica_driver : public epoch::ParsingDriverBase {
|
||||
public :
|
||||
altarica_driver(epoch::ParsingDriverReporter& reporter, const std::string& parsedRessource,
|
||||
bool traceScanning = false, bool traceParsing = false);
|
||||
virtual ~altarica_driver();
|
||||
|
||||
epoch::altarica::AltaricaModel * amodel;
|
||||
|
||||
|
||||
virtual int Parse ();
|
||||
|
||||
void scan_end();
|
||||
|
||||
typedef epoch::altarica::altarica_parser Parser;
|
||||
|
||||
private :
|
||||
/**
|
||||
* Deletes a stacked rule (useful for Bison-based parsers)
|
||||
* The derived parsing driver must cast the given rule to any possible rule in the parser
|
||||
* Typically, all %type declared rules must be deleted in case of matching cast
|
||||
* @param rule Rule to delete
|
||||
* @see #ClearRuleStack
|
||||
*/
|
||||
virtual void DeleteRule(boost::any& rule);
|
||||
|
||||
// Bison friend
|
||||
friend class epoch::altarica::altarica_parser;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
56
src/grammars/altarica/details/AltaricaGeneratorImpl.hh
Normal file
56
src/grammars/altarica/details/AltaricaGeneratorImpl.hh
Normal file
@@ -0,0 +1,56 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
|
||||
100
src/grammars/altarica/domains/ArrayDomain.cc
Normal file
100
src/grammars/altarica/domains/ArrayDomain.cc
Normal file
@@ -0,0 +1,100 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ArrayDomain.hh"
|
||||
#include "Variable.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
ArrayDomain::ArrayDomain(int asize, Domain*d):asize_(asize), adomain_(d) {
|
||||
}
|
||||
|
||||
unsigned int ArrayDomain::index(std::string arg) const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("index asked on a Structured domain")));
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string ArrayDomain::text(unsigned int index) const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("text asked on a Structured domain")));
|
||||
return 0;
|
||||
}
|
||||
|
||||
Value * ArrayDomain::toValue() const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("toOpenValue asked on a Structured domain")));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ArrayDomain::getMin() const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getMin asked on an ArrayDomain")));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ArrayDomain::getMax() const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getMax asked on a ArrayDomain")));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Value * ArrayDomain::getFixedValue(int i) {
|
||||
// BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getFixedValue(i) asked on a ArrayDomain")));
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
Value * ArrayDomain::getValue(int i) {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getFixedValue(i) asked on a ArrayDomain")));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<Variable*> * ArrayDomain::flatten(Variable* v) const {
|
||||
std::vector<Variable*> * nvv = new std::vector<Variable*>();
|
||||
std::vector<Variable*> * fv = adomain_->flatten(v);
|
||||
for (std::vector<Variable*>::iterator fvi= fv->begin(); fvi != fv->end(); ++fvi) {
|
||||
for (int i = 0; i<asize_; ++i) {
|
||||
Variable * nv = (*fvi)->clone();
|
||||
nv->addToMASecond(i);
|
||||
nvv->push_back(nv);
|
||||
}
|
||||
}
|
||||
delete(fv);
|
||||
return nvv;
|
||||
}
|
||||
|
||||
std::string ArrayDomain::toString() const {
|
||||
return "ARRAY";
|
||||
}
|
||||
ArrayDomain::~ArrayDomain() {
|
||||
// delete(adomain_);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
70
src/grammars/altarica/domains/ArrayDomain.hh
Normal file
70
src/grammars/altarica/domains/ArrayDomain.hh
Normal file
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_ARRAY_DOMAIN_H_
|
||||
#define ALTA_ARRAY_DOMAIN_H_
|
||||
|
||||
#include "DiscreteDomain.hh"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
//! Array Domain
|
||||
/*!
|
||||
Stucture pour stocker les types array d'altarica
|
||||
*/
|
||||
class ArrayDomain : public DiscreteDomain {
|
||||
|
||||
protected:
|
||||
|
||||
//! les types sont stockes dans un vecteur
|
||||
int asize_;
|
||||
Domain* adomain_;
|
||||
|
||||
public:
|
||||
|
||||
//! constructeur qui ne fait rien
|
||||
ArrayDomain(int asize, Domain* d);
|
||||
|
||||
//! calcule un index. attention aux debordements
|
||||
virtual unsigned int index(std::string arg) const;
|
||||
virtual std::string text(unsigned int index) const;
|
||||
virtual std::vector<Variable*> * flatten(Variable* v) const;
|
||||
virtual Value * toValue() const;
|
||||
virtual int getMin() const;
|
||||
virtual int getMax() const;
|
||||
virtual Value * getValue(int i);
|
||||
virtual std::string toString() const;
|
||||
|
||||
virtual ~ArrayDomain();
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
44
src/grammars/altarica/domains/ContinuousDomain.hh
Normal file
44
src/grammars/altarica/domains/ContinuousDomain.hh
Normal file
@@ -0,0 +1,44 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_CONTINUOUS_DOMAIN_H_
|
||||
#define ALTA_CONTINUOUS_DOMAIN_H_
|
||||
|
||||
#include "Domain.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class ContinuousDomain : public Domain {
|
||||
|
||||
protected :
|
||||
public:
|
||||
virtual ~ContinuousDomain() {};
|
||||
virtual std::vector<Variable*> * flatten(Variable* v) const = 0;
|
||||
virtual Value * toValue() const = 0;
|
||||
virtual std::string toString() const = 0;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
55
src/grammars/altarica/domains/DiscreteDomain.hh
Normal file
55
src/grammars/altarica/domains/DiscreteDomain.hh
Normal file
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_DISCRETE_DOMAIN_H_
|
||||
#define ALTA_DISCRETE_DOMAIN_H_
|
||||
|
||||
#include "Domain.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Value;
|
||||
|
||||
class DiscreteDomain : public Domain {
|
||||
|
||||
protected :
|
||||
unsigned int arity_;
|
||||
public:
|
||||
virtual unsigned int getArity() const {return arity_;}
|
||||
virtual int getMin() const = 0;
|
||||
virtual int getMax() const = 0;
|
||||
virtual unsigned int index(std::string arg) const =0;
|
||||
virtual std::string text(unsigned int index) const = 0;
|
||||
// virtual std::vector<Variable*> * flatten(Variable* v) const = 0;
|
||||
virtual Value * toValue() const = 0;
|
||||
virtual Value * getValue(int i) = 0;
|
||||
virtual std::string toString() const = 0;
|
||||
virtual ~DiscreteDomain() {};
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
73
src/grammars/altarica/domains/Domain.cc
Normal file
73
src/grammars/altarica/domains/Domain.cc
Normal file
@@ -0,0 +1,73 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#include "Domain.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
std::string Domain::get_name() {
|
||||
if (name_.size() > 0)
|
||||
return name_[0];
|
||||
else return std::string("");
|
||||
}
|
||||
|
||||
bool Domain::alias(std::string name) {
|
||||
for (std::vector<std::string>::iterator nit = name_.begin();
|
||||
nit != name_.end(); ++nit) {
|
||||
if (name.compare(*nit) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Domain::set_name(std::string n) {
|
||||
name_.push_back(n);
|
||||
}
|
||||
|
||||
// Domain* Domain::findDomainInVector(std::vector<Domain*> vd, std::string *name) {
|
||||
// for (std::vector<Domain*>::iterator vdit = vd.begin();
|
||||
// vdit != vd.end(); ++vdit)
|
||||
// if ((*vdit)->alias(name))
|
||||
// return *vdit;
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
std::vector<Variable*> * Domain::flatten(Variable* v) const {
|
||||
std::vector<Variable*> * nv = new std::vector<Variable*>();
|
||||
nv->push_back(v);
|
||||
return nv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
63
src/grammars/altarica/domains/Domain.hh
Normal file
63
src/grammars/altarica/domains/Domain.hh
Normal file
@@ -0,0 +1,63 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_DOMAIN_H_
|
||||
#define ALTA_DOMAIN_H_
|
||||
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Variable;
|
||||
class Value;
|
||||
|
||||
class Domain {
|
||||
protected :
|
||||
std::vector<std::string> name_;
|
||||
public :
|
||||
virtual ~Domain() {};
|
||||
Domain () {}
|
||||
virtual unsigned int getArity() const = 0;
|
||||
virtual std::string get_name();
|
||||
bool alias(std::string name);
|
||||
void set_name(std::string n);
|
||||
static Domain* findDomainInVector(std::vector<Domain*>, std::string name);
|
||||
virtual std::vector<Variable*> * flatten(Variable* v) const;
|
||||
virtual Value * toValue() const = 0;
|
||||
virtual std::string toString() const = 0;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
35
src/grammars/altarica/domains/Domains.hh
Normal file
35
src/grammars/altarica/domains/Domains.hh
Normal file
@@ -0,0 +1,35 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_DOMAINS_HH
|
||||
#define ALTA_DOMAINS_HH
|
||||
#include "EnumDomain.hh"
|
||||
#include "RangeDomain.hh"
|
||||
#include "RealDomain.hh"
|
||||
#include "ArrayDomain.hh"
|
||||
#include "StructuredDomain.hh"
|
||||
#include "DiscreteDomain.hh"
|
||||
#include "PredefinedDomain.hh"
|
||||
#endif
|
||||
153
src/grammars/altarica/domains/EnumDomain.cc
Normal file
153
src/grammars/altarica/domains/EnumDomain.cc
Normal file
@@ -0,0 +1,153 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "EnumDomain.hh"
|
||||
#include "Values.hh"
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
EnumDomain::EnumDomain() {
|
||||
indexes = NULL;
|
||||
}
|
||||
|
||||
EnumDomain::EnumDomain(int nSymbols) {
|
||||
symbols.reserve(nSymbols);
|
||||
arity_ = nSymbols;
|
||||
}
|
||||
|
||||
void EnumDomain::addSymbol(std::string s) {
|
||||
// symbols.push_back(s);
|
||||
std::vector<std::string>::iterator i = symbols.begin();
|
||||
for (; i!= symbols.end() && s.compare(*i) > 0 ; ++i);
|
||||
symbols.insert(i, s);
|
||||
arity_ = symbols.size();
|
||||
}
|
||||
|
||||
void EnumDomain::addSymbols(std::vector<std::string> *sv) {
|
||||
for (std::vector<std::string>::iterator svit = sv->begin();
|
||||
svit != sv->end(); ++svit)
|
||||
addSymbol(*svit);
|
||||
}
|
||||
|
||||
unsigned int EnumDomain::index(std::string arg) const {
|
||||
// if (indexes == NULL) {
|
||||
// indexes = new std::map<std::string, int>();
|
||||
// int j = 0;
|
||||
// for (std::vector<std::string>::const_iterator i = symbols.begin();i!=symbols.end(); ++i)
|
||||
// (*indexes)[*i] = j++;
|
||||
// }
|
||||
// return (*indexes)[arg];
|
||||
unsigned int i=0;
|
||||
for (std::vector<std::string>::const_iterator sit = symbols.begin(); sit!=symbols.end(); ++sit) {
|
||||
if (sit->compare(arg) == 0)
|
||||
return i;
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
std::string EnumDomain::text(unsigned int index) const {
|
||||
std::string s;
|
||||
s+=symbols[index];
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Value * EnumDomain::toValue() const {
|
||||
return new ValueSymbol(this);
|
||||
}
|
||||
|
||||
int EnumDomain::getMin() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EnumDomain::getMax() const {
|
||||
return arity_-1;
|
||||
}
|
||||
|
||||
// Value * EnumDomain::getFixedValue(int i) {
|
||||
// return new FixedInt(i);
|
||||
// }
|
||||
|
||||
Value * EnumDomain::getValue(int i) {
|
||||
return new ValueInt(i);
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::string>* EnumDomain::getSymbols() const {
|
||||
return &symbols;
|
||||
}
|
||||
|
||||
std::string EnumDomain::toString() const {
|
||||
std::string s;
|
||||
s+= "{ ";
|
||||
for (std::vector<std::string>::const_iterator i = symbols.begin(); i!= symbols.end(); ++i) {
|
||||
s+=*i;
|
||||
s+=" ";
|
||||
}
|
||||
s+= "}";
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool EnumDomain::equals(const EnumDomain *d) const {
|
||||
if (d == this)
|
||||
return true;
|
||||
const std::vector<std::string> * os = d->getSymbols();
|
||||
if (os->size() != symbols.size())
|
||||
return false;
|
||||
for (std::vector<std::string>::const_iterator i = os->begin();
|
||||
i!= os->end(); ++i) {
|
||||
bool isIn = false;
|
||||
for (std::vector<std::string>::const_iterator j = symbols.begin();
|
||||
j!= symbols.end() && !isIn; ++j) {
|
||||
if (j->compare(*i) == 0)
|
||||
isIn = true;
|
||||
}
|
||||
if (!isIn)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
EnumDomain::~EnumDomain() {
|
||||
symbols.clear();
|
||||
}
|
||||
|
||||
bool EnumDomain::contains(const std::string s) const {
|
||||
for (std::vector<std::string>::const_iterator i = symbols.begin(); i!= symbols.end(); ++i)
|
||||
if (s.compare(*i)==0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
63
src/grammars/altarica/domains/EnumDomain.hh
Normal file
63
src/grammars/altarica/domains/EnumDomain.hh
Normal file
@@ -0,0 +1,63 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_ENUM_DOMAIN_H_
|
||||
#define ALTA_ENUM_DOMAIN_H_
|
||||
|
||||
#include "DiscreteDomain.hh"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class EnumDomain : public DiscreteDomain {
|
||||
|
||||
protected:
|
||||
std::vector<std::string> symbols;
|
||||
mutable std::map<std::string, int> *indexes;
|
||||
public:
|
||||
EnumDomain(int nSymbols);
|
||||
EnumDomain();
|
||||
const std::vector<std::string>* getSymbols() const;
|
||||
virtual unsigned int index(std::string arg) const;
|
||||
virtual std::string text(unsigned int index) const;
|
||||
void addSymbol(std::string s);
|
||||
void addSymbols(std::vector<std::string> * ss);
|
||||
// virtual std::vector<Variable*> * flatten(Variable* v) const;
|
||||
virtual Value * toValue() const;
|
||||
virtual int getMin() const;
|
||||
virtual int getMax() const;
|
||||
virtual Value * getValue(int i);
|
||||
virtual std::string toString() const ;
|
||||
bool contains(const std::string s) const;
|
||||
bool equals(const EnumDomain *d) const;
|
||||
virtual ~EnumDomain();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
146
src/grammars/altarica/domains/PredefinedDomain.cc
Normal file
146
src/grammars/altarica/domains/PredefinedDomain.cc
Normal file
@@ -0,0 +1,146 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "PredefinedDomain.hh"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Variable.hh"
|
||||
#include "Values.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
PredefinedDomain::PredefinedDomain(bool type) {
|
||||
if (type) {
|
||||
bool_ = true;
|
||||
arity_ = 2;
|
||||
} else {
|
||||
bool_ = false;
|
||||
arity_ = UINT32_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int PredefinedDomain::index(std::string arg) const {
|
||||
if (bool_) {
|
||||
if (arg == "TRUE" || arg == "true")
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
} else {
|
||||
return (atoi(arg.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
std::string PredefinedDomain::text(unsigned int index) const {
|
||||
std::string s;
|
||||
if (bool_) {
|
||||
if (index == 1)
|
||||
s+="true";
|
||||
else
|
||||
s+="false";
|
||||
} else {
|
||||
std::string *s = new std::string();
|
||||
s +=index;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Value * PredefinedDomain::toValue() const {
|
||||
if (bool_)
|
||||
return new ValueBool();
|
||||
else
|
||||
return new ValueInt();
|
||||
}
|
||||
|
||||
|
||||
int PredefinedDomain::getMin() const {
|
||||
if (bool_)
|
||||
return 0;
|
||||
else
|
||||
return INT32_MIN;
|
||||
}
|
||||
|
||||
int PredefinedDomain::getMax() const {
|
||||
if (bool_)
|
||||
return 1;
|
||||
else
|
||||
return INT32_MAX;
|
||||
}
|
||||
|
||||
int PredefinedDomain::min(bool b) {
|
||||
if (b)
|
||||
return 0;
|
||||
else
|
||||
return INT32_MIN;
|
||||
}
|
||||
int PredefinedDomain::max(bool b) {
|
||||
if (b)
|
||||
return 1;
|
||||
else
|
||||
return INT32_MAX;
|
||||
}
|
||||
|
||||
|
||||
// Value * PredefinedDomain::getFixedValue(int i) {
|
||||
// if (bool_) {
|
||||
// if (i == 0)
|
||||
// return new FixedBool(true);
|
||||
// else
|
||||
// return new FixedBool(false);
|
||||
// } else {
|
||||
// return new FixedInt(i);
|
||||
// }
|
||||
// }
|
||||
|
||||
Value * PredefinedDomain::getValue(int i) {
|
||||
if (bool_) {
|
||||
if (i == 1)
|
||||
return new ValueBool(true,false);
|
||||
else
|
||||
return new ValueBool(false,true);
|
||||
} else {
|
||||
return new ValueInt(i);
|
||||
}
|
||||
}
|
||||
|
||||
std::string PredefinedDomain::toString() const {
|
||||
if (bool_)
|
||||
return "BOOL";
|
||||
else
|
||||
return "INTEGER";
|
||||
}
|
||||
|
||||
PredefinedDomain::~PredefinedDomain() {}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
59
src/grammars/altarica/domains/PredefinedDomain.hh
Normal file
59
src/grammars/altarica/domains/PredefinedDomain.hh
Normal file
@@ -0,0 +1,59 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_PREDEFINED_DOMAIN_H_
|
||||
#define ALTA_PREDEFINED_DOMAIN_H_
|
||||
|
||||
#include "DiscreteDomain.hh"
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class PredefinedDomain : public DiscreteDomain {
|
||||
|
||||
protected:
|
||||
bool bool_; //or int
|
||||
public:
|
||||
PredefinedDomain(bool type);
|
||||
virtual unsigned int index(std::string arg) const;
|
||||
virtual std::string text(unsigned int index) const;
|
||||
// virtual std::vector<Variable*> * flatten(Variable* v) const;
|
||||
virtual Value * toValue() const;
|
||||
virtual int getMin() const;
|
||||
virtual int getMax() const;
|
||||
virtual Value * getValue(int i);
|
||||
virtual std::string toString() const ;
|
||||
static int min(bool);
|
||||
static int max(bool);
|
||||
bool isBooleanDomain() const {return bool_;}
|
||||
virtual ~PredefinedDomain();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
85
src/grammars/altarica/domains/RangeDomain.cc
Normal file
85
src/grammars/altarica/domains/RangeDomain.cc
Normal file
@@ -0,0 +1,85 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "RangeDomain.hh"
|
||||
#include "Values.hh"
|
||||
#include <stdlib.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
RangeDomain::RangeDomain(int inf, int sup):
|
||||
inf_(inf), sup_(sup) {
|
||||
arity_ = sup-inf+1;
|
||||
}
|
||||
|
||||
unsigned int RangeDomain::index(std::string arg) const {
|
||||
return (atoi(arg.c_str()));
|
||||
}
|
||||
|
||||
std::string RangeDomain::text(unsigned int index) const {
|
||||
std::string s;
|
||||
s += index;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Value * RangeDomain::toValue() const {
|
||||
return new ValueInt(this);
|
||||
}
|
||||
|
||||
int RangeDomain::getMin() const {
|
||||
return inf_;
|
||||
}
|
||||
|
||||
int RangeDomain::getMax() const {
|
||||
return sup_;
|
||||
}
|
||||
// Value * RangeDomain::getFixedValue(int i) {
|
||||
// return new FixedInt(i);
|
||||
// }
|
||||
|
||||
Value * RangeDomain::getValue(int i) {
|
||||
ValueInt * oi = new ValueInt();
|
||||
oi->setValue(i);
|
||||
return oi;
|
||||
}
|
||||
std::string RangeDomain::toString() const {
|
||||
std::stringstream ss;
|
||||
// std::string s;
|
||||
ss<< "[";
|
||||
ss<<inf_;
|
||||
ss<<",";
|
||||
ss<<sup_;
|
||||
ss<<"]";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
55
src/grammars/altarica/domains/RangeDomain.hh
Normal file
55
src/grammars/altarica/domains/RangeDomain.hh
Normal file
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_RANGE_DOMAIN_H_
|
||||
#define ALTA_RANGE_DOMAIN_H_
|
||||
|
||||
#include "DiscreteDomain.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class RangeDomain : public DiscreteDomain {
|
||||
|
||||
protected:
|
||||
int inf_;
|
||||
int sup_;
|
||||
public:
|
||||
RangeDomain(int inf, int sup);
|
||||
virtual unsigned int index(std::string arg) const;
|
||||
virtual std::string text(unsigned int index) const;
|
||||
// virtual std::vector<Variable*> * flatten(Variable* v) const;
|
||||
virtual Value * toValue() const;
|
||||
virtual int getMin() const;
|
||||
virtual int getMax() const;
|
||||
virtual Value * getValue(int i);
|
||||
virtual std::string toString() const;
|
||||
virtual ~RangeDomain() {};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
79
src/grammars/altarica/domains/RealDomain.cc
Normal file
79
src/grammars/altarica/domains/RealDomain.cc
Normal file
@@ -0,0 +1,79 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "RealDomain.hh"
|
||||
#include "DiscreteDomain.hh"
|
||||
#include "values/ValueReal.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
RealDomain::RealDomain(const DiscreteDomain *d) :Domain(){
|
||||
if (d != NULL)
|
||||
di = boost::icl::continuous_interval<double>(d->getMin(), d->getMax(), boost::icl::interval_bounds::closed());
|
||||
else
|
||||
di = boost::icl::continuous_interval<double>(std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), boost::icl::interval_bounds::closed());
|
||||
}
|
||||
|
||||
|
||||
RealDomain::RealDomain() :Domain(){
|
||||
di = boost::icl::continuous_interval<double>(std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), boost::icl::interval_bounds::closed());
|
||||
}
|
||||
|
||||
RealDomain::RealDomain(double inf, double sup, bool openleft, bool openright) {
|
||||
if (openright)
|
||||
if (openleft)
|
||||
di = boost::icl::continuous_interval<double>(inf, sup, boost::icl::interval_bounds::open());
|
||||
else
|
||||
di = boost::icl::continuous_interval<double>(inf, sup, boost::icl::interval_bounds::right_open());
|
||||
else
|
||||
if (openleft)
|
||||
di = boost::icl::continuous_interval<double>(inf, sup, boost::icl::interval_bounds::left_open());
|
||||
else
|
||||
di = boost::icl::continuous_interval<double>(inf, sup, boost::icl::interval_bounds::closed());
|
||||
}
|
||||
|
||||
|
||||
Value * RealDomain::toValue() const {
|
||||
return new ValueReal(this);
|
||||
}
|
||||
|
||||
std::string RealDomain::toString() const {
|
||||
std::stringstream ss;
|
||||
ss << di;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
unsigned int RealDomain::getArity() const {
|
||||
if (di.upper() == di.lower() &&
|
||||
di.bounds() == boost::icl::interval_bounds::closed())
|
||||
return 1;
|
||||
return std::numeric_limits<unsigned int>::infinity();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
59
src/grammars/altarica/domains/RealDomain.hh
Normal file
59
src/grammars/altarica/domains/RealDomain.hh
Normal file
@@ -0,0 +1,59 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_REAL_DOMAIN_H_
|
||||
#define ALTA_REAL_DOMAIN_H_
|
||||
|
||||
#include "Domain.hh"
|
||||
#include <boost/icl/continuous_interval.hpp>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class DiscreteDomain;
|
||||
|
||||
class RealDomain : public Domain {
|
||||
|
||||
protected:
|
||||
boost::icl::continuous_interval<double> di;
|
||||
public:
|
||||
RealDomain(const DiscreteDomain *d);
|
||||
RealDomain();
|
||||
RealDomain(double inf, double sup,
|
||||
bool openleft=false,
|
||||
bool openright=false);
|
||||
virtual ~RealDomain() {};
|
||||
// virtual std::vector<Variable*> * flatten(Variable* v) const = 0;
|
||||
virtual Value * toValue() const;
|
||||
virtual std::string toString() const;
|
||||
virtual unsigned int getArity() const;
|
||||
const boost::icl::continuous_interval<double>& getBI() const {return di;}
|
||||
double getMin() const {return di.lower();}
|
||||
double getMax() const {return di.upper();}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
122
src/grammars/altarica/domains/StructuredDomain.cc
Normal file
122
src/grammars/altarica/domains/StructuredDomain.cc
Normal file
@@ -0,0 +1,122 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "StructuredDomain.hh"
|
||||
#include "Variable.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
StructuredDomain::StructuredDomain() {
|
||||
arity_ = 1;
|
||||
}
|
||||
|
||||
void StructuredDomain::addDomains(std::vector<std::string> *domainNames, Domain* domain) {
|
||||
for (std::vector<std::string>::iterator idit = domainNames->begin(); idit!=domainNames->end(); ++idit)
|
||||
addDomain(*idit, domain);
|
||||
}
|
||||
|
||||
void StructuredDomain::addDomain(std::string domainName, Domain* domain) {
|
||||
if (sdomain_.find(domainName) != sdomain_.end())
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error("bad identifier for domain name"));
|
||||
sdomain_[domainName] = domain;
|
||||
arity_ *= domain->getArity();
|
||||
}
|
||||
|
||||
void StructuredDomain::addMyDomainsTo(StructuredDomain * sd) {
|
||||
for (std::map<std::string, Domain*>::iterator dit = sdomain_.begin();
|
||||
dit != sdomain_.end(); ++dit)
|
||||
sd->addDomain((*dit).first,(*dit).second);
|
||||
}
|
||||
|
||||
|
||||
unsigned int StructuredDomain::index(std::string arg) const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("index asked on a Structured domain")));
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string StructuredDomain::text(unsigned int index) const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("text asked on a Structured domain")));
|
||||
return "text associated to a structured domain";
|
||||
}
|
||||
|
||||
Value * StructuredDomain::toValue() const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("toValue asked on a Structured domain")));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int StructuredDomain::getMin() const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getMin asked on a Structured domain")));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int StructuredDomain::getMax() const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getMax asked on a Structured domain")));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Value * StructuredDomain::getFixedValue(int i) {
|
||||
// BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getFixedValue(i) asked on a structDomain")));
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
Value * StructuredDomain::getValue(int i) {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getFixedValue(i) asked on a structDomain")));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::vector<Variable*> * StructuredDomain::flatten(Variable* v) const {
|
||||
std::vector<Variable*> * nvv = new std::vector<Variable*>();
|
||||
|
||||
for (std::map<std::string, Domain*>::const_iterator i = sdomain_.begin(); i != sdomain_.end(); ++i) {
|
||||
std::vector<Variable*> * fv = (*i).second->flatten(v);
|
||||
for (std::vector<Variable*>::iterator fvi= fv->begin(); fvi != fv->end(); ++fvi) {
|
||||
Variable * nv = (*fvi)->clone();
|
||||
nv->addToMASecond((*i).first);
|
||||
nvv->push_back(nv);
|
||||
}
|
||||
delete(fv);
|
||||
}
|
||||
return nvv;
|
||||
}
|
||||
|
||||
std::string StructuredDomain::toString() const {
|
||||
return "STRUCTURED";
|
||||
}
|
||||
|
||||
StructuredDomain::~StructuredDomain() {
|
||||
sdomain_.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
75
src/grammars/altarica/domains/StructuredDomain.hh
Normal file
75
src/grammars/altarica/domains/StructuredDomain.hh
Normal file
@@ -0,0 +1,75 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_STRUCT_DOMAIN_H_
|
||||
#define ALTA_STRUCT_DOMAIN_H_
|
||||
|
||||
#include "DiscreteDomain.hh"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
//! Structured Domain
|
||||
/*!
|
||||
Stucture pour stocker les types complexes d'altarica
|
||||
*/
|
||||
class StructuredDomain : public DiscreteDomain {
|
||||
|
||||
protected:
|
||||
|
||||
//! les types sont stockes dans une map id->type
|
||||
std::map<std::string, Domain*> sdomain_;
|
||||
|
||||
public:
|
||||
|
||||
//! constructeur qui ne fait rien
|
||||
StructuredDomain();
|
||||
|
||||
//! ajout des domaines, cas ou on a plusieurs id pour 1 domaine
|
||||
void addDomains(std::vector<std::string>* domainNames, Domain* domain);
|
||||
|
||||
//! ajout d'un domaine au type structure
|
||||
void addDomain(std::string domainName, Domain *domain);
|
||||
|
||||
void addMyDomainsTo(StructuredDomain * sd);
|
||||
|
||||
//! calcule un index. attention aux debordements
|
||||
virtual unsigned int index(std::string arg) const;
|
||||
virtual std::string text(unsigned int index) const;
|
||||
|
||||
virtual std::vector<Variable*> * flatten(Variable* v) const;
|
||||
virtual Value * toValue() const;
|
||||
virtual int getMin() const;
|
||||
virtual int getMax() const;
|
||||
virtual Value * getValue(int i);
|
||||
virtual std::string toString() const;
|
||||
virtual ~StructuredDomain();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
70
src/grammars/altarica/expressions/EvaluationVisitor.hh
Normal file
70
src/grammars/altarica/expressions/EvaluationVisitor.hh
Normal file
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
// This file is part of EPOCH.
|
||||
// File: EvaluationVisitor.hh
|
||||
// Author: Xavier Pucel
|
||||
// Contact: xavier.pucel@onera.fr
|
||||
//
|
||||
// EPOCH is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// EPOCH is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with EPOCH. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef EVALUATION_VISITOR_HH
|
||||
#define EVALUATION_VISITOR_HH
|
||||
|
||||
#include "Visitor.hh"
|
||||
|
||||
namespace epoch {
|
||||
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaState;
|
||||
class Node;
|
||||
class AltaricaModel;
|
||||
|
||||
class EvaluationVisitor: public Visitor {
|
||||
protected:
|
||||
AltaricaState *state_;
|
||||
const AltaricaModel *amodel_;
|
||||
const Node *node_;
|
||||
|
||||
EvaluationVisitor(const AltaricaModel *am, AltaricaState *s, const Node *n):
|
||||
state_(s), amodel_(am), node_(n) {}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
56
src/grammars/altarica/expressions/Expression.cc
Normal file
56
src/grammars/altarica/expressions/Expression.cc
Normal file
@@ -0,0 +1,56 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Expression.hh"
|
||||
#include "ExpressionEvaluator.hh"
|
||||
#include "ExpressionEvaluatorLandmark.hh"
|
||||
#include "ExpressionInfoVar.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
Value * Expression::evaluate(const AltaricaModel *am, AltaricaState *s, const Node*n, bool assert) const {
|
||||
ExpressionEvaluator evf(am, s,n,assert);
|
||||
accept(&evf);
|
||||
Value * fv = evf.getValue();
|
||||
return fv;
|
||||
}
|
||||
|
||||
Value * Expression::evaluateLM(const AltaricaModel *am, LandmarkState *lms, const Node*n, bool assert) const {
|
||||
ExpressionEvaluatorLandmark evlm(am, lms,n,assert);
|
||||
accept(&evlm);
|
||||
Value * fv = evlm.getValue();
|
||||
return fv;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Variable*> * Expression::infoVars(const AltaricaModel *am, const Node *n, bool flow, bool computed) const {
|
||||
ExpressionInfoVar eiv(flow, computed, am, NULL, n);
|
||||
accept(&eiv);
|
||||
std::vector<Variable*> * vars = eiv.getVars();
|
||||
return vars;
|
||||
}
|
||||
73
src/grammars/altarica/expressions/Expression.hh
Normal file
73
src/grammars/altarica/expressions/Expression.hh
Normal file
@@ -0,0 +1,73 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_H_
|
||||
#define ALTA_EXPRESSION_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Visitor.hh"
|
||||
#include "../Node.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Visitor;
|
||||
class AltaricaState;
|
||||
class LandmarkState;
|
||||
class Node;
|
||||
class Value;
|
||||
class Variable;
|
||||
class AltaricaModel;
|
||||
|
||||
class Expression {
|
||||
|
||||
|
||||
protected:
|
||||
Expression() {}
|
||||
|
||||
|
||||
public:
|
||||
virtual void accept(Visitor * v) const = 0;
|
||||
|
||||
virtual Expression * clone() const = 0;
|
||||
|
||||
virtual ~Expression() {};
|
||||
|
||||
virtual std::string toString() const = 0;
|
||||
virtual std::string toString(const Node *n, const AltaricaModel& am) const = 0;
|
||||
virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const = 0;
|
||||
|
||||
Value * evaluate(const AltaricaModel *am, AltaricaState *s, const Node* n, bool assert = false) const;
|
||||
Value * evaluateLM(const AltaricaModel *am, LandmarkState *lms, const Node* n, bool assert = false) const;
|
||||
std::vector<Variable*> * infoVars(const AltaricaModel *am, Node const * const n, bool flow, bool computed) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
85
src/grammars/altarica/expressions/ExpressionADD.cc
Normal file
85
src/grammars/altarica/expressions/ExpressionADD.cc
Normal file
@@ -0,0 +1,85 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionADD.hh"
|
||||
#include "Visitor.hh"
|
||||
#include "ExpressionMUL.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
ExpressionADD * ExpressionADD::clone() const {
|
||||
ExpressionADD * nea = new ExpressionADD(left_->clone(), right_->clone());
|
||||
if (add_type_ == 0)
|
||||
nea->setPlus();
|
||||
else
|
||||
nea ->setMinus();
|
||||
return nea;
|
||||
|
||||
}
|
||||
|
||||
std::string ExpressionADD::toString() const {
|
||||
std::string s;
|
||||
s+= left_->toString();
|
||||
if (add_type_ == 0)
|
||||
s+= " + ";
|
||||
else
|
||||
s+= " - ";
|
||||
s+= right_->toString();
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionADD::toString(const Node *n, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= left_->toString(n, am);
|
||||
if (add_type_ == 0)
|
||||
s+= " + ";
|
||||
else
|
||||
s+= " - ";
|
||||
s+= right_->toString(n, am);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
std::string ExpressionADD::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= left_->toString(n, f, am);
|
||||
if (add_type_ == 0)
|
||||
s+= " + ";
|
||||
else
|
||||
s+= " - ";
|
||||
s+= right_->toString(n, f, am);
|
||||
return s;
|
||||
}
|
||||
ExpressionADD::~ExpressionADD() {
|
||||
delete left_;
|
||||
delete right_;
|
||||
}
|
||||
|
||||
void ExpressionADD::accept(Visitor* v) const {
|
||||
v->visitADD(this);
|
||||
}
|
||||
76
src/grammars/altarica/expressions/ExpressionADD.hh
Normal file
76
src/grammars/altarica/expressions/ExpressionADD.hh
Normal file
@@ -0,0 +1,76 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_ADD_H_
|
||||
#define ALTA_EXPRESSION_ADD_H_
|
||||
|
||||
|
||||
#include "ExpressionARITH.hh"
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class ExpressionMUL;
|
||||
|
||||
class ExpressionADD : public ExpressionARITH {
|
||||
|
||||
private:
|
||||
|
||||
ExpressionADD * left_;
|
||||
ExpressionMUL * right_;
|
||||
short add_type_;
|
||||
|
||||
|
||||
public:
|
||||
ExpressionADD(): left_(NULL), right_(NULL) {}
|
||||
virtual ~ExpressionADD();
|
||||
ExpressionADD(ExpressionADD *l, ExpressionMUL *r) : ExpressionARITH(), left_(l), right_(r) {}
|
||||
|
||||
|
||||
void setPlus() {add_type_ = 0;}
|
||||
void setMinus() {add_type_ = 1;}
|
||||
const ExpressionADD * getLeft() const {return left_;}
|
||||
const ExpressionMUL * getRight() const {return right_;}
|
||||
|
||||
short getType() const {return add_type_;}
|
||||
|
||||
virtual ExpressionADD * clone() const;
|
||||
|
||||
virtual void accept(Visitor* v) const;
|
||||
virtual std::string toString() const;
|
||||
virtual std::string toString(const Node *n, const AltaricaModel& am) const ;
|
||||
virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const ;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
54
src/grammars/altarica/expressions/ExpressionAND.cc
Normal file
54
src/grammars/altarica/expressions/ExpressionAND.cc
Normal file
@@ -0,0 +1,54 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionAND.hh"
|
||||
#include "ExpressionLOG.hh"
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
ExpressionAND::~ExpressionAND() {
|
||||
delete left_;
|
||||
delete right_;
|
||||
}
|
||||
|
||||
ExpressionAND * ExpressionAND::clone() const {
|
||||
return new ExpressionAND(left_->clone(), right_->clone());
|
||||
}
|
||||
|
||||
std::string ExpressionAND::toString() const {
|
||||
return left_->toString() + " and " + right_->toString();
|
||||
}
|
||||
|
||||
std::string ExpressionAND::toString(const Node *n, const AltaricaModel& am) const {
|
||||
return left_->toString(n, am) + " and " + right_->toString(n, am);
|
||||
}
|
||||
|
||||
std::string ExpressionAND::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
|
||||
return left_->toString(n, f, am) + " and " + right_->toString(n, f, am);
|
||||
}
|
||||
71
src/grammars/altarica/expressions/ExpressionAND.hh
Normal file
71
src/grammars/altarica/expressions/ExpressionAND.hh
Normal file
@@ -0,0 +1,71 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_AND_H_
|
||||
#define ALTA_EXPRESSION_AND_H_
|
||||
|
||||
|
||||
#include "ExpressionOR.hh"
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class ExpressionLOG;
|
||||
|
||||
class ExpressionAND : public ExpressionOR {
|
||||
|
||||
private:
|
||||
|
||||
ExpressionAND * left_;
|
||||
ExpressionLOG * right_;
|
||||
|
||||
|
||||
public:
|
||||
ExpressionAND(): left_(NULL), right_(NULL) {}
|
||||
virtual ~ExpressionAND();
|
||||
ExpressionAND(ExpressionAND *l, ExpressionLOG *r) : ExpressionOR(), left_(l), right_(r) {}
|
||||
|
||||
|
||||
const ExpressionAND * getLeft() const {return left_;}
|
||||
const ExpressionLOG * getRight() const {return right_;}
|
||||
|
||||
virtual ExpressionAND * clone() const;
|
||||
|
||||
virtual void accept(Visitor* v) const {v->visitAND(this);}
|
||||
virtual std::string toString() const;
|
||||
virtual std::string toString(const Node *n, const AltaricaModel& am) const;
|
||||
virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
91
src/grammars/altarica/expressions/ExpressionARITH.cc
Normal file
91
src/grammars/altarica/expressions/ExpressionARITH.cc
Normal file
@@ -0,0 +1,91 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionARITH.hh"
|
||||
#include "ExpressionADD.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
|
||||
ExpressionARITH * ExpressionARITH::clone() const {
|
||||
ExpressionARITH * nea = new ExpressionARITH(left_->clone(), right_->clone());
|
||||
switch (arith_type_) {
|
||||
case 0: nea->setInf(); break;
|
||||
case 1: nea->setSup(); break;
|
||||
case 2: nea->setInfEq(); break;
|
||||
case 3: nea->setSupEq(); break;
|
||||
}
|
||||
return nea;
|
||||
}
|
||||
|
||||
|
||||
std::string ExpressionARITH::toString() const {
|
||||
std::string s;
|
||||
s+= left_->toString();
|
||||
switch (arith_type_) {
|
||||
case 0: s+= " < "; break;
|
||||
case 1: s+= " > "; break;
|
||||
case 2: s+= " <= "; break;
|
||||
case 3: s+= " >= "; break;
|
||||
}
|
||||
s+= right_->toString();
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionARITH::toString(const Node *n, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= left_->toString(n, am);
|
||||
switch (arith_type_) {
|
||||
case 0: s+= " < "; break;
|
||||
case 1: s+= " > "; break;
|
||||
case 2: s+= " <= "; break;
|
||||
case 3: s+= " >= "; break;
|
||||
}
|
||||
s+= right_->toString(n, am);
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionARITH::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= left_->toString(n, f, am);
|
||||
switch (arith_type_) {
|
||||
case 0: s+= " < "; break;
|
||||
case 1: s+= " > "; break;
|
||||
case 2: s+= " <= "; break;
|
||||
case 3: s+= " >= "; break;
|
||||
}
|
||||
s+= right_->toString(n, f, am);
|
||||
return s;
|
||||
}
|
||||
|
||||
ExpressionARITH::~ExpressionARITH() {
|
||||
delete left_;
|
||||
delete right_;
|
||||
}
|
||||
|
||||
80
src/grammars/altarica/expressions/ExpressionARITH.hh
Normal file
80
src/grammars/altarica/expressions/ExpressionARITH.hh
Normal file
@@ -0,0 +1,80 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_ARITH_H_
|
||||
#define ALTA_EXPRESSION_ARITH_H_
|
||||
|
||||
|
||||
#include "ExpressionLOG.hh"
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class ExpressionADD;
|
||||
|
||||
class ExpressionARITH : public ExpressionLOG {
|
||||
|
||||
private:
|
||||
|
||||
ExpressionARITH * left_;
|
||||
ExpressionADD * right_;
|
||||
short arith_type_;
|
||||
|
||||
|
||||
public:
|
||||
ExpressionARITH(): left_(NULL), right_(NULL) {}
|
||||
virtual ~ExpressionARITH();
|
||||
ExpressionARITH(ExpressionARITH *l, ExpressionADD *r) : ExpressionLOG(), left_(l), right_(r) {}
|
||||
|
||||
|
||||
|
||||
void setInf() {arith_type_ = 0;}
|
||||
void setSup() {arith_type_ = 1;}
|
||||
void setInfEq() {arith_type_ = 2;}
|
||||
void setSupEq() {arith_type_ = 3;}
|
||||
|
||||
const ExpressionARITH * getLeft() const {return left_;}
|
||||
const ExpressionADD * getRight() const {return right_;}
|
||||
short getType() const {return arith_type_;}
|
||||
|
||||
|
||||
virtual ExpressionARITH * clone() const;
|
||||
|
||||
virtual void accept(Visitor* v) const {v->visitARITH(this);}
|
||||
virtual std::string toString() const;
|
||||
virtual std::string toString(const Node *n, const AltaricaModel& am) const;
|
||||
virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
61
src/grammars/altarica/expressions/ExpressionATOMIC.hh
Normal file
61
src/grammars/altarica/expressions/ExpressionATOMIC.hh
Normal file
@@ -0,0 +1,61 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_ATOMIC_H_
|
||||
#define ALTA_EXPRESSION_ATOMIC_H_
|
||||
|
||||
|
||||
#include "ExpressionUNARY.hh"
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class ExpressionATOMIC : public ExpressionUNARY {
|
||||
|
||||
private:
|
||||
|
||||
|
||||
public:
|
||||
ExpressionATOMIC(){}
|
||||
virtual ~ExpressionATOMIC() {}
|
||||
|
||||
virtual ExpressionATOMIC * clone() const = 0;
|
||||
|
||||
virtual void accept(Visitor* v) const=0;
|
||||
virtual std::string toString() const = 0;
|
||||
std::string toString(const Node *n, const AltaricaModel& am) const {return toString(); }
|
||||
std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {return toString(); }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
47
src/grammars/altarica/expressions/ExpressionBOOLCONSTANT.cc
Normal file
47
src/grammars/altarica/expressions/ExpressionBOOLCONSTANT.cc
Normal file
@@ -0,0 +1,47 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionBOOLCONSTANT.hh"
|
||||
#include "../Values.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
ExpressionBOOLCONSTANT::ExpressionBOOLCONSTANT(bool b)
|
||||
: ExpressionATOMIC(), b_(b) {
|
||||
ov = new ValueBool(b_, !b_);
|
||||
ov->own();
|
||||
}
|
||||
|
||||
ExpressionBOOLCONSTANT::~ExpressionBOOLCONSTANT() {
|
||||
Value::release(ov);
|
||||
}
|
||||
|
||||
void ExpressionBOOLCONSTANT::set(bool b) {
|
||||
b_ = b;
|
||||
Value::release(ov);
|
||||
ov = new ValueBool(b_, !b_);
|
||||
ov->own();
|
||||
}
|
||||
|
||||
70
src/grammars/altarica/expressions/ExpressionBOOLCONSTANT.hh
Normal file
70
src/grammars/altarica/expressions/ExpressionBOOLCONSTANT.hh
Normal file
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_BOOLCONSTANT_H_
|
||||
#define ALTA_EXPRESSION_BOOLCONSTANT_H_
|
||||
|
||||
|
||||
#include "ExpressionATOMIC.hh"
|
||||
#include "../values/ValueBool.hh"
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Value;
|
||||
|
||||
class ExpressionBOOLCONSTANT : public ExpressionATOMIC {
|
||||
|
||||
private:
|
||||
|
||||
bool b_;
|
||||
// FixedValue * fv;
|
||||
Value *ov;
|
||||
|
||||
public:
|
||||
ExpressionBOOLCONSTANT(): ov(NULL) {}
|
||||
virtual ~ExpressionBOOLCONSTANT();
|
||||
ExpressionBOOLCONSTANT(bool b);
|
||||
|
||||
void set(bool b);
|
||||
Value * get() const {return ov;}
|
||||
|
||||
|
||||
virtual ExpressionBOOLCONSTANT * clone() const {return new ExpressionBOOLCONSTANT(b_);}
|
||||
|
||||
virtual void accept(Visitor* v) const { v->visitBOOLCONSTANT(this);}
|
||||
virtual std::string toString() const { return b_? "true": "false";}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
70
src/grammars/altarica/expressions/ExpressionCARD.cc
Normal file
70
src/grammars/altarica/expressions/ExpressionCARD.cc
Normal file
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionCARD.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
ExpressionCARD * ExpressionCARD::clone() const {
|
||||
ExpressionCARD* nec = new ExpressionCARD();
|
||||
for (std::vector<Expression*>::const_iterator i = exprs_.begin(); i!= exprs_.end(); ++i)
|
||||
nec->addExpr((*i)->clone());
|
||||
return nec;
|
||||
}
|
||||
|
||||
|
||||
std::string ExpressionCARD::toString() const {
|
||||
std::string s;
|
||||
s+= "CARD (";
|
||||
for (std::vector<Expression*>::const_iterator i = exprs_.begin(); i!= exprs_.end(); ++i)
|
||||
s+= (*i)->toString()+ ",";
|
||||
s+= ")";
|
||||
return s;
|
||||
}
|
||||
std::string ExpressionCARD::toString(const Node *n, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= "CARD (";
|
||||
for (std::vector<Expression*>::const_iterator i = exprs_.begin(); i!= exprs_.end(); ++i) {
|
||||
s+= n->toFiacre();
|
||||
s+= (*i)->toString(n, am)+ ",";
|
||||
}
|
||||
s+= ")";
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionCARD::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= "CARD (";
|
||||
for (std::vector<Expression*>::const_iterator i = exprs_.begin(); i!= exprs_.end(); ++i) {
|
||||
s+= f->first + "&" + n->toFiacre();
|
||||
s+= (*i)->toString(n, f, am)+ ",";
|
||||
}
|
||||
s+= ")";
|
||||
return s;
|
||||
}
|
||||
66
src/grammars/altarica/expressions/ExpressionCARD.hh
Normal file
66
src/grammars/altarica/expressions/ExpressionCARD.hh
Normal file
@@ -0,0 +1,66 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_CARD_H_
|
||||
#define ALTA_EXPRESSION_CARD_H_
|
||||
|
||||
|
||||
#include "ExpressionATOMIC.hh"
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class ExpressionCARD : public ExpressionATOMIC {
|
||||
|
||||
private:
|
||||
std::vector<Expression*> exprs_;
|
||||
|
||||
public:
|
||||
ExpressionCARD(): exprs_() {}
|
||||
virtual ~ExpressionCARD() { exprs_.clear();}
|
||||
|
||||
void addExpr(Expression *e) {exprs_.push_back(e);}
|
||||
const std::vector<Expression*> *getExprs() const {return &exprs_;}
|
||||
|
||||
virtual ExpressionCARD * clone() const;
|
||||
|
||||
virtual void accept(Visitor* v) const {v->visitCARD(this);}
|
||||
virtual std::string toString() const;
|
||||
virtual std::string toString(const Node *n, const AltaricaModel& am) const;
|
||||
virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const;
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
144
src/grammars/altarica/expressions/ExpressionCASE.cc
Normal file
144
src/grammars/altarica/expressions/ExpressionCASE.cc
Normal file
@@ -0,0 +1,144 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionCASE.hh"
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
void ExpressionCASE::addCase(Expression * c, Expression* t) {
|
||||
cond_.push_back(c);
|
||||
then_.push_back(t);
|
||||
}
|
||||
|
||||
void ExpressionCASE::addElse(Expression * t) {
|
||||
else_ = t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ExpressionCASE * ExpressionCASE::clone() const {
|
||||
ExpressionCASE * nec = new ExpressionCASE();
|
||||
typename std::vector<Expression*>::const_iterator i = cond_.begin();
|
||||
typename std::vector<Expression*>::const_iterator j = then_.begin();
|
||||
for (; i!= cond_.end(); ++i, ++j)
|
||||
nec->addCase((*i)->clone(), (*j)->clone());
|
||||
if (else_ != NULL)
|
||||
nec->addElse(else_->clone());
|
||||
return nec;
|
||||
}
|
||||
|
||||
|
||||
std::string ExpressionCASE::toString() const {
|
||||
std::string s;
|
||||
s+= "case\n";
|
||||
std::vector<Expression*>::const_iterator ci = cond_.begin();
|
||||
std::vector<Expression*>::const_iterator ti = then_.begin();
|
||||
|
||||
for (; ci != cond_.end(); ++ci, ++ti)
|
||||
s+= (*ci)->toString() + " -> " + (*ti)->toString() + "\n";
|
||||
if (else_ != NULL)
|
||||
s+= " else: " + else_->toString();
|
||||
s+= " end";
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionCASE::toString(const Node *n, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= "case\n";
|
||||
std::vector<Expression*>::const_iterator ci = cond_.begin();
|
||||
std::vector<Expression*>::const_iterator ti = then_.begin();
|
||||
|
||||
for (; ci != cond_.end(); ++ci, ++ti) {
|
||||
if (ci == cond_.begin())
|
||||
s += "\n";
|
||||
else
|
||||
s+= "|\n";
|
||||
|
||||
s += (*ci)->toString(n, am) + " -> " + (*ti)->toString(n, am) ;
|
||||
}
|
||||
if (else_ != NULL)
|
||||
s+= "|\n any -> " + else_->toString(n, am);
|
||||
s+= " end";
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionCASE::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= "case v of\n";
|
||||
std::vector<Expression*>::const_iterator ci = cond_.begin();
|
||||
std::vector<Expression*>::const_iterator ti = then_.begin();
|
||||
|
||||
for (; ci != cond_.end(); ++ci, ++ti) {
|
||||
if (ci == cond_.begin())
|
||||
s += "\t\t";
|
||||
else
|
||||
s+= "\n\t\t|";
|
||||
|
||||
s+= (*ci)->toString(n, f, am) + " -> " + (*ti)->toString(n, f, am);
|
||||
}
|
||||
if (else_ != NULL)
|
||||
s+= "\n\t\t| any -> " + else_->toString(n, f, am);
|
||||
|
||||
s+= " end";
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Example : t := case r|q -> 2
|
||||
/// p -> 5
|
||||
/// ==> if ( r|q ) then t := 2
|
||||
/// else if p then t := 5
|
||||
std::string ExpressionCASE::toFiacre(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am, std::string head) const {
|
||||
std::string s;
|
||||
std::vector<Expression*>::const_iterator ci = cond_.begin();
|
||||
std::vector<Expression*>::const_iterator ti = then_.begin();
|
||||
|
||||
for (; ci != cond_.end(); ++ci, ++ti) {
|
||||
if (ci != cond_.begin())
|
||||
s+= "\n\tels";
|
||||
|
||||
s+= "if " + (*ci)->toString(n, f, am) + " then " + head + (*ti)->toString(n, f, am);
|
||||
}
|
||||
if (else_ != NULL)
|
||||
s+= "\n\telse " + head + else_->toString(n, f, am);
|
||||
|
||||
s+= " end";
|
||||
return s;
|
||||
}
|
||||
|
||||
ExpressionCASE::~ExpressionCASE() {
|
||||
for (std::vector<Expression*>::iterator i =
|
||||
cond_.begin(); i!= cond_.end(); ++i)
|
||||
delete *i;
|
||||
for (std::vector<Expression*>::iterator i =
|
||||
then_.begin(); i!= then_.end(); ++i)
|
||||
delete *i;
|
||||
delete else_;
|
||||
}
|
||||
|
||||
74
src/grammars/altarica/expressions/ExpressionCASE.hh
Normal file
74
src/grammars/altarica/expressions/ExpressionCASE.hh
Normal file
@@ -0,0 +1,74 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_CASE_H_
|
||||
#define ALTA_EXPRESSION_CASE_H_
|
||||
|
||||
|
||||
#include "Expression.hh"
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class ExpressionCASE : public Expression {
|
||||
|
||||
private:
|
||||
|
||||
std::vector<Expression*> cond_;
|
||||
std::vector<Expression*> then_;
|
||||
Expression * else_;
|
||||
|
||||
|
||||
public:
|
||||
ExpressionCASE(): cond_(), then_(), else_(NULL) {}
|
||||
virtual ~ExpressionCASE();
|
||||
|
||||
void addCase(Expression * c, Expression* t);
|
||||
void addElse(Expression * t);
|
||||
|
||||
const std::vector<Expression*> * getConds() const {return &cond_;}
|
||||
const std::vector<Expression*> * getThens() const {return &then_;}
|
||||
const Expression* getElse() const {return else_;}
|
||||
|
||||
virtual ExpressionCASE * clone() const ;
|
||||
|
||||
virtual void accept(Visitor* v) const {v->visitCASE(this);}
|
||||
virtual std::string toString() const ;
|
||||
virtual std::string toString(const Node *n, const AltaricaModel& am) const ;
|
||||
virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const ;
|
||||
virtual std::string toFiacre(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am, std::string h) const ;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
68
src/grammars/altarica/expressions/ExpressionCONSTARRAY.cc
Normal file
68
src/grammars/altarica/expressions/ExpressionCONSTARRAY.cc
Normal file
@@ -0,0 +1,68 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionCONSTARRAY.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
ExpressionCONSTARRAY * ExpressionCONSTARRAY::clone() const {
|
||||
ExpressionCONSTARRAY * neca = new ExpressionCONSTARRAY();
|
||||
for (std::vector<Expression*>::const_iterator i = cexprs_.begin(); i!= cexprs_.end(); ++i)
|
||||
neca->addConst((*i)->clone());
|
||||
return neca;
|
||||
}
|
||||
|
||||
std::string ExpressionCONSTARRAY::toString() const {
|
||||
std::string s;
|
||||
s+= "[";
|
||||
for (std::vector<Expression*>::const_iterator i = cexprs_.begin(); i!= cexprs_.end(); ++i)
|
||||
s+= (*i)->toString() + ",";
|
||||
s+= "]";
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
std::string ExpressionCONSTARRAY::toString(const Node *n, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= "[";
|
||||
for (std::vector<Expression*>::const_iterator i = cexprs_.begin(); i!= cexprs_.end(); ++i)
|
||||
s+= n->toFiacre() + (*i)->toString() + ",";
|
||||
s+= "]";
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
std::string ExpressionCONSTARRAY::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= "[";
|
||||
for (std::vector<Expression*>::const_iterator i = cexprs_.begin(); i!= cexprs_.end(); ++i)
|
||||
s+= f->first + "&" + n->toFiacre() + (*i)->toString() + ",";
|
||||
s+= "]";
|
||||
return s;
|
||||
}
|
||||
64
src/grammars/altarica/expressions/ExpressionCONSTARRAY.hh
Normal file
64
src/grammars/altarica/expressions/ExpressionCONSTARRAY.hh
Normal file
@@ -0,0 +1,64 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_CONSTARRAY_H_
|
||||
#define ALTA_EXPRESSION_CONSTARRAY_H_
|
||||
|
||||
|
||||
#include "ExpressionATOMIC.hh"
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class ExpressionCONSTARRAY : public ExpressionATOMIC {
|
||||
|
||||
private:
|
||||
|
||||
std::vector<Expression*> cexprs_;
|
||||
|
||||
public:
|
||||
ExpressionCONSTARRAY(): cexprs_(){}
|
||||
virtual ~ExpressionCONSTARRAY() { cexprs_.clear();}
|
||||
|
||||
void addConst(Expression * e) {cexprs_.push_back(e);}
|
||||
|
||||
virtual ExpressionCONSTARRAY * clone() const;
|
||||
|
||||
virtual void accept(Visitor* v) const {v->visitCONSTARRAY(this);}
|
||||
virtual std::string toString() const;
|
||||
virtual std::string toString(const Node *n, const AltaricaModel& am) const;
|
||||
virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
97
src/grammars/altarica/expressions/ExpressionCONSTSTRUCT.cc
Normal file
97
src/grammars/altarica/expressions/ExpressionCONSTSTRUCT.cc
Normal file
@@ -0,0 +1,97 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionCONSTSTRUCT.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
ExpressionCONSTSTRUCT::ExpressionCONSTSTRUCT()
|
||||
: ExpressionATOMIC() {
|
||||
ids_ = new std::vector<std::string>();
|
||||
cexprs_ = new std::vector<Expression*>();
|
||||
}
|
||||
|
||||
void ExpressionCONSTSTRUCT::mergeAssigns(ExpressionCONSTSTRUCT * o) {
|
||||
std::vector<Expression*>::iterator i2 = o->getExprs()->begin();
|
||||
for ( std::vector<std::string>::iterator i = o->getIDs()->begin();
|
||||
i != o->getIDs()->end(); ++i) {
|
||||
addAssign(*i, *i2);
|
||||
i2++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ExpressionCONSTSTRUCT::~ExpressionCONSTSTRUCT() {
|
||||
ids_->clear();
|
||||
delete(ids_);
|
||||
cexprs_->clear();
|
||||
delete(cexprs_);
|
||||
}
|
||||
|
||||
ExpressionCONSTSTRUCT * ExpressionCONSTSTRUCT::clone() const {
|
||||
ExpressionCONSTSTRUCT * necs = new ExpressionCONSTSTRUCT();
|
||||
std::vector<std::string>::iterator si = ids_->begin();
|
||||
std::vector<Expression*>::iterator cei = cexprs_->begin();
|
||||
for (; si != ids_->end(); ++si, ++cei)
|
||||
necs->addAssign(*si, (*cei)->clone());
|
||||
return necs;
|
||||
}
|
||||
|
||||
|
||||
std::string ExpressionCONSTSTRUCT::toString() const {
|
||||
std::string s;
|
||||
s+= "[";
|
||||
std::vector<std::string>::const_iterator ii = ids_->begin();
|
||||
std::vector<Expression*>::const_iterator ei = cexprs_->begin();
|
||||
for (; ii!= ids_->end(); ++ii, ++ei)
|
||||
s+= *ii + ":" + (*ei)->toString() + ",";
|
||||
s+= "]";
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionCONSTSTRUCT::toString(const Node *n, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= "[";
|
||||
std::vector<std::string>::const_iterator ii = ids_->begin();
|
||||
std::vector<Expression*>::const_iterator ei = cexprs_->begin();
|
||||
for (; ii!= ids_->end(); ++ii, ++ei)
|
||||
s+= *ii + ":" + n->toFiacre() + (*ei)->toString() + ",";
|
||||
s+= "]";
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionCONSTSTRUCT::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= "[";
|
||||
std::vector<std::string>::const_iterator ii = ids_->begin();
|
||||
std::vector<Expression*>::const_iterator ei = cexprs_->begin();
|
||||
for (; ii!= ids_->end(); ++ii, ++ei)
|
||||
f->first + "&" + n->toFiacre() + (*ei)->toString() + ",";
|
||||
s+= "]";
|
||||
return s;
|
||||
}
|
||||
73
src/grammars/altarica/expressions/ExpressionCONSTSTRUCT.hh
Normal file
73
src/grammars/altarica/expressions/ExpressionCONSTSTRUCT.hh
Normal file
@@ -0,0 +1,73 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_CONSTSTRUCT_H_
|
||||
#define ALTA_EXPRESSION_CONSTSTRUCT_H_
|
||||
|
||||
|
||||
#include "ExpressionATOMIC.hh"
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
|
||||
class ExpressionCONSTSTRUCT : public ExpressionATOMIC {
|
||||
|
||||
private:
|
||||
std::vector<std::string> *ids_;
|
||||
std::vector<Expression *> *cexprs_;
|
||||
|
||||
public:
|
||||
ExpressionCONSTSTRUCT();
|
||||
virtual ~ExpressionCONSTSTRUCT();
|
||||
|
||||
void addAssign(std::string id, Expression * e) {ids_->push_back(id); cexprs_->push_back(e);}
|
||||
|
||||
void mergeAssigns(ExpressionCONSTSTRUCT * o);
|
||||
|
||||
std::vector<std::string> * getIDs() {return ids_;}
|
||||
std::vector<Expression *>* getExprs() {return cexprs_;}
|
||||
|
||||
|
||||
|
||||
virtual ExpressionCONSTSTRUCT * clone() const;
|
||||
|
||||
virtual void accept(Visitor* v) const {v->visitCONSTSTRUCT(this);}
|
||||
virtual std::string toString() const;
|
||||
virtual std::string toString(const Node *n, const AltaricaModel& am) const;
|
||||
virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
928
src/grammars/altarica/expressions/ExpressionEvaluator.cc
Normal file
928
src/grammars/altarica/expressions/ExpressionEvaluator.cc
Normal file
@@ -0,0 +1,928 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionEvaluator.hh"
|
||||
#include "Expressions.hh"
|
||||
#include "../AltaricaState.hh"
|
||||
#include "../AltaricaModel.hh"
|
||||
#include "../Assignment.hh"
|
||||
#include "../AltaricaException.hh"
|
||||
#include "../Constant.hh"
|
||||
#include "../Node.hh"
|
||||
#include "../Values.hh"
|
||||
#include "../Variable.hh"
|
||||
// #include <iostream>
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
Value * ExpressionEvaluator::visit(const Expression *e) {
|
||||
e->accept(this);
|
||||
Value *v = val_;
|
||||
if (v == NULL)
|
||||
std::cerr << "NULL value computed!!!\n";
|
||||
val_ = NULL;
|
||||
return v;
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::visitADD(const ExpressionADD *e){
|
||||
Value *lv = visit(e->getLeft());
|
||||
Value *rv = visit(e->getRight());
|
||||
|
||||
if (lv->isBool() || rv->isBool() || lv->isSymbol() || rv->isSymbol()) {
|
||||
Value::deleteIfPossible(lv);
|
||||
Value::deleteIfPossible(rv);
|
||||
throw AltaricaException("PLUS/MINUS asked on bools or symbols");
|
||||
}
|
||||
|
||||
|
||||
ValueInt * li = NULL;
|
||||
ValueReal *lr = NULL;
|
||||
ValueInt * ri = NULL;
|
||||
ValueReal *rr = NULL;
|
||||
if (lv->isInt())
|
||||
li = (ValueInt*) lv;
|
||||
else
|
||||
lr = (ValueReal*) lv;
|
||||
if (rv->isInt())
|
||||
ri = (ValueInt*) rv;
|
||||
else
|
||||
rr = (ValueReal*) rv;
|
||||
|
||||
if (lv->ro())
|
||||
if (li && ri)
|
||||
li = (ValueInt*) lv->clone();
|
||||
else if (lr)
|
||||
lr = (ValueReal*) lv->clone();
|
||||
else {
|
||||
lr = new ValueReal((double)li->toInt());
|
||||
Value::deleteIfPossible(li);
|
||||
li = NULL;
|
||||
}
|
||||
|
||||
if (e->getType() == 0) {
|
||||
if (li)
|
||||
li->add(ri);
|
||||
else
|
||||
if (ri)
|
||||
lr->add(new ValueReal((double)ri->toInt()));
|
||||
else
|
||||
lr->add(rr);
|
||||
} else {
|
||||
if (li)
|
||||
li->minus(ri);
|
||||
else
|
||||
if (ri)
|
||||
lr->minus(new ValueReal((double)ri->toInt()));
|
||||
else
|
||||
lr->minus(rr);
|
||||
}
|
||||
Value::deleteIfPossible(rv);
|
||||
if (li)
|
||||
val_ = li;
|
||||
else
|
||||
val_ = lr;
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::visitAND(const ExpressionAND *e){
|
||||
Value * lv = visit(e->getLeft());
|
||||
|
||||
|
||||
// if (lv->isBool() != rv->isBool()) {
|
||||
// std::cerr<< state_->toString(true,true,true,true);
|
||||
// throw AltaricaException(
|
||||
// std::string() + "AND left and right argument are not of same type -> " +
|
||||
// "do not know if i have to do a unification or a logical comparison in " +
|
||||
// e->toString());
|
||||
// Value::deleteIfPossible(lv);
|
||||
// Value::deleteIfPossible(rv);
|
||||
// }
|
||||
|
||||
if (lv->isBool()) {
|
||||
ValueBool * lb = (ValueBool*) lv;
|
||||
if (lb->ro())
|
||||
lb = (ValueBool*) lb->clone();
|
||||
|
||||
if (lb->allowedTop()) {
|
||||
ValueBool * rb = (ValueBool*) visit(e->getRight());
|
||||
lb->land(rb);
|
||||
}
|
||||
val_ = lb;
|
||||
|
||||
|
||||
} else {
|
||||
if (lv->ro())
|
||||
lv = lv->clone();
|
||||
Value * rv = visit(e->getRight());
|
||||
lv->intersectValue(rv);
|
||||
val_ = lv;
|
||||
Value::deleteIfPossible(rv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::doAffectIfNecessary(Value *v, const Expression * le) {
|
||||
if (!v->constrained()) {
|
||||
|
||||
const ExpressionMEMBER * em = dynamic_cast<const ExpressionMEMBER*>(le);
|
||||
if (em != NULL) // we have to do the affectation
|
||||
state_->setValue(em->getVariable(node_, amodel_),v);
|
||||
}
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::visitARITH(const ExpressionARITH *e) {
|
||||
Value * lv = visit(e->getLeft());
|
||||
Value * rv = visit(e->getRight());
|
||||
|
||||
if (lv->isBool() || rv->isBool() || lv->isSymbol() || rv->isSymbol()) {
|
||||
throw AltaricaException(
|
||||
"ARITHMETIC OPERATION ON NOT INTs nor REALs.." + lv->toString() +
|
||||
" " + rv->toString() + " in " + e->toString());
|
||||
}
|
||||
|
||||
ValueInt * li = NULL;
|
||||
ValueReal *lr = NULL;
|
||||
if (lv->isInt())
|
||||
li = (ValueInt*) lv;
|
||||
else
|
||||
lr = (ValueReal*) lv;
|
||||
ValueInt * ri = NULL;
|
||||
ValueReal * rr = NULL;
|
||||
if (rv->isInt())
|
||||
ri = (ValueInt*) rv;
|
||||
else
|
||||
rr = (ValueReal*) rv;
|
||||
|
||||
|
||||
|
||||
if (assert_) {
|
||||
|
||||
if (li && ri) {
|
||||
if (li->ro())
|
||||
li = (ValueInt*) li->clone();
|
||||
switch(e->getType()) {
|
||||
case 0: li->setToInfThan(ri); break;
|
||||
case 1: li->setToSupThan(ri); break;
|
||||
case 2: li->setToInfEqThan(ri); break;
|
||||
case 3: li->setToSupEqThan(ri); break;
|
||||
}
|
||||
doAffectIfNecessary(li, e->getLeft());
|
||||
} else if (lr && rr) {
|
||||
if (lr->ro())
|
||||
lr = (ValueReal*) lr->clone();
|
||||
switch(e->getType()) {
|
||||
case 0: lr->setToInfThan(rr); break;
|
||||
case 1: lr->setToSupThan(rr); break;
|
||||
case 2: lr->setToInfEqThan(rr); break;
|
||||
case 3: lr->setToSupEqThan(rr); break;
|
||||
}
|
||||
doAffectIfNecessary(lr, e->getLeft());
|
||||
} else if (li && rr) {
|
||||
ValueReal * lr = new ValueReal(li);
|
||||
switch(e->getType()) {
|
||||
case 0: lr->setToInfThan(rr); break;
|
||||
case 1: lr->setToSupThan(rr); break;
|
||||
case 2: lr->setToInfEqThan(rr); break;
|
||||
case 3: lr->setToSupEqThan(rr); break;
|
||||
}
|
||||
doAffectIfNecessary(lr, e->getLeft());
|
||||
} else { // lr && ri
|
||||
if (lr->ro())
|
||||
lr = (ValueReal*) lr->clone();
|
||||
ValueReal * rr = new ValueReal(ri);
|
||||
switch(e->getType()) {
|
||||
case 0: lr->setToInfThan(rr); break;
|
||||
case 1: lr->setToSupThan(rr); break;
|
||||
case 2: lr->setToInfEqThan(rr); break;
|
||||
case 3: lr->setToSupEqThan(rr); break;
|
||||
}
|
||||
delete rr;
|
||||
doAffectIfNecessary(lr, e->getLeft());
|
||||
}
|
||||
|
||||
// if (!lv->constrained()) {
|
||||
// const ExpressionMEMBER * em = dynamic_cast<const ExpressionMEMBER*>(e->getLeft());
|
||||
// if (em != NULL) // we have to do the affectation
|
||||
// state_->setValue(em->getVariable(node_),lv);
|
||||
// }
|
||||
val_ = new ValueBool(true,false);
|
||||
} else {
|
||||
if (li && ri) {
|
||||
switch(e->getType()) {
|
||||
case 0: val_ = new ValueBool(li->getMin()<ri->getMax(),li->getMax()>=ri->getMin()); break;
|
||||
case 1: val_ = new ValueBool(li->getMin()>ri->getMax(),li->getMax()<=ri->getMin()); break;
|
||||
case 2: val_ = new ValueBool(li->getMin()<=ri->getMax(),li->getMax()>ri->getMin()); break;
|
||||
case 3: val_ = new ValueBool(li->getMin()>=ri->getMax(),li->getMax()<ri->getMin()); break;
|
||||
}
|
||||
} else if (lr && ri) {
|
||||
switch(e->getType()) {
|
||||
case 0: val_ = new ValueBool(lr->getMin()<ri->getMax(),lr->getMax()>=ri->getMin()); break;
|
||||
case 1: val_ = new ValueBool(lr->getMin()>ri->getMax(),lr->getMax()<=ri->getMin()); break;
|
||||
case 2: val_ = new ValueBool(lr->getMin()<=ri->getMax(),lr->getMax()>ri->getMin()); break;
|
||||
case 3: val_ = new ValueBool(lr->getMin()>=ri->getMax(),lr->getMax()<ri->getMin()); break;
|
||||
}
|
||||
} else if (li && rr) {
|
||||
switch(e->getType()) {
|
||||
case 0: val_ = new ValueBool(li->getMin()<rr->getMax(),li->getMax()>=rr->getMin()); break;
|
||||
case 1: val_ = new ValueBool(li->getMin()>rr->getMax(),li->getMax()<=rr->getMin()); break;
|
||||
case 2: val_ = new ValueBool(li->getMin()<=rr->getMax(),li->getMax()>rr->getMin()); break;
|
||||
case 3: val_ = new ValueBool(li->getMin()>=rr->getMax(),li->getMax()<rr->getMin()); break;
|
||||
}
|
||||
} else { //lr && rr
|
||||
switch(e->getType()) {
|
||||
case 0: val_ = new ValueBool(lr->getMin()<rr->getMax(),lr->getMax()>=rr->getMin()); break;
|
||||
case 1: val_ = new ValueBool(lr->getMin()>rr->getMax(),lr->getMax()<=rr->getMin()); break;
|
||||
case 2: val_ = new ValueBool(lr->getMin()<=rr->getMax(),lr->getMax()>rr->getMin()); break;
|
||||
case 3: val_ = new ValueBool(lr->getMin()>=rr->getMax(),lr->getMax()<rr->getMin()); break;
|
||||
}
|
||||
}
|
||||
Value::deleteIfPossible(lv);
|
||||
}
|
||||
Value::deleteIfPossible(rv);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// gives the highest element
|
||||
void ExpressionEvaluator::visitINTERVAL(const ExpressionINTERVAL *e) {
|
||||
Value * lv = visit(e->getLeft());
|
||||
Value * rv = visit(e->getRight());
|
||||
|
||||
ValueReal * v;
|
||||
v = (ValueReal*)rv;
|
||||
val_ = new ValueReal(v->toDouble());
|
||||
|
||||
Value::deleteIfPossible(rv);
|
||||
Value::deleteIfPossible(lv);
|
||||
}
|
||||
|
||||
|
||||
void ExpressionEvaluator::visitBOOLCONSTANT(const ExpressionBOOLCONSTANT *e) {
|
||||
val_ = e->get();
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::visitCARD(const ExpressionCARD *e) {
|
||||
int i = 0;
|
||||
for (std::vector<Expression*>::const_iterator ei = e->getExprs()->begin(); ei != e->getExprs()->end(); ++ei) {
|
||||
Value *v = visit(*ei);//val_;
|
||||
i+= v->card();
|
||||
Value::deleteIfPossible(v);
|
||||
}
|
||||
val_ = new ValueInt(i);
|
||||
}
|
||||
void ExpressionEvaluator::visitCONSTARRAY(const ExpressionCONSTARRAY *e) {
|
||||
throw AltaricaException("Const Array eval not implemented!!!");
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::visitCONSTSTRUCT(const ExpressionCONSTSTRUCT *e) {
|
||||
throw AltaricaException("Const Struct eval not implemented!!!");
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::visitCASE(const ExpressionCASE *e) {
|
||||
bool doElse = false;
|
||||
bool doCase = false;
|
||||
Value * ret = NULL;
|
||||
const std::vector<Expression*> * conds = e->getConds();
|
||||
const std::vector<Expression*> * thens = e->getThens();
|
||||
for (unsigned int i = 0; i< conds->size(); ++i) {
|
||||
// std::cerr << (*conds)[i]->toString() << std::endl;
|
||||
Value *c = visit((*conds)[i]);
|
||||
if (!c->isBool())
|
||||
throw AltaricaException("condition of case is not a bool!");
|
||||
|
||||
|
||||
ValueBool *c2 = (ValueBool*)c;
|
||||
if (c2->allowedTop()) {
|
||||
doCase = true;
|
||||
Value *v = visit((*thens)[i]);
|
||||
if (ret == NULL) {
|
||||
ret = v;
|
||||
|
||||
}
|
||||
else {
|
||||
ret->merge(v);
|
||||
Value::deleteIfPossible(v);
|
||||
}
|
||||
}
|
||||
if (c2->allowedBottom())
|
||||
doElse = true;
|
||||
Value::deleteIfPossible(c2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (e->getElse() != NULL && (doElse && !doCase)) {
|
||||
Value *v = visit(e->getElse());
|
||||
if (ret == NULL)
|
||||
ret = v;
|
||||
else {
|
||||
ret->merge(v);
|
||||
Value::deleteIfPossible(v);
|
||||
}
|
||||
// if (ret == NULL)
|
||||
// std::cerr << "NULL value in case\n";
|
||||
}
|
||||
val_ = ret;
|
||||
// if (val_ == NULL)
|
||||
// std::cerr << "NULL value in case\n";
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::visitFUNCTIONCALL(const ExpressionFUNCTIONCALL *e) {
|
||||
throw AltaricaException("function eval not implemented");
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::visitIfThenElse(const ExpressionIfThenElse *e) {
|
||||
Value *c = visit(e->getIf());
|
||||
if (!c->isBool()) {
|
||||
Value::deleteIfPossible(c);
|
||||
throw AltaricaException("conditon of ifthenelse is not a bool in " +
|
||||
e->toString());
|
||||
}
|
||||
|
||||
ValueBool * c2 = (ValueBool*) c;
|
||||
|
||||
if (c2->allowedTop())
|
||||
val_ = visit(e->getThen());
|
||||
if (c2->allowedBottom()) {
|
||||
Value * v = visit(e->getElse());
|
||||
if (val_ == NULL)
|
||||
val_ = v;
|
||||
else {
|
||||
val_->merge(v);
|
||||
Value::deleteIfPossible(v);
|
||||
}
|
||||
}
|
||||
Value::deleteIfPossible(c);
|
||||
}
|
||||
|
||||
|
||||
void ExpressionEvaluator::visitMEMBER(const ExpressionMEMBER *e) {
|
||||
Variable * v = NULL;
|
||||
Value * vv;
|
||||
Constant *c = NULL;
|
||||
|
||||
//cached version (dig expressions.old or svn for uncached versions)
|
||||
switch (e->getIsSymbol()) {
|
||||
case -1:
|
||||
if (node_ != NULL && node_->isSymbol(e->getSymbol())) {
|
||||
e->setIsSymbol(0);
|
||||
e->setSymbol();
|
||||
val_ = e->getSymbolValue();
|
||||
} else {
|
||||
if (node_ != NULL) {
|
||||
v = node_->findStateVariableByName(e->getMA());
|
||||
e->resizeCache(amodel_->getNNodes());
|
||||
}
|
||||
if (v != NULL) {
|
||||
e->setIsSymbol(1);
|
||||
e->setCache(node_->getIndex(), v);
|
||||
vv = state_->getValue(v);
|
||||
if (vv == NULL)
|
||||
vv = v->getInit()->evaluate(amodel_, state_,node_);
|
||||
vv->setDomain(v->getDomain());
|
||||
val_ = vv;
|
||||
} else {
|
||||
if (node_ != NULL)
|
||||
v = node_->findFlowVariableByName(e->getMA());
|
||||
if (v != NULL) {
|
||||
e->setIsSymbol(2);
|
||||
e->setCache(node_->getIndex(), v);
|
||||
v->evaluate(amodel_, state_);
|
||||
val_ = state_->getValue(v);
|
||||
} else {
|
||||
c = amodel_->findConstantByName(e->getMA()->toString());
|
||||
if (c != NULL) {
|
||||
e->setIsSymbol(3);
|
||||
val_ = c->getValue(amodel_, state_, node_);
|
||||
} else {
|
||||
// in this case, symbol that is not in n->symbolCache ( -> symbol of subnode....)
|
||||
e->setIsSymbol(0);
|
||||
e->setSymbol();
|
||||
val_ = e->getSymbolValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
val_ = e->getSymbolValue();
|
||||
break;
|
||||
case 1:
|
||||
v = e->getVarFromCache(node_->getIndex());
|
||||
if (v == NULL) {
|
||||
v = node_->findStateVariableByName(e->getMA());
|
||||
e->setCache(node_->getIndex(),v);
|
||||
}
|
||||
vv = state_->getValue(v);
|
||||
vv->setDomain(v->getDomain());
|
||||
val_ = vv;
|
||||
break;
|
||||
case 2:
|
||||
v = e->getVarFromCache(node_->getIndex());
|
||||
if (v == NULL) {
|
||||
v = node_->findFlowVariableByName(e->getMA());
|
||||
e->setCache(node_->getIndex(),v);
|
||||
}
|
||||
v->evaluate(amodel_, state_);
|
||||
val_ = state_->getValue(v);
|
||||
break;
|
||||
case 3:
|
||||
c = amodel_->findConstantByName(e->getMA()->toString());
|
||||
val_ = c->getValue(amodel_, state_, node_);
|
||||
break;
|
||||
default:
|
||||
ValueSymbol *os = new ValueSymbol(e->getSymbol());
|
||||
val_ = os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ExpressionEvaluator::visitMINMAX(const ExpressionMINMAX *e) {
|
||||
const std::vector<Expression*> * exprs = e->getExprs();
|
||||
|
||||
Value *optV = visit(*(exprs->begin()));
|
||||
if (!optV->isInt() && !optV->isReal()) {
|
||||
delete(optV);
|
||||
throw AltaricaException("MIN/MAX on not int nor real in " +
|
||||
e->toString());
|
||||
}
|
||||
|
||||
ValueInt * optI;
|
||||
ValueReal * optR;
|
||||
if (optV->isInt())
|
||||
optI = (ValueInt*)(optV);
|
||||
else
|
||||
optR = (ValueReal*)(optV);
|
||||
|
||||
if (e->max()) {
|
||||
int maxI = std::numeric_limits<int>::min();
|
||||
double maxR = std::numeric_limits<double>::min();
|
||||
if (optI) {
|
||||
maxI = optI->max();
|
||||
Value::deleteIfPossible(optI);
|
||||
} else {
|
||||
maxR = optR->max();
|
||||
Value::deleteIfPossible(optR);
|
||||
}
|
||||
|
||||
|
||||
for (std::vector<Expression*>::const_iterator eIT = exprs->begin(); eIT != exprs->end(); ++eIT) {
|
||||
Value *v = visit((*eIT));
|
||||
if (!v->isInt() && !v->isReal()) {
|
||||
Value::deleteIfPossible(v);
|
||||
throw AltaricaException("MIN/MAX on not an int nor a real in " +
|
||||
e->toString());
|
||||
} else {
|
||||
if (v->isInt()) {
|
||||
int cmax = ((ValueInt*)v)->max();
|
||||
if (cmax > maxI)
|
||||
maxI = cmax;
|
||||
} else {
|
||||
double cmax = ((ValueReal*)v)->max();
|
||||
if (cmax > maxI)
|
||||
maxR = cmax;
|
||||
}
|
||||
Value::deleteIfPossible(v);
|
||||
}
|
||||
}
|
||||
if (maxR > maxI)
|
||||
val_ = new ValueReal(maxR);
|
||||
else if (maxR != std::numeric_limits<double>::min())
|
||||
val_ = new ValueReal(maxI);
|
||||
else
|
||||
val_ = new ValueInt(maxI);
|
||||
} else {
|
||||
|
||||
int minI = std::numeric_limits<int>::max();
|
||||
double minR = std::numeric_limits<double>::max();
|
||||
if (optI)
|
||||
minI = optI->min();
|
||||
else
|
||||
minR = optR->min();
|
||||
|
||||
for (std::vector<Expression*>::const_iterator eIT = exprs->begin(); eIT != exprs->end(); ++eIT) {
|
||||
Value *v = visit(*eIT);
|
||||
if (!v->isInt() && !v->isReal()) {
|
||||
Value::deleteIfPossible(v);
|
||||
throw AltaricaException("MIN/MAX on not an int nor a real :" +
|
||||
e->toString());
|
||||
} else {
|
||||
if (v->isInt()) {
|
||||
int cmin = ((ValueInt*)v)->min();
|
||||
if (cmin < minI)
|
||||
minI = cmin;
|
||||
} else {
|
||||
int cmin = ((ValueReal*)v)->min();
|
||||
if (cmin < minR)
|
||||
minR = cmin;
|
||||
}
|
||||
Value::deleteIfPossible(v);
|
||||
}
|
||||
}
|
||||
if (minR < minI)
|
||||
val_ = new ValueReal(minR);
|
||||
else if (minR != std::numeric_limits<double>::max())
|
||||
val_ = new ValueReal(minI);
|
||||
else
|
||||
val_ = new ValueInt(minI);
|
||||
}
|
||||
}
|
||||
void ExpressionEvaluator::visitMUL(const ExpressionMUL *e) {
|
||||
Value *lv = visit(e->getLeft());
|
||||
Value *rv = visit(e->getRight());
|
||||
|
||||
if ( (!lv->isInt()&&!lv->isReal()) || (!rv->isInt()&&!rv->isReal())) {
|
||||
Value::deleteIfPossible(lv);
|
||||
Value::deleteIfPossible(rv);
|
||||
throw AltaricaException("TIMES/DIV asked on bools in " + e->toString());
|
||||
}
|
||||
|
||||
ValueInt * li = NULL;
|
||||
ValueReal * lr = NULL;
|
||||
ValueInt * ri = NULL;
|
||||
ValueReal * rr = NULL;
|
||||
if (lv->isInt())
|
||||
li = (ValueInt*) lv;
|
||||
else
|
||||
lr = (ValueReal*) lv;
|
||||
if (rv->isInt())
|
||||
ri = (ValueInt*) rv;
|
||||
else
|
||||
rr = (ValueReal*) rv;
|
||||
|
||||
if (li && ri) {
|
||||
if (li->ro())
|
||||
li = (ValueInt*) li->clone();
|
||||
switch (e->getType()) {
|
||||
case 0: li->times(ri); break;
|
||||
case 1: li->div(ri); break;
|
||||
default: li->mod(ri); break;
|
||||
}
|
||||
val_ = li;
|
||||
Value::deleteIfPossible(rv);
|
||||
return;
|
||||
}
|
||||
|
||||
if (li) {
|
||||
lr = new ValueReal(li);
|
||||
Value::deleteIfPossible(li);
|
||||
} else
|
||||
if (lr->ro())
|
||||
lr = (ValueReal*) lr->clone();
|
||||
|
||||
if (ri) {
|
||||
rr = new ValueReal(ri);
|
||||
Value::deleteIfPossible(ri);
|
||||
}
|
||||
|
||||
switch (e->getType()) {
|
||||
case 0: lr->times(rr); break;
|
||||
case 1: lr->div(rr); break;
|
||||
default: lr->mod(rr); break;
|
||||
}
|
||||
|
||||
Value::deleteIfPossible(rr);
|
||||
|
||||
val_ = lr;
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::visitPAREN(const ExpressionPAREN *e) {
|
||||
val_ = visit(e->getExpr());
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::visitUNSIGNEDINT(const ExpressionUNSIGNEDINT *e) {
|
||||
val_ = e->getValue();
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::visitREAL(const ExpressionREAL *e) {
|
||||
val_ = e->getValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ExpressionEvaluator::visitUNARY(const ExpressionUNARY *e) {
|
||||
Value *c = visit(e->getBelow());
|
||||
switch(e->getType()) {
|
||||
case 0: // MINUS
|
||||
if (!c->isInt() && !c->isReal()) {
|
||||
Value::deleteIfPossible(c);
|
||||
throw AltaricaException("unary MINUS on not an int nor a real in " +
|
||||
e->toString());
|
||||
}
|
||||
if (c->ro())
|
||||
c = (Value*) c->clone();
|
||||
c->inverse();
|
||||
val_ = c;
|
||||
break;
|
||||
case 1: //NOT
|
||||
if (!c->isBool()) {
|
||||
Value::deleteIfPossible(c);
|
||||
throw AltaricaException("NOT on a not bool in " +e->toString());
|
||||
}
|
||||
if (c->ro())
|
||||
c = c->clone();
|
||||
c->inverse();
|
||||
val_ = c;
|
||||
break;
|
||||
case 2: //COMPL
|
||||
if (c->ro())
|
||||
c = c->clone();
|
||||
c->inverse();
|
||||
val_ = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExpressionEvaluator::visitOR(const ExpressionOR *e) {
|
||||
Value *lv = visit(e->getLeft());
|
||||
Value *rv = visit(e->getRight());
|
||||
|
||||
if (lv->ro())
|
||||
lv = lv->clone();
|
||||
|
||||
if (lv->isBool()) {
|
||||
if (!rv->isBool()) {
|
||||
throw AltaricaException(
|
||||
std::string() + "OR left is bool and right is not -> do not know if " +
|
||||
"i have to do a unification or a logical comparison" + e->toString());
|
||||
}
|
||||
((ValueBool*)lv)->lor((ValueBool*)rv);
|
||||
Value::deleteIfPossible(rv);
|
||||
val_ = lv;
|
||||
} else if (lv->isSymbol()) {
|
||||
if (!rv->isSymbol()) {
|
||||
throw AltaricaException("OR left is symbol and right is not" +
|
||||
e->toString());
|
||||
}
|
||||
((ValueSymbol*)lv)->merge((ValueSymbol*)rv);
|
||||
Value::deleteIfPossible(rv);
|
||||
val_ = lv;
|
||||
} else if (lv->isInt() && rv->isInt()) {
|
||||
((ValueInt*)lv)->intUnion((ValueInt*)rv);
|
||||
Value::deleteIfPossible(rv);
|
||||
val_ = lv;
|
||||
} else {
|
||||
if (lv->isReal() && rv->isInt()) {
|
||||
ValueReal* rr = new ValueReal((ValueInt*)rv);
|
||||
((ValueReal*)lv)->realUnion(rr);
|
||||
delete rr;
|
||||
Value::deleteIfPossible(rv);
|
||||
val_ = lv;
|
||||
} else if (lv->isReal() && rv->isReal()) {
|
||||
((ValueReal*)lv)->realUnion((ValueReal*)rv);
|
||||
Value::deleteIfPossible(rv);
|
||||
val_ = lv;
|
||||
} else { //lv->isInt() && rv->isReal()
|
||||
ValueReal * lr = new ValueReal((ValueInt*)lv);
|
||||
lr->realUnion((ValueReal*)rv);
|
||||
Value::deleteIfPossible(rv);
|
||||
Value::deleteIfPossible(lv);
|
||||
val_ = lr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ExpressionEvaluator::visitQUANTIFIED(const ExpressionQUANTIFIED *e) {
|
||||
std::vector<Variable*> vars;
|
||||
const std::vector<std::string> * qVars = e->getQVars();
|
||||
const std::vector<Domain*> * dVars = e->getDVars();
|
||||
|
||||
for (unsigned int i= 0; i<qVars->size(); ++i) {
|
||||
Variable * v = new Variable((*qVars)[i],(*dVars)[i],true);
|
||||
v->setNode(node_);
|
||||
vars.push_back(v);
|
||||
}
|
||||
|
||||
std::vector<std::vector<Value*>*> * combinations = buildCombinations(&vars);
|
||||
val_ = new ValueBool();
|
||||
bool top;
|
||||
bool bottom;
|
||||
|
||||
if (e->forAll()) {
|
||||
top = true;
|
||||
bottom = false;
|
||||
for (std::vector<std::vector<Value*>*>::iterator combi = combinations->begin();
|
||||
combi != combinations->end(); ++combi) {
|
||||
AltaricaState *ss = state_->clone();
|
||||
for (unsigned int i = 0; i<qVars->size(); ++i) {
|
||||
ss->setValue(vars[i], (**combi)[i]);
|
||||
}
|
||||
Value *v = visit(e->getExpr());
|
||||
if (v->isBool()) {
|
||||
ValueBool * vb = (ValueBool*)v;
|
||||
if (!vb->allowedTop()) {
|
||||
top = false;
|
||||
bottom = true;
|
||||
}
|
||||
if (vb->allowedBottom())
|
||||
bottom = true;
|
||||
}
|
||||
}
|
||||
val_ = new ValueBool(top,bottom);
|
||||
} else {
|
||||
top = false;
|
||||
bottom = true;
|
||||
for (std::vector<std::vector<Value*>*>::iterator combi = combinations->begin();
|
||||
combi != combinations->end() ; ++combi) {
|
||||
AltaricaState *ss = state_->clone();
|
||||
for (unsigned int i = 0; i<qVars->size(); ++i) {
|
||||
ss->setValue(vars[i], (**combi)[i]);
|
||||
}
|
||||
Value *v = visit(e->getExpr());
|
||||
if (v->isBool()) {
|
||||
ValueBool * vb = (ValueBool*) v;
|
||||
if (vb->allowedTop()) {
|
||||
top = true;
|
||||
}
|
||||
if (!vb->allowedBottom())
|
||||
bottom = false;
|
||||
}
|
||||
}
|
||||
val_ = new ValueBool(top,bottom);
|
||||
}
|
||||
//clean combinations
|
||||
combinations->clear();
|
||||
delete(combinations);
|
||||
}
|
||||
|
||||
|
||||
void ExpressionEvaluator::visitLOG(const ExpressionLOG *e) {
|
||||
|
||||
bool oldAssert = assert_;
|
||||
assert_ = false;
|
||||
Value *rv = visit(e->getRight());
|
||||
|
||||
Value *lv;
|
||||
|
||||
assert_ = oldAssert;
|
||||
|
||||
if (!assert_) {
|
||||
lv = visit(e->getLeft());
|
||||
switch (e->getType()) {
|
||||
case 0:
|
||||
val_ = new ValueBool(lv->hasIntersection(rv),lv->pDifferent(rv));
|
||||
Value::deleteIfPossible(lv);
|
||||
Value::deleteIfPossible(rv);
|
||||
break;
|
||||
case 1:
|
||||
val_ = new ValueBool(lv->pDifferent(rv), lv->hasIntersection(rv));
|
||||
Value::deleteIfPossible(lv);
|
||||
Value::deleteIfPossible(rv);
|
||||
break;
|
||||
case 2:
|
||||
if (lv->isBool()) {
|
||||
ValueBool * vb = (ValueBool*) lv;
|
||||
if (vb->allowedTop() && !vb->allowedBottom()) {
|
||||
val_ = rv;
|
||||
} else {
|
||||
val_ = new ValueBool(true,false);
|
||||
Value::deleteIfPossible(rv);
|
||||
}
|
||||
Value::deleteIfPossible(lv);
|
||||
} else {
|
||||
throw AltaricaException("non boolean at left of implies "
|
||||
+ e->toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
bool doAffect = false;
|
||||
const ExpressionMEMBER * em;
|
||||
std::vector<Variable*> * v;
|
||||
// lv = visit(e->getLeft());
|
||||
// if (e->getType() != 2 && (rv->isBool() != lv->isBool() ||
|
||||
// rv->isInt() != lv->isInt() ||
|
||||
// rv->isReal() != lv->isReal() ||
|
||||
// rv->isSymbol() != lv->isSymbol())) {
|
||||
// throw AltaricaException("LOGICAL op on different types " +
|
||||
// e->toString());
|
||||
// return;
|
||||
// }
|
||||
|
||||
|
||||
switch (e->getType()) {
|
||||
case 0:
|
||||
// if (lv->constrained()) {
|
||||
// val_ = new ValueBool(lv->hasIntersection(rv),lv->pDifferent(rv));
|
||||
// Value::deleteIfPossible(rv);
|
||||
// Value::deleteIfPossible(lv);
|
||||
// doAffect = false;
|
||||
// } else {
|
||||
// if (lv->ro()) {
|
||||
// val_ = lv->clone();
|
||||
// }
|
||||
// else
|
||||
// val_ = lv;
|
||||
// val_->intersectValue(rv);
|
||||
|
||||
// doAffect = true;
|
||||
// Value::deleteIfPossible(rv);
|
||||
|
||||
if (rv == NULL)
|
||||
rv = visit(e->getRight());
|
||||
val_ = rv->clone();
|
||||
Value::deleteIfPossible(rv);
|
||||
|
||||
// }
|
||||
// if (doAffect) {
|
||||
|
||||
em = dynamic_cast<const ExpressionMEMBER*>(e->getLeft());
|
||||
if (em != NULL) { // we have to do the affectation
|
||||
state_->setValue(em->getVariable(node_, amodel_),val_);
|
||||
}
|
||||
// }
|
||||
break;
|
||||
case 1:
|
||||
if (lv->constrained()) {
|
||||
val_ = new ValueBool(lv->pDifferent(rv), lv->hasIntersection(rv));
|
||||
Value::deleteIfPossible(rv);
|
||||
Value::deleteIfPossible(lv);
|
||||
doAffect = false;
|
||||
} else {
|
||||
val_ = rv->getComplement();
|
||||
Value::deleteIfPossible(rv);
|
||||
Value::deleteIfPossible(lv);
|
||||
doAffect = true;
|
||||
}
|
||||
|
||||
if (doAffect) {
|
||||
em = dynamic_cast <const ExpressionMEMBER*> (e->getLeft());
|
||||
if (em != NULL)
|
||||
state_->setValue(em->getVariable(node_, amodel_),val_);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (lv->isBool()) {
|
||||
ValueBool * lb = (ValueBool*) lv;
|
||||
if (lb->allowedTop() && !lb->allowedBottom()) {
|
||||
Value::deleteIfPossible(lb);
|
||||
val_ = rv;
|
||||
} else {
|
||||
Value::deleteIfPossible(lb);
|
||||
Value::deleteIfPossible(rv);
|
||||
val_= new ValueBool(true,false);
|
||||
}
|
||||
} else {
|
||||
throw AltaricaException("LOGICAL => with non-bool left argument");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw AltaricaException("BAD COMPARISON TYPE IN LOG COMP " +
|
||||
e->toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::vector<Value*>*> * ExpressionEvaluator::buildCombinations(std::vector<Variable*> * vars) {
|
||||
if (vars->size() == 0)
|
||||
return new std::vector<std::vector<Value*>*>();
|
||||
Variable * v = vars->front();
|
||||
vars->erase(vars->begin());
|
||||
std::vector<std::vector<Value*>*> * comb = buildCombinations(vars);
|
||||
unsigned int s = comb->size();
|
||||
DiscreteDomain * dd = (DiscreteDomain*) v->getDomain();
|
||||
for (int j = dd->getMin(); j<dd->getMax(); ++j)
|
||||
for (unsigned int i = 0; i<s; ++i)
|
||||
comb->push_back(new std::vector<Value*>((*comb)[i]->begin(),(*comb)[i]->end()));
|
||||
int j = dd->getMin();
|
||||
for (unsigned int i =0; i<comb->size(); ++i) {
|
||||
(*comb)[i]->insert((*comb)[i]->begin(), dd->getValue(j++));
|
||||
}
|
||||
return comb;
|
||||
}
|
||||
84
src/grammars/altarica/expressions/ExpressionEvaluator.hh
Normal file
84
src/grammars/altarica/expressions/ExpressionEvaluator.hh
Normal file
@@ -0,0 +1,84 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef EXPRESSION_EVALUATOR_HH
|
||||
#define EXPRESSION_EVALUATOR_HH
|
||||
|
||||
#include "EvaluationVisitor.hh"
|
||||
#include "../Values.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class ExpressionEvaluator : public EvaluationVisitor {
|
||||
private :
|
||||
bool assert_;
|
||||
Value * val_;
|
||||
|
||||
public :
|
||||
|
||||
|
||||
ExpressionEvaluator(const AltaricaModel *am, AltaricaState *s, const Node*n, bool assert=false) : EvaluationVisitor(am, s,n),assert_(assert), val_(NULL) {};
|
||||
virtual ~ExpressionEvaluator() {}
|
||||
Value * getValue() {return val_;}
|
||||
|
||||
Value * visit(const Expression *e);
|
||||
|
||||
virtual void visitADD(const ExpressionADD *e);
|
||||
virtual void visitAND(const ExpressionAND *e);
|
||||
virtual void visitARITH(const ExpressionARITH *e) ;
|
||||
// virtual void visitATOMIC(const ExpressionATOMIC *e) ;
|
||||
virtual void visitBOOLCONSTANT(const ExpressionBOOLCONSTANT *e) ;
|
||||
virtual void visitCARD(const ExpressionCARD *e) ;
|
||||
virtual void visitCONSTARRAY(const ExpressionCONSTARRAY *e) ;
|
||||
virtual void visitCONSTSTRUCT(const ExpressionCONSTSTRUCT *e) ;
|
||||
virtual void visitCASE(const ExpressionCASE *e) ;
|
||||
virtual void visitFUNCTIONCALL(const ExpressionFUNCTIONCALL *e) ;
|
||||
virtual void visitIfThenElse(const ExpressionIfThenElse *e) ;
|
||||
virtual void visitLOG(const ExpressionLOG *e) ;
|
||||
virtual void visitMEMBER(const ExpressionMEMBER *e) ;
|
||||
virtual void visitMINMAX(const ExpressionMINMAX *e) ;
|
||||
virtual void visitMUL(const ExpressionMUL *e) ;
|
||||
virtual void visitOR(const ExpressionOR *e) ;
|
||||
virtual void visitPAREN(const ExpressionPAREN *e) ;
|
||||
virtual void visitQUANTIFIED(const ExpressionQUANTIFIED *e) ;
|
||||
virtual void visitUNSIGNEDINT(const ExpressionUNSIGNEDINT *e) ;
|
||||
virtual void visitREAL(const ExpressionREAL *e) ;
|
||||
virtual void visitUNARY(const ExpressionUNARY *e) ;
|
||||
virtual void visitINTERVAL(const ExpressionINTERVAL *e) ;
|
||||
|
||||
private:
|
||||
std::vector<std::vector<Value*>*> * buildCombinations(std::vector<Variable*> * vars);
|
||||
void doAffectIfNecessary(Value *v, const Expression * le);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
1215
src/grammars/altarica/expressions/ExpressionEvaluatorLandmark.cc
Normal file
1215
src/grammars/altarica/expressions/ExpressionEvaluatorLandmark.cc
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef EXPRESSION_EVALUATOR_LM_HH
|
||||
#define EXPRESSION_EVALUATOR_LM_HH
|
||||
|
||||
#include "EvaluationVisitor.hh"
|
||||
#include "../Values.hh"
|
||||
#include "LandmarkState.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class ExpressionEvaluatorLandmark : public EvaluationVisitor {
|
||||
private :
|
||||
bool assert_;
|
||||
Value * val_;
|
||||
LandmarkState *lms_;
|
||||
landmarkType * lm_;
|
||||
public :
|
||||
|
||||
|
||||
ExpressionEvaluatorLandmark(const AltaricaModel *am, LandmarkState *lms, const Node*n, bool assert=false) : EvaluationVisitor(am, lms->getState(),n),assert_(assert), val_(NULL), lms_(lms), lm_(NULL) {};
|
||||
virtual ~ExpressionEvaluatorLandmark() {}
|
||||
Value * getValue() {return val_;}
|
||||
|
||||
void addOrIntersectLM(landmarkType *lm1, Value *v1, landmarkType*lm2, Value *v2);
|
||||
void addOrIntersectLM(landmarkType *lm1, Value *v1, AltaricaState* l);
|
||||
void printLM(landmarkType*lm);
|
||||
bool hasLM(landmarkType * lm, Value*v);
|
||||
std::pair<Value*, landmarkType*> * visitLM(const Expression *e);
|
||||
|
||||
virtual void visitADD(const ExpressionADD *e);
|
||||
virtual void visitAND(const ExpressionAND *e);
|
||||
virtual void visitARITH(const ExpressionARITH *e) ;
|
||||
// virtual void visitATOMIC(const ExpressionATOMIC *e) ;
|
||||
virtual void visitBOOLCONSTANT(const ExpressionBOOLCONSTANT *e) ;
|
||||
virtual void visitCARD(const ExpressionCARD *e) ;
|
||||
virtual void visitCONSTARRAY(const ExpressionCONSTARRAY *e) ;
|
||||
virtual void visitCONSTSTRUCT(const ExpressionCONSTSTRUCT *e) ;
|
||||
virtual void visitCASE(const ExpressionCASE *e) ;
|
||||
virtual void visitFUNCTIONCALL(const ExpressionFUNCTIONCALL *e) ;
|
||||
virtual void visitIfThenElse(const ExpressionIfThenElse *e) ;
|
||||
virtual void visitLOG(const ExpressionLOG *e) ;
|
||||
virtual void visitMEMBER(const ExpressionMEMBER *e) ;
|
||||
virtual void visitMINMAX(const ExpressionMINMAX *e) ;
|
||||
virtual void visitMUL(const ExpressionMUL *e) ;
|
||||
virtual void visitOR(const ExpressionOR *e) ;
|
||||
virtual void visitPAREN(const ExpressionPAREN *e) ;
|
||||
virtual void visitQUANTIFIED(const ExpressionQUANTIFIED *e) ;
|
||||
virtual void visitUNSIGNEDINT(const ExpressionUNSIGNEDINT *e) ;
|
||||
virtual void visitREAL(const ExpressionREAL *e) ;
|
||||
virtual void visitUNARY(const ExpressionUNARY *e) ;
|
||||
virtual void visitINTERVAL(const ExpressionINTERVAL *e) ;
|
||||
|
||||
private:
|
||||
std::vector<std::vector<Value*>*> * buildCombinations(std::vector<Variable*> * vars);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
69
src/grammars/altarica/expressions/ExpressionFUNCTIONCALL.cc
Normal file
69
src/grammars/altarica/expressions/ExpressionFUNCTIONCALL.cc
Normal file
@@ -0,0 +1,69 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* 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) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* 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
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionFUNCTIONCALL.hh"
|
||||
#include "Visitor.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
std::string ExpressionFUNCTIONCALL::toString() const {
|
||||
std::string s;
|
||||
s+= funcName_ + "(";
|
||||
for (std::vector<Expression*>::const_iterator i = args_.begin(); i!= args_.end(); ++i)
|
||||
s+= (*i)->toString() + ",";
|
||||
s+= ")";
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionFUNCTIONCALL::toString(const Node *n, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= funcName_ + "(";
|
||||
for (std::vector<Expression*>::const_iterator i = args_.begin(); i!= args_.end(); ++i)
|
||||
s+= n->toFiacre() + (*i)->toString() + ",";
|
||||
s+= ")";
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionFUNCTIONCALL::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= funcName_ + "(";
|
||||
for (std::vector<Expression*>::const_iterator i = args_.begin(); i!= args_.end(); ++i)
|
||||
s+= f->first + "&" + n->toFiacre() + (*i)->toString() + ",";
|
||||
s+= ")";
|
||||
return s;
|
||||
}
|
||||
|
||||
ExpressionFUNCTIONCALL * ExpressionFUNCTIONCALL::clone() const {
|
||||
ExpressionFUNCTIONCALL * nefc = new ExpressionFUNCTIONCALL(funcName_);
|
||||
for (std::vector<Expression*>::const_iterator i = args_.begin(); i!= args_.end(); ++i)
|
||||
nefc->addArg((*i)->clone());
|
||||
return nefc;
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user