<commit_before>/**
 * \file dcs/testbed/albano2013_application_manager.hpp
 *
 * \brief Application manager based on the work by (Albano et al., 2013)
 *
 * \author <NAME> (<EMAIL>)
 *
 * <hr/>
 *
 * Copyright 2014   <NAME> (<EMAIL>)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef DCS_TESTBED_ALBANO2013_APPLICATION_MANAGER_HPP
#define DCS_TESTBED_ALBANO2013_APPLICATION_MANAGER_HPP


#include <boost/smart_ptr.hpp>
#include <cstddef>
#include <dcs/assert.hpp>
#include <dcs/debug.hpp>
#include <dcs/exception.hpp>
#include <dcs/logging.hpp>
#include <dcs/testbed/application_performance_category.hpp>
#include <dcs/testbed/base_application_manager.hpp>
#include <dcs/testbed/virtual_machine_performance_category.hpp>
#include <fl/Headers.h>
#include <fstream>
#include <limits>
#include <map>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>


namespace dcs { namespace testbed {

/**
 * \brief Application Manager based on the work by (Albano et al., 2013)
 *
 * This class implements the Fuzzy-Q&E fuzzy controller proposed in [1].
 *
 * References:
 * -# <NAME>, <NAME>, <NAME>, and <NAME>,
 *    "Fuzzy-Q&E: achieving QoS guarantees and energy savings for cloud applications with fuzzy control,"
 *    Proc. of the 3rd International Conference on Cloud and Green Computing (CGC 2013), 2013. 
 * .
 *
 * \author <NAME> (<EMAIL>)
 */
template <typename TraitsT>
class albano2013_application_manager: public base_application_manager<TraitsT>
{
	private: typedef base_application_manager<TraitsT> base_type;
	public: typedef typename base_type::traits_type traits_type;
	public: typedef typename traits_type::real_type real_type;
	private: typedef typename base_type::app_type app_type;
	private: typedef typename base_type::app_pointer app_pointer;
	private: typedef typename app_type::sensor_type sensor_type;
	private: typedef typename app_type::sensor_pointer sensor_pointer;
	private: typedef ::std::vector<real_type> observation_container;
	private: typedef ::std::map<application_performance_category,observation_container> observation_map;
	private: typedef ::std::map<application_performance_category,sensor_pointer> out_sensor_map;
	private: typedef ::std::map<virtual_machine_performance_category,::std::vector<sensor_pointer> > in_sensor_map;


	private: static const ::std::string rgain_fuzzy_var_name;
	private: static const ::std::string cres_fuzzy_var_name;
	private: static const ::std::string deltac_fuzzy_var_name;


	public: albano2013_application_manager()
	: beta_(0.9),
	  p_fuzzy_eng_(new fl::Engine())
	{
		init();
	}

	public: void smoothing_factor(real_type value)
	{
		beta_ = value;
		this->data_smoother(cpu_util_virtual_machine_performance, ::boost::make_shared< testbed::brown_single_exponential_smoother<real_type> >(beta_));
	}

	public: real_type smoothing_factor() const
	{
		return beta_;
	}

	public: void export_data_to(::std::string const& fname)
	{
		dat_fname_ = fname;
	}

	private: void init()
	{
		this->data_estimator(cpu_util_virtual_machine_performance, boost::make_shared< testbed::mean_estimator<real_type> >());

		this->data_smoother(cpu_util_virtual_machine_performance, ::boost::make_shared< testbed::brown_single_exponential_smoother<real_type> >(beta_));

		DCS_DEBUG_ASSERT( p_fuzzy_eng_ );

		fl::InputVariable* p_iv = 0;

		p_iv = new fl::InputVariable();
		p_iv->setEnabled(true);
		p_iv->setName(cres_fuzzy_var_name);
		p_iv->setRange(-0.1, 1.0);
		p_iv->addTerm(new fl::Triangle("LOW", -0.10, 0.10, 0.30));
		p_iv->addTerm(new fl::Triangle("FINE", 0.10, 0.25, 0.40));
		p_iv->addTerm(new fl::Triangle("HIGH", 0.30, 0.65, 1.00));
		p_fuzzy_eng_->addInputVariable(p_iv);

		p_iv = new fl::InputVariable();
		p_iv->setEnabled(true);
		p_iv->setName(rgain_fuzzy_var_name);
		p_iv->setRange(-1, 1);
		p_iv->addTerm(new fl::Triangle("LOW", -1.00, -0.40, 0.20));
		p_iv->addTerm(new fl::Triangle("FINE", 0.10, 0.20, 0.30));
		p_iv->addTerm(new fl::Triangle("HIGH", 0.30, 0.65, 1.00));
		p_fuzzy_eng_->addInputVariable(p_iv);<commit_msg>(change:minor) Removed useless namespace testbed qualifier<commit_after>/**
 * \file dcs/testbed/albano2013_application_manager.hpp
 *
 * \brief Application manager based on the work by (Albano et al., 2013)
 *
 * \author <NAME> (<EMAIL>)
 *
 * <hr/>
 *
 * Copyright 2014   <NAME> (<EMAIL>)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef DCS_TESTBED_ALBANO2013_APPLICATION_MANAGER_HPP
#define DCS_TESTBED_ALBANO2013_APPLICATION_MANAGER_HPP


#include <boost/smart_ptr.hpp>
#include <cstddef>
#include <dcs/assert.hpp>
#include <dcs/debug.hpp>
#include <dcs/exception.hpp>
#include <dcs/logging.hpp>
#include <dcs/testbed/application_performance_category.hpp>
#include <dcs/testbed/base_application_manager.hpp>
#include <dcs/testbed/data_estimators.hpp>
#include <dcs/testbed/data_smoothers.hpp>
#include <dcs/testbed/virtual_machine_performance_category.hpp>
#include <fl/Headers.h>
#include <fstream>
#include <limits>
#include <map>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>


namespace dcs { namespace testbed {

/**
 * \brief Application Manager based on the work by (Albano et al., 2013)
 *
 * This class implements the Fuzzy-Q&E fuzzy controller proposed in [1].
 *
 * References:
 * -# <NAME>, <NAME>, <NAME>, and <NAME>,
 *    "Fuzzy-Q&E: achieving QoS guarantees and energy savings for cloud applications with fuzzy control,"
 *    Proc. of the 3rd International Conference on Cloud and Green Computing (CGC 2013), 2013. 
 * .
 *
 * \author <NAME> (<EMAIL>)
 */
template <typename TraitsT>
class albano2013_application_manager: public base_application_manager<TraitsT>
{
	private: typedef base_application_manager<TraitsT> base_type;
	public: typedef typename base_type::traits_type traits_type;
	public: typedef typename traits_type::real_type real_type;
	private: typedef typename base_type::app_type app_type;
	private: typedef typename base_type::app_pointer app_pointer;
	private: typedef typename app_type::sensor_type sensor_type;
	private: typedef typename app_type::sensor_pointer sensor_pointer;
	private: typedef ::std::vector<real_type> observation_container;
	private: typedef ::std::map<application_performance_category,observation_container> observation_map;
	private: typedef ::std::map<application_performance_category,sensor_pointer> out_sensor_map;
	private: typedef ::std::map<virtual_machine_performance_category,::std::vector<sensor_pointer> > in_sensor_map;


	private: static const ::std::string rgain_fuzzy_var_name;
	private: static const ::std::string cres_fuzzy_var_name;
	private: static const ::std::string deltac_fuzzy_var_name;


	public: albano2013_application_manager()
	: beta_(0.9),
	  p_fuzzy_eng_(new fl::Engine())
	{
		init();
	}

	public: void smoothing_factor(real_type value)
	{
		beta_ = value;
		this->data_smoother(cpu_util_virtual_machine_performance, ::boost::make_shared< testbed::brown_single_exponential_smoother<real_type> >(beta_));
	}

	public: real_type smoothing_factor() const
	{
		return beta_;
	}

	public: void export_data_to(::std::string const& fname)
	{
		dat_fname_ = fname;
	}

	private: void init()
	{
		this->data_estimator(cpu_util_virtual_machine_performance, boost::make_shared< mean_estimator<real_type> >());

		this->data_smoother(cpu_util_virtual_machine_performance, ::boost::make_shared< brown_single_exponential_smoother<real_type> >(beta_));

		DCS_DEBUG_ASSERT( p_fuzzy_eng_ );

		fl::InputVariable* p_iv = 0;

		p_iv = new fl::InputVariable();
		p_iv->setEnabled(true);
		p_iv->setName(cres_fuzzy_var_name);
		p_iv->setRange(-0.1, 1.0);
		p_iv->addTerm(new fl::Triangle("LOW", -0.10, 0.10, 0.30));
		p_iv->addTerm(new fl::Triangle("FINE", 0.10, 0.25, 0.40));
		p_iv->addTerm(new fl::Triangle("HIGH", 0.30, 0.65, 1.00));
		p_fuzzy_eng_->addInputVariable(p_iv);

		p_iv = new fl::InputVariable();
		p_iv->setEnabled(true);
		p_iv->setName(rgain_fuzzy_var_name);
		p_iv->setRange(-1, 1);
		p_iv->addTerm(new fl::Triangle("LOW", -1.00, -0.40, 0.20));
		p_iv->addTerm(new fl::Triangle("FINE", 0.10, 0.20, 0.30));
		p_iv->addTerm(new fl::Triangle("HIGH", 0.30, 0.65, 1.00));
		p_fuzzy_eng_->addInputVariable(p_iv);
{'fraction_non_alphanumeric': 0.1268754076973255, 'fraction_numerical': 0.02370080452272233, 'mean_word_length': 5.824183976261128, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 123, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2489023', 'n_tokens_mistral': 3458, 'n_tokens_neox': 3129, 'n_words': 734}