agent

package
v0.0.0-...-5935107 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BOILER_TARGET_FALLBACK = 40000
	BOILER_MAX_TOP         = 45000
)

Variables

View Source
var (
	Potential_Count = [1000][1000]int{}
	Test            = "String"
)

Functions

func GetDeltaCount

func GetDeltaCount()
func (r *ReflexAgent) ProcessNewState(s *ReflexState)(){
	if r.previousState == nil {
		r.previousState = s
		r.previousAction = s.action
		r.seqBeginningState = s
		s.wEnergyRequirement = 0
	} else {
		if r.seqBeginningState.action != nil {
			if s.action.GetBurnerState() != r.previousState.action.GetBurnerState() || s.action.GetWPumpState() != r.previousState.action.GetWPumpState() {
				r.seqBeginningState = s
			} else {
				if !(r.previousAction.GetBurnerState() || r.previousAction.GetWPumpState()) {
					e := base_delta_transitions[fmt.Sprintf("BT:%d x DE:%d",r.previousState.Percept.BoilerMidTemp.GetValue(),r.previousState.boilerDeltaSince)][s.wEnergyRequirement]
					var t int
					for _,count := range base_delta_transitions[fmt.Sprintf("BT:%d x DE:%d",r.previousState.Percept.BoilerMidTemp.GetValue(),r.previousState.boilerDeltaSince)] {
						t += count
					}
					ae := delta_transitions[fmt.Sprintf("BT:%d x DE:%d",r.previousState.Percept.BoilerMidTemp.GetValue(),r.previousState.boilerDeltaSince)][s.wEnergyRequirement]
					var at int
					for _,count := range delta_transitions[fmt.Sprintf("BT:%d x DE:%d",r.previousState.Percept.BoilerMidTemp.GetValue(),r.previousState.boilerDeltaSince)] {
						at += count
					}
					if t == 0 {
						t=1
						e=0
					}
					fmt.Printf("%v\t%.2f (night)\t%.2f (all)\t[%d>%d]",r.previousState.Percept.CurrentTime,100.0*float64(e)/float64(t),100.0*float64(ae)/float64(at),r.previousState.wEnergyRequirement,s.wEnergyRequirement)

					npb := base_potential_transitions[r.previousState.wEnergyPotential][s.wEnergyPotential]
					var npt int
					for _,count := range base_potential_transitions[r.previousState.wEnergyPotential] {
						npt += count
					}
					pab := potential_transitions[r.previousState.wEnergyPotential][s.wEnergyPotential]
					var pat int
					for _,count := range potential_transitions[r.previousState.wEnergyPotential] {
						pat += count
					}
					if t > 0 {
						fmt.Printf("\t%.2f (night)\t%.2f (all)\t[%d>%d]\n",100.0*float64(npb)/float64(npt),100.0*float64(pab)/float64(pat),r.previousState.wEnergyPotential,s.wEnergyPotential)
					}
				}
			}
		}
		r.previousState = s
		r.previousAction = s.action
	}
}

func GetLastState

func GetLastState() system.SystemState

func SetBurner

func SetBurner(b *gpio.Pin)

func SetLastState

func SetLastState(s system.SystemState)

func SetPumpH

func SetPumpH(p *system.Pump)

func SetPumpW

func SetPumpW(p *system.Pump)
type Percept struct {
	//logger.Relation
	CurrentTime time.Time
	OutsideTemp, BoilerMidTemp, BoilerTopTemp, KettleTemp, HForeRunTemp, HReverseRunTemp, WForeRunTemp, WReverseRunTemp, WIntakeTemp *w1.Temperature
	Valid bool
}
func (p *Percept) String()(string){
	var buffer bytes.Buffer
	buffer.WriteString(fmt.Sprintf("\nPercept at:\t%s\n",p.CurrentTime.String()))
	buffer.WriteString(fmt.Sprintf("Outside Temperature Value:\t%d\t(%v)\n",p.OutsideTemp.GetValue(),p.OutsideTemp.IsValid()))
	buffer.WriteString(fmt.Sprintf("BoilerTopTemp Temperature Value:\t%d\t(%v)\n",p.BoilerTopTemp.GetValue(),p.BoilerTopTemp.IsValid()))
	buffer.WriteString(fmt.Sprintf("BoilerMidTemp Temperature Value:\t%d\t(%v)\n",p.BoilerMidTemp.GetValue(),p.BoilerMidTemp.IsValid()))
	buffer.WriteString(fmt.Sprintf("KettleTemp Temperature Value:\t%d\t(%v)\n",p.KettleTemp.GetValue(),p.KettleTemp.IsValid()))
	buffer.WriteString(fmt.Sprintf("HForeRun Temperature Value:\t%d\t(%v)\n",p.HForeRunTemp.GetValue(),p.HForeRunTemp.IsValid()))
	buffer.WriteString(fmt.Sprintf("HReverse Temperature Value:\t%d\t(%v)\n",p.HReverseRunTemp.GetValue(),p.HReverseRunTemp.IsValid()))
	buffer.WriteString(fmt.Sprintf("WForeRun Temperature Value:\t%d\t(%v)\n",p.WForeRunTemp.GetValue(),p.WForeRunTemp.IsValid()))
	buffer.WriteString(fmt.Sprintf("WReverse Temperature Value:\t%d\t(%v)\n",p.WReverseRunTemp.GetValue(),p.WReverseRunTemp.IsValid()))
	buffer.WriteString(fmt.Sprintln())
	return buffer.String()
}
func (p *Percept) GetRelationName()(string) {
	return PERCEPT_TABLE
}
func (p *Percept) CreateRelation()() {
	var stmnt_string string

	stmnt_string = fmt.Sprintf(
		"CREATE TABLE IF NOT EXISTS %s(" +
		"p_id INT NOT NULL AUTO_INCREMENT," +
		"OutsideTemp INT SIGNED NULL DEFAULT 0," +
		"BoilerMidTemp INT SIGNED NULL DEFAULT 0," +
		"BoilerTopTemp INT SIGNED NULL DEFAULT 0," +
		"KettleTemp INT SIGNED NULL DEFAULT 0," +
		"H1ForeRunTemp INT SIGNED NULL DEFAULT 0," +
		"H1ReverseRunTemp INT SIGNED NULL DEFAULT 0," +
		"H2ForeRunTemp INT SIGNED NULL DEFAULT 0," +
		"WForeRunTemp INT SIGNED NULL DEFAULT 0," +
		"WReverseRunTemp INT SIGNED NULL DEFAULT 0," +
		"PRIMARY KEY(p_id)," +
		"UNIQUE value_key (OutsideTemp,BoilerMidTemp,BoilerTopTemp,KettleTemp,H1ForeRunTemp,H1ReverseRunTemp,H2ForeRunTemp,WForeRunTemp,WReverseRunTemp)" +
		")ENGINE=InnoDB DEFAULT CHARSET=latin1",
		p.GetRelationName())

	logger.StatementExecute(stmnt_string)
}
func (p *Percept) Insert(val ...interface{})() {
	var stmnt_string string

	stmnt_string = fmt.Sprintf(
		"INSERT IGNORE INTO %s" +
		"(OutsideTemp,BoilerMidTemp,BoilerTopTemp,KettleTemp,H1ForeRunTemp,H1ReverseRunTemp,H2ForeRunTemp,WForeRunTemp,WReverseRunTemp)" +
		" VALUES " +
		"(%d,%d,%d,%d,%d,%d,%d,%d,%d)",
		p.GetRelationName(),p.OutsideTemp.GetValue(),p.BoilerMidTemp.GetValue(),p.BoilerTopTemp.GetValue(),p.KettleTemp.GetValue(),p.HForeRunTemp.GetValue(),p.HReverseRunTemp.GetValue(),p.WIntakeTemp.GetValue(),p.WForeRunTemp.GetValue(),p.WReverseRunTemp.GetValue())

	logger.StatementExecute(stmnt_string)
}
func (p *Percept) Delete()() {
	//@todo
}
func (p *Percept) Update(val ...interface{})() {
	//@todo
}
func (p *Percept) getBoilerDelta(successor *Percept)(tempDelta int,recordingDuration time.Duration){
	if successor == nil {
		return
	} else {
		tempDelta = p.BoilerMidTemp.GetValue() - successor.BoilerMidTemp.GetValue()
		recordingDuration = p.CurrentTime.Sub(successor.CurrentTime)
	}
	return
}
func (p *Percept) getKettleDelta(successor *Percept)(tempDelta int,recordingDuration time.Duration){
	if successor == nil {
		return
	} else {
		tempDelta = p.KettleTemp.GetValue() - successor.KettleTemp.GetValue()
		recordingDuration = p.CurrentTime.Sub(successor.CurrentTime)
	}
	return
}
func (p *Percept) checkValidity()(bool){
	return true
}

Types

type ADPState

type ADPState struct {
	AiState
	// contains filtered or unexported fields
}

func (*ADPState) CompareTo

func (s *ADPState) CompareTo(sPrime system.State) int

func (*ADPState) CreateRelation

func (a *ADPState) CreateRelation()

func (*ADPState) Delete

func (a *ADPState) Delete()

func (*ADPState) Equals

func (s *ADPState) Equals(sPrime system.State) bool

func (*ADPState) GetRelationName

func (a *ADPState) GetRelationName() string

func (*ADPState) Insert

func (a *ADPState) Insert(val ...interface{})

func (*ADPState) Reward

func (s *ADPState) Reward(a *system.Action, sPrime system.State) system.Reward

func (*ADPState) String

func (s *ADPState) String() string

func (*ADPState) Successor

func (s *ADPState) Successor(a *system.Action) system.State

func (*ADPState) Terminal

func (s *ADPState) Terminal() bool

func (*ADPState) Update

func (a *ADPState) Update(val ...interface{})

type ActionPicker

type ActionPicker func(*system.Percept, system.Reward) (action *system.Action, log bool)

type Agent

type Agent interface {
	CalculateAction(*system.Percept, system.Reward) (action *system.Action, log bool)
	GetWPumpThrottle(*system.Action) float64
	GetHPumpThrottle(*system.Action) float64
	GetBurnerState(*system.Action) bool
	SetLastAction(*system.Action)
}

type AiState

type AiState interface {
	system.State
	// contains filtered or unexported methods
}

type CountTable

type CountTable map[ReflexStateHash]int

type HashLookupTable

type HashLookupTable map[ReflexStateHash]AiState

type HeatingAgent

type HeatingAgent interface {
	GetAction(*system.Percept) *system.Action
}

type Policy

type Policy func(system.State) *system.Action

type QStateTable

type QStateTable map[ReflexStateActionHash]int

type ReflexAction

type ReflexAction struct {
	*system.Action
}

func (*ReflexAction) RollOut

func (a *ReflexAction) RollOut()

type ReflexAgent

type ReflexAgent struct {
	Agent
	// contains filtered or unexported fields
}

func NewADPAgent

func NewADPAgent(a *system.Action) (r *ReflexAgent)

func NewReflexAgent

func NewReflexAgent(a *system.Action) (r *ReflexAgent)

func (*ReflexAgent) CalculateAction

func (agent *ReflexAgent) CalculateAction(percept *system.Percept, reward system.Reward) (action *system.Action, log bool)

*

  • Agent Interface functions

func (*ReflexAgent) GetBurnerState

func (agent *ReflexAgent) GetBurnerState(*system.Action) bool

func (*ReflexAgent) GetCurrentHStartingTemp

func (agent *ReflexAgent) GetCurrentHStartingTemp(percept *system.Percept) int

func (*ReflexAgent) GetCurrentWStartingTemp

func (agent *ReflexAgent) GetCurrentWStartingTemp(percept *system.Percept) int

func (*ReflexAgent) GetHPumpThrottle

func (agent *ReflexAgent) GetHPumpThrottle(*system.Action) float64

func (*ReflexAgent) GetStateHash

func (r *ReflexAgent) GetStateHash()

func (*ReflexAgent) GetWPumpThrottle

func (agent *ReflexAgent) GetWPumpThrottle(*system.Action) float64

func (*ReflexAgent) InitProcessPerceptData

func (r *ReflexAgent) InitProcessPerceptData(p *system.Percept, vals ...int) (s *ReflexState)

func (*ReflexAgent) PassiveAdpLearning

func (r *ReflexAgent) PassiveAdpLearning(p *system.Percept, rPrime system.Reward) (a *system.Action, log bool)

func (*ReflexAgent) PrintData

func (r *ReflexAgent) PrintData()

func (*ReflexAgent) PrintSeq

func (r *ReflexAgent) PrintSeq()

func (*ReflexAgent) ResetReflexAgent

func (r *ReflexAgent) ResetReflexAgent()

func (*ReflexAgent) SetLastAction

func (r *ReflexAgent) SetLastAction(a *system.Action)

type ReflexState

type ReflexState struct {
	AiState

	Percept *system.Percept
	// contains filtered or unexported fields
}

func (*ReflexState) CompareTo

func (s *ReflexState) CompareTo(sPrime system.State) int

func (*ReflexState) Equals

func (s *ReflexState) Equals(sPrime system.State) bool

func (*ReflexState) GetIdentifier

func (s *ReflexState) GetIdentifier() (hash string)

func (*ReflexState) Reward

func (s *ReflexState) Reward(a *system.Action, sPrime system.State) system.Reward

func (*ReflexState) SetBurnerVal

func (s *ReflexState) SetBurnerVal(number int)

func (*ReflexState) SetWPumpVal

func (s *ReflexState) SetWPumpVal(number int)

func (*ReflexState) Successor

func (s *ReflexState) Successor(a *system.Action) system.State

func (*ReflexState) Terminal

func (s *ReflexState) Terminal() bool

type ReflexStateActionHash

type ReflexStateActionHash string

type ReflexStateHash

type ReflexStateHash string

type RewardFunction

type RewardFunction map[ReflexStateHash]system.Reward

type SimpleHeatingAgent

type SimpleHeatingAgent struct {
	// contains filtered or unexported fields
}

func NewSimpleHeatingAgent

func NewSimpleHeatingAgent(config_oracle_available bool) (a *SimpleHeatingAgent)

func (*SimpleHeatingAgent) GetAction

func (self *SimpleHeatingAgent) GetAction(percept *system.Percept) (action *system.Action)

Implementation of HeatingAgent interface

type StateGenerator

type StateGenerator func(*system.Percept) AiState

type StateID

type StateID uint8
const (
	STATE_w0_h0     StateID = 0
	STATE_w1_h0     StateID = 4
	STATE_w0_h1     StateID = 2
	STATE_w1_h1     StateID = 8
	ADP_STATE_TABLE         = "adp_states"
)

type TransitionTable

type TransitionTable map[ReflexStateActionHash]map[ReflexStateHash]int

type UtilityFunction

type UtilityFunction map[ReflexStateHash]float64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL