FMU/Source/Building.cpp
/**
 * @brief Loops over the values and chooses the value with the highest power
 * @details Loops over the values and calculates if the choice is an increase or
 * decrease on the current state chooses whether to stay the same, increase, or
 * decrease based on the highest value
 * if the power is equal for two or more options then toss a coin.
 * @param  val          Occupant desires
 * @param  power        Occupant power
 * @param  currentState current state of the device
 * @return              The final negotiated choice for the device
 */
@brief Loops over the values and chooses the value with the highest power
@details Loops over the values and calculates if the choice is an increase or
decrease on the current state chooses whether to stay the same, increase, or
decrease based on the highest value
if the power is equal for two or more options then toss a coin.
@param  val          Occupant desires
@param  power        Occupant power
@param  currentState current state of the device
@return              The final negotiated choice for the device
@brief Loops over the values and chooses the value with the highest power @details Loops over the values and calculates if the choice is an increase or decrease on the current state chooses whether to stay the same increase or decrease based on the highest value if the power is equal for two or more options then toss a coin . @param val Occupant desires @param power Occupant power @param currentState current state of the device @return The final negotiated choice for the device
double Building::decisionDoubleVec(const std::vector<double> & val,
                                  const std::vector<double> & power,
                                  const double currentState) const {
  double state = currentState;
  if (!val.empty()){
    double totalIncrease = 0;
    double totalDecrease = 0;
    double increase = 0;
    double decrease = 0;
    double increasePower = 0;
    double decreasePower = 0;
    double samePower = 0;
    for (unsigned int i = 0; i < val.size(); i++) {
      double d = val[i];
      double powerValue = power[i];
      if (d < currentState) {
        decrease++;
        totalDecrease = totalDecrease + d;
        decreasePower = decreasePower + powerValue;
      } else if (d > currentState) {
        increase++;
        totalIncrease = totalIncrease + d;
        increasePower = increasePower + powerValue;
      } else {
        samePower = samePower + powerValue;
      }
    }
    if (samePower == increasePower
        && samePower == decreasePower
        && increasePower == decreasePower) {
        int i = Utility::randomInt(0, 2);
        if (i == 0) {
            state = totalIncrease / increase;
        } else if (i == 1) {
            state = totalDecrease / decrease;
        }
    } else if (samePower < increasePower && increasePower > decreasePower) {
        state = totalIncrease / increase;
    } else if (samePower < decreasePower && increasePower < decreasePower) {
        state = totalDecrease / decrease;
    } else if (samePower == increasePower && samePower > decreasePower) {
        if (Utility::tossACoin()) {
            state = totalIncrease / increase;
        }
    } else if (samePower > increasePower && samePower == decreasePower) {
        if (Utility::tossACoin()) {
            state = totalDecrease / decrease;
        }
    } else if (samePower < increasePower
        && samePower < decreasePower
        && increasePower == decreasePower) {
        if (Utility::tossACoin()) {
            state = totalIncrease / increase;
        } else {
            state = totalDecrease / decrease;
        }
    }
  }
  return state;
}
double Building :: decisionDoubleVec ( const std :: vector < double > & val , const std :: vector < double > & power , const double currentState ) const { double state = currentState ; if ( ! val . empty ( ) ) { double totalIncrease = 0 ; double totalDecrease = 0 ; double increase = 0 ; double decrease = 0 ; double increasePower = 0 ; double decreasePower = 0 ; double samePower = 0 ; for ( unsigned int i = 0 ; i < val . size ( ) ; i ++ ) { double d = val [ i ] ; double powerValue = power [ i ] ; if ( d < currentState ) { decrease ++ ; totalDecrease = totalDecrease + d ; decreasePower = decreasePower + powerValue ; } else if ( d > currentState ) { increase ++ ; totalIncrease = totalIncrease + d ; increasePower = increasePower + powerValue ; } else { samePower = samePower + powerValue ; } } if ( samePower == increasePower && samePower == decreasePower && increasePower == decreasePower ) { int i = Utility :: randomInt ( 0 , 2 ) ; if ( i == 0 ) { state = totalIncrease / increase ; } else if ( i == 1 ) { state = totalDecrease / decrease ; } } else if ( samePower < increasePower && increasePower > decreasePower ) { state = totalIncrease / increase ; } else if ( samePower < decreasePower && increasePower < decreasePower ) { state = totalDecrease / decrease ; } else if ( samePower == increasePower && samePower > decreasePower ) { if ( Utility :: tossACoin ( ) ) { state = totalIncrease / increase ; } } else if ( samePower > increasePower && samePower == decreasePower ) { if ( Utility :: tossACoin ( ) ) { state = totalDecrease / decrease ; } } else if ( samePower < increasePower && samePower < decreasePower && increasePower == decreasePower ) { if ( Utility :: tossACoin ( ) ) { state = totalIncrease / increase ; } else { state = totalDecrease / decrease ; } } } return state ; }
@brief Loops over the values and chooses the value with the highest power
 @details Loops over the values and calculates if the choice is an increase or
 decrease on the current state chooses whether to stay the same, increase, or
 decrease based on the highest value
 if the power is equal for two or more options then toss a coin.
@brief Loops over the values and chooses the value with the highest power @details Loops over the values and calculates if the choice is an increase or decrease on the current state chooses whether to stay the same increase or decrease based on the highest value if the power is equal for two or more options then toss a coin .
// if same toss a coin // choose an increase // choose an decrease // toss a coin if stay the same and increase // toss a coin if stay the same and decrease // toss a coin if stay the increase and decrease