00001 00004 #ifndef _SKIING_H_ 00005 #define _SKIING_H_ 1 00006 #include <algorithm> 00007 #include "globals.h" 00008 00016 struct skiing_spec { 00017 double initial_resort, taoVal, m_factor, ratio; 00018 }; 00019 00020 class Skiing 00021 { 00022 private: 00024 double tao; 00026 double m_factor; 00028 double acc_cost; 00030 double resort_cost; 00032 double ratio; 00034 double svm_baseline_update; 00035 00036 00040 void resetAccCost() {acc_cost = 0;} 00045 void updateResortCost(double res_cost) {resort_cost = res_cost;} 00046 00050 bool firstAfterResort; // This is set to true by resort. 00058 double adjustCost(double cost) { 00059 if(firstAfterResort) { 00060 setSVMBaseline(cost); 00061 firstAfterResort = false; 00062 return cost; 00063 } else { 00064 double svm_baseline_update = getSVMBaselineUpdate(); 00065 double adjustedCost = std::max(cost - svm_baseline_update, 0.0); 00066 setSVMBaseline(std::min(cost, svm_baseline_update)); 00067 return adjustedCost; 00068 } 00069 } 00070 00074 void setup() { 00075 acc_cost = 0.0; 00076 svm_baseline_update = 0.0; 00077 firstAfterResort = false; 00078 } 00079 public: 00084 Skiing(struct skiing_spec &s) { 00085 this->tao = s.taoVal; 00086 this->m_factor = s.m_factor; 00087 this->resort_cost = s.initial_resort; 00088 this->ratio = s.ratio; 00089 setup(); 00090 LOGGING_ONLY(std::cout << "[skiing.h] ski constructor" << std::endl;); 00091 LOGGING_ONLY(std::cout << "\ttao: " << tao << std::endl;); 00092 LOGGING_ONLY(std::cout << "\tm_factor: " << m_factor << std::endl;); 00093 LOGGING_ONLY(std::cout << "\tresort_cost: " << resort_cost << std::endl;); 00094 LOGGING_ONLY(std::cout << "\tratio: " << ratio << std::endl;); 00095 LOGGING_ONLY(std::cout << "\tacc_cost: " << acc_cost << std::endl;); 00096 LOGGING_ONLY(std::cout << "\tsvm_baseline_update: " << svm_baseline_update << std::endl;); 00097 LOGGING_ONLY(std::cout << "\tfirstAfterResort: " << firstAfterResort << std::endl;); 00098 } 00100 // TODO: PHASE TbHIS CONSTRUCTOR OUT! 00108 Skiing(double tao_val, double m_f, double resort, double ratio) { 00109 this->tao = tao_val; 00110 this->m_factor = m_f; 00111 this->resort_cost = resort; 00112 this->ratio = ratio; 00113 setup(); 00114 } 00116 double getMFactor() {return m_factor;} 00118 double getAccCost() {return acc_cost;} 00120 double getResortCost() {return resort_cost;} 00121 00123 void updateAccCost(double waste_time) { 00124 double adjustedCost = adjustCost(waste_time); 00125 acc_cost = ((1 - tao) * acc_cost) + adjustedCost; 00126 LOGGING_ONLY(std::cout << "[skiing.h] updateAccCost" << std::endl;); 00127 LOGGING_ONLY(std::cout << "\ttao: " << tao << std::endl;); 00128 LOGGING_ONLY(std::cout << "\tm_factor: " << m_factor << std::endl;); 00129 LOGGING_ONLY(std::cout << "\tresort_cost: " << resort_cost << std::endl;); 00130 LOGGING_ONLY(std::cout << "\tratio: " << ratio << std::endl;); 00131 LOGGING_ONLY(std::cout << "\tacc_cost: " << acc_cost << std::endl;); 00132 LOGGING_ONLY(std::cout << "\tsvm_baseline_update: " << svm_baseline_update << std::endl;); 00133 LOGGING_ONLY(std::cout << "\tfirstAfterResort: " << firstAfterResort << std::endl;); 00134 } 00135 00137 bool shouldResort() {return acc_cost > resort_cost * ratio;} 00138 00143 void doResort(double time_to_resort) { 00144 updateResortCost(time_to_resort); 00145 resetAccCost(); 00146 firstAfterResort = true; 00147 } 00148 00149 // These are only for debugging. 00151 void setSVMBaseline(double baseline) {svm_baseline_update = baseline;} 00153 double getSVMBaselineUpdate() {return svm_baseline_update;} 00154 00155 }; 00156 #endif