001 package dk.deepthought.sidious.rules;
002
003 import java.util.ArrayList;
004 import java.util.Collection;
005
006 import org.apache.commons.logging.Log;
007 import org.apache.commons.logging.LogFactory;
008
009 import dk.deepthought.sidious.goalhandler.Goal;
010 import dk.deepthought.sidious.greenhouse.ClimaticState;
011 import dk.deepthought.sidious.greenhouse.SensorInput;
012 import dk.deepthought.sidious.supportsystem.Adjustable;
013 import dk.deepthought.sidious.supportsystem.State;
014 import dk.deepthought.sidious.supportsystem.Step;
015 import dk.deepthought.sidious.supportsystem.SystemSettings;
016
017 /**
018 * Class simulates the heat expenses.
019 * <p>
020 * This simple simulation is done by checking whether the heater is active or
021 * not. The higher the activity of the heater the higher the desire value.
022 *
023 * @author Deepthought
024 *
025 */
026 public class HeatExpensesRule extends Rule {
027
028 //FIXME flyt værdier ud i property fil!
029
030 /**
031 * Logger for this class
032 */
033 private static final Log logger = LogFactory.getLog(HeatExpensesRule.class);
034
035 /*
036 * (non-Javadoc)
037 *
038 * @see dk.deepthought.sidious.rules.Rule#desire(dk.deepthought.sidious.supportsystem.State,
039 * dk.deepthought.sidious.supportsystem.State,
040 * dk.deepthought.sidious.supportsystem.Step)
041 */
042 public double desire(State currentState, State newState, Step step) {
043 if (logger.isDebugEnabled()) {
044 logger.debug("desire(State currentState=" + currentState
045 + ", State newState=" + newState + ", Step step=" + step
046 + ") - start");
047 }
048
049 ArrayList<Adjustable> adjs = new ArrayList<Adjustable>(step
050 .getAdjustables());
051 Adjustable heater = null;
052 for (Adjustable adjustable : adjs) {
053 if (adjustable.getID().equals(SystemSettings.getHeaterSetPointID())) {
054 heater = adjustable;
055 }
056 }
057 SensorInput temperature = null;
058 if (currentState instanceof ClimaticState) {
059 ClimaticState currentClima = (ClimaticState) currentState;
060 for (SensorInput input : currentClima.getSensors()) {
061 if (input.getID().equals(SystemSettings.getTemperatureID())) {
062 temperature = input;
063 }
064 }
065 }
066 double returndouble = 0;
067 double diff = 0;
068 if (heater != null && temperature != null) {
069 diff = heater.getSetting() - temperature.getValue();
070 }
071 if (diff < 0) {
072 returndouble = 0;
073 } else if (diff < 5) {
074 returndouble = (diff / 5);
075 } else {
076 returndouble = 1;
077 }
078 if (logger.isDebugEnabled()) {
079 logger.debug("desire(State currentState=" + currentState
080 + ", State newState=" + newState + ", Step step=" + step
081 + ") - end - return value=" + returndouble);
082 }
083 return returndouble;
084 }
085
086 /*
087 * (non-Javadoc)
088 *
089 * @see dk.deepthought.sidious.rules.Rule#getGoals()
090 */
091 public Collection<Goal> getGoals() {
092 if (logger.isDebugEnabled()) {
093 logger.debug("getGoals() - start");
094 }
095 // Is not goal oriented
096 Collection<Goal> returnCollection = new ArrayList<Goal>();
097 if (logger.isDebugEnabled()) {
098 logger.debug("getGoals() - end - return value=" + returnCollection);
099 }
100 return returnCollection;
101 }
102
103 }
|