<commit_before>#include "hybrid_automaton/Controller.h"
#include "hybrid_automaton/HybridAutomaton.h"
#include "hybrid_automaton/error_handling.h"

namespace ha {

	Controller::Controller()
		:_goal(),
		_goal_is_relative(false),
		_kp(),
		_kv(),
		_completion_times(),
		_v_max(),
		_a_max(),
		_priority(0.0),
		_name("default")
	{

	}

	Controller::~Controller()
	{

	}

	Controller::Controller(const ha::Controller &controller)
	{
		this->_goal = controller._goal;
		this->_goal_is_relative = controller._goal_is_relative;		
		this->_kp = controller._kp;
		this->_kv = controller._kv;
		this->_completion_times = controller._completion_times;
		this->_priority = controller._priority;
		this->_name = controller._name;
	}

	DescriptionTreeNode::Ptr Controller::serialize(const DescriptionTree::ConstPtr& factory) const 
	{
		DescriptionTreeNode::Ptr tree = factory->createNode("Controller");

		tree->setAttribute<std::string>(std::string("type"), this->getType());
		tree->setAttribute<std::string>(std::string("name"), this->getName());

		tree->setAttribute<Eigen::MatrixXd>(std::string("goal"), this->_goal);
		tree->setAttribute<bool>(std::string("goal_is_relative"), this->_goal_is_relative);
		tree->setAttribute<Eigen::MatrixXd>(std::string("kp"), this->_kp);
		tree->setAttribute<Eigen::MatrixXd>(std::string("kv"), this->_kv);
		tree->setAttribute<Eigen::MatrixXd>(std::string("completion_times"), this->_completion_times);
		tree->setAttribute<Eigen::MatrixXd>(std::string("v_max"), this->_v_max);
		tree->setAttribute<Eigen::MatrixXd>(std::string("a_max"), this->_a_max);
		tree->setAttribute<double>(std::string("priority"), this->_priority);

		std::map<std::string, std::string>::const_iterator it;
		for (it = this->_additional_arguments.begin(); it != this->_additional_arguments.end(); ++it) {
			tree->setAttribute(it->first, it->second);
		}

		return tree;
	}

	void Controller::deserialize(const DescriptionTreeNode::ConstPtr& tree, const System::ConstPtr& system, const HybridAutomaton* ha) 
	{
		if (tree->getType() != "Controller") {
			HA_THROW_ERROR("Controller.deserialize", "DescriptionTreeNode must have type 'Controller', not '" << tree->getType() << "'!");
		}
		tree->getAttribute<std::string>("type", _type, "");

        if (!ha->getDeserializeDefaultEntities()) {
            if (_type == "" || !HybridAutomaton::isControllerRegistered(_type)) {
                HA_THROW_ERROR("Controller.deserialize", "Controller type '" << _type << "' "
                               << "invalid - empty or not registered with HybridAutomaton!");
            } else {
                setType(_type);
            }
        }

		if(!tree->getAttribute<std::string>("name", _name, ""))
			HA_WARN("Controller.deserialize", "No \"name\" parameter given in Controller - using default value");
		// TODO register object with HybridAutomaton / check that it is unique!

		if(!tree->getAttribute<Eigen::MatrixXd>(std::string("goal"), this->_goal))
			HA_WARN("Controller.deserialize", "No \"goal\" parameter given in Controller "<<_name<<" - using default value");
		
		if(!tree->getAttribute<bool>(std::string("goal_is_relative"), this->_goal_is_relative, false))
			HA_WARN("Controller.deserialize", "No \"goal_is_relative\" parameter given in Controller "<<_name<<" - using default value");
		
		if(!tree->getAttribute<Eigen::MatrixXd>(std::string("kp"), this->_kp))
			HA_WARN("Controller.deserialize", "No \"kp\" parameter given in Controller "<<_name<<" - using default value");
		
		if(!tree->getAttribute<Eigen::MatrixXd>(std::string("kv"), this->_kv))
			HA_WARN("Controller.deserialize", "No \"kv\" parameter given in Controller "<<_name<<" - using default value");

		if(!tree->getAttribute<Eigen::MatrixXd>(std::string("completion_times"), this->_completion_times))
			HA_WARN("Controller.deserialize", "No \"completion_times\" parameter given in Controller "<<_name<<" - using default value");

		//TODO: Read v_max and a_max from dml file
		if(!tree->getAttribute<Eigen::MatrixXd>(std::string("completion_times"), this->_v_max))
			HA_WARN("Controller.deserialize", "No \"v_max\" parameter given in Controller "<<_name<<" - using default value");

		if(!tree->getAttribute<Eigen::MatrixXd>(std::string("completion_times"), this->_a_max))
			HA_WARN("Controller.deserialize", "No \"a_max\" parameter given in Controller "<<_name<<" - using default value");
		
		if(!tree->getAttribute<double>(std::string("priority"), this->_priority, 0.0))
			HA_WARN("Controller.deserialize", "No \"priority\" parameter given in Controller "<<_name<<" - using default value");

		// write all arguments into "_additional_arguments" field
		tree->getAllAttributes(_additional_arguments);

		_system = system;
	}

	int Controller::getDimensionality() const
	{
		return -1;
	}

	void Controller::setSystem(const System::ConstPtr& system)
	{
		this->_system = system;
	}

	Eigen::MatrixXd Controller::getGoal() const
	{
		return this->_goal;
	}

	void Controller::setGoal(const Eigen::MatrixXd& new_goal)<commit_msg>Added updateGoal method to rlabController.<commit_after>#include "hybrid_automaton/Controller.h"
#include "hybrid_automaton/HybridAutomaton.h"
#include "hybrid_automaton/error_handling.h"

namespace ha {

	Controller::Controller()
		:_goal(),
		_goal_is_relative(false),
		_kp(),
		_kv(),
		_completion_times(),
		_v_max(),
		_a_max(),
		_priority(0.0),
		_name("default")
	{
	}

	Controller::~Controller()
	{

	}

	Controller::Controller(const ha::Controller &controller)
	{
		this->_goal = controller._goal;
		this->_goal_is_relative = controller._goal_is_relative;		
		this->_kp = controller._kp;
		this->_kv = controller._kv;
		this->_completion_times = controller._completion_times;
		this->_priority = controller._priority;
		this->_name = controller._name;
	}

	DescriptionTreeNode::Ptr Controller::serialize(const DescriptionTree::ConstPtr& factory) const 
	{
		DescriptionTreeNode::Ptr tree = factory->createNode("Controller");

		tree->setAttribute<std::string>(std::string("type"), this->getType());
		tree->setAttribute<std::string>(std::string("name"), this->getName());

		tree->setAttribute<Eigen::MatrixXd>(std::string("goal"), this->_goal);
		tree->setAttribute<bool>(std::string("goal_is_relative"), this->_goal_is_relative);
		tree->setAttribute<Eigen::MatrixXd>(std::string("kp"), this->_kp);
		tree->setAttribute<Eigen::MatrixXd>(std::string("kv"), this->_kv);
		tree->setAttribute<Eigen::MatrixXd>(std::string("completion_times"), this->_completion_times);
		tree->setAttribute<Eigen::MatrixXd>(std::string("v_max"), this->_v_max);
		tree->setAttribute<Eigen::MatrixXd>(std::string("a_max"), this->_a_max);
		tree->setAttribute<double>(std::string("priority"), this->_priority);

		std::map<std::string, std::string>::const_iterator it;
		for (it = this->_additional_arguments.begin(); it != this->_additional_arguments.end(); ++it) {
			tree->setAttribute(it->first, it->second);
		}

		return tree;
	}

	void Controller::deserialize(const DescriptionTreeNode::ConstPtr& tree, const System::ConstPtr& system, const HybridAutomaton* ha) 
	{
		if (tree->getType() != "Controller") {
			HA_THROW_ERROR("Controller.deserialize", "DescriptionTreeNode must have type 'Controller', not '" << tree->getType() << "'!");
		}
		tree->getAttribute<std::string>("type", _type, "");

        if (!ha->getDeserializeDefaultEntities()) {
            if (_type == "" || !HybridAutomaton::isControllerRegistered(_type)) {
                HA_THROW_ERROR("Controller.deserialize", "Controller type '" << _type << "' "
                               << "invalid - empty or not registered with HybridAutomaton!");
            } else {
                setType(_type);
            }
        }

		if(!tree->getAttribute<std::string>("name", _name, ""))
			HA_WARN("Controller.deserialize", "No \"name\" parameter given in Controller - using default value");
		// TODO register object with HybridAutomaton / check that it is unique!

		if(!tree->getAttribute<Eigen::MatrixXd>(std::string("goal"), this->_goal))
			HA_WARN("Controller.deserialize", "No \"goal\" parameter given in Controller "<<_name<<" - using default value");
		
		if(!tree->getAttribute<bool>(std::string("goal_is_relative"), this->_goal_is_relative, false))
			HA_WARN("Controller.deserialize", "No \"goal_is_relative\" parameter given in Controller "<<_name<<" - using default value");
		
		if(!tree->getAttribute<Eigen::MatrixXd>(std::string("kp"), this->_kp))
			HA_WARN("Controller.deserialize", "No \"kp\" parameter given in Controller "<<_name<<" - using default value");
		
		if(!tree->getAttribute<Eigen::MatrixXd>(std::string("kv"), this->_kv))
			HA_WARN("Controller.deserialize", "No \"kv\" parameter given in Controller "<<_name<<" - using default value");

		if(!tree->getAttribute<Eigen::MatrixXd>(std::string("completion_times"), this->_completion_times))
			HA_WARN("Controller.deserialize", "No \"completion_times\" parameter given in Controller "<<_name<<" - using default value");

		//TODO: Read v_max and a_max from dml file
		if(!tree->getAttribute<Eigen::MatrixXd>(std::string("v_max"), this->_v_max))
			HA_WARN("Controller.deserialize", "No \"v_max\" parameter given in Controller "<<_name<<" - using default value");

		if(!tree->getAttribute<Eigen::MatrixXd>(std::string("a_max"), this->_a_max))
			HA_WARN("Controller.deserialize", "No \"a_max\" parameter given in Controller "<<_name<<" - using default value");
		
		if(!tree->getAttribute<double>(std::string("priority"), this->_priority, 0.0))
			HA_WARN("Controller.deserialize", "No \"priority\" parameter given in Controller "<<_name<<" - using default value");

		// write all arguments into "_additional_arguments" field
		tree->getAllAttributes(_additional_arguments);

		_system = system;
	}

	int Controller::getDimensionality() const
	{
		return -1;
	}

	void Controller::setSystem(const System::ConstPtr& system)
	{
		this->_system = system;
	}

	Eigen::MatrixXd Controller::getGoal() const
	{
		return this->_goal;
	}

	void Controller::setGoal(const Eigen::MatrixXd& new_goal)
{'fraction_non_alphanumeric': 0.17434929465527518, 'fraction_numerical': 0.0009934432743890324, 'mean_word_length': 5.383639822447686, 'pattern_counts': {'":': 0, '<': 129, '<?xml version=': 0, '>': 159, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1956107', 'n_tokens_mistral': 3256, 'n_tokens_neox': 3015, 'n_words': 569}