Fawkes API  Fawkes Development Version
config_estimator.cpp
1 /***************************************************************************
2  * config_estimator.cpp - Read estimated execution time from config
3  *
4  * Created: Sun 22 Dec 2019 17:18:10 CET 17:18
5  * Copyright 2019 Till Hofmann <hofmann@kbsg.rwth-aachen.de>
6  ****************************************************************************/
7 
8 /* This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Library General Public License for more details.
17  *
18  * Read the full text in the LICENSE.GPL file in the doc directory.
19  */
20 
21 #include "config_estimator.h"
22 
23 #include <utils/misc/string_split.h>
24 
25 #include <memory>
26 
27 namespace fawkes {
28 
29 /** @class ConfigExecutionTimeEstimator
30  * Get a static estimate for the skill execution time from the config.
31  * This simply reads the execution time from the config.
32  */
33 
34 /** Constructor
35  * @param config The config to read from
36  * @param cfg_prefix The config prefix to read from
37  */
39  const std::string &cfg_prefix)
40 : ExecutionTimeEstimator(config, cfg_prefix), exec_times_(config_, cfg_prefix_, "exec-time")
41 {
42 }
43 
44 bool
46 {
48 }
49 
50 bool
52 {
53  if (active_whitelist_entry_ == whitelist_.end()) {
54  return config_->exists(cfg_prefix_ + "exec-time") || exec_times_.get_default_value();
55  } else {
56  return exec_times_.property_entries.find(active_whitelist_entry_->first)
57  != exec_times_.property_entries.end();
58  }
59 }
60 
61 float
63 {
64  return get_property(exec_times_) / speed_;
65 }
66 } // namespace fawkes
ConfigExecutionTimeEstimator(Configuration *config, const std::string &cfg_prefix)
Constructor.
float get_execution_time(const Skill &skill) override
Get the estimated execution time for the given skill string.
bool can_execute(const Skill &skill) override
Check if this estimator is both allowed and able to give an estimate for a given skill.
bool can_provide_exec_time(const Skill &skill) const override
Check if this estimator can give an estimate for a given skill.
Interface for configuration handling.
Definition: config.h:65
virtual bool exists(const char *path)=0
Check if a given value exists.
A structured representation of a skill.
An abstract estimator for the execution time of a skill.
Configuration *const config_
Config to obtain common configurables.
std::map< std::string, Skill >::const_iterator active_whitelist_entry_
Points to the whitelist entry that matches the skill to execute.
virtual bool can_execute(const Skill &skill)
Check if this estimator is both allowed and able to give an estimate for a given skill.
const std::map< std::string, Skill > whitelist_
Whitelist of skills that the estimator is allowed to process.
T get_property(const Property< T > &property) const
Get the current property value for active_whitelist_entry_.
const std::string cfg_prefix_
Config prefix of the estimator.
const float speed_
Config estimator-specific speedup factor.
Fawkes library namespace.