Example #1
0
func (this *BFS3Agent) getAction() (index discrete.Action) {
	if this.fs3.Dump {
		println("getAction")
	}
	if this.Cfg.ReplanEachStep {
		this.ResetPlanner()
	}
	if this.fs3 == nil {
		index = discrete.Action(stat.NextRange(int64(this.task.Act.Ints.Count())))
		return
	}
	node := this.fs3.GetNode(this.stepsWithPlanner, this.belief)
	var expanded uint64
	for i := uint64(0); i < this.Cfg.MaxTrajectories; i++ {
		expandedThisTime := this.fs3.RunTrajectory(node, this.Cfg.Depth)
		expanded += expandedThisTime
		if this.Cfg.Budget != 0 && expanded > this.Cfg.Budget {
			break
		}
	}
	if this.Dump {
		this.fs3.Dump = true
		fmt.Printf("root:\n%v\n\n", node)
		this.fs3.RunTrajectory(node, this.Cfg.Depth)
	}
	index = discrete.Action(this.fs3.GetAction(node))
	fmt.Fprintf(os.Stderr, "%v\n", this.fs3.GetQs(node))
	if !this.Cfg.FS3.Shallow {
		this.fs3.ClearLevel(this.stepsWithPlanner)
		this.stepsWithPlanner++
	}
	time.Sleep(1e9)
	return
}
Example #2
0
func (ra *RmaxFSSSAgent) GetAction() (action discrete.Action) {
	if ra.s == nil {
		action = discrete.Action(stat.NextRange(int64(ra.task.Act.Ints.Count())))
		return
	}
	node := ra.s.GetNode(ra.stepsWithPlanner, ra.mdpo)
	action = discrete.Action(ra.s.GetAction(node))
	ra.s.ClearLevel(ra.stepsWithPlanner)
	return
}
Example #3
0
func (this *Agent) GetAction() (action uint64) {
	if this.s == nil {
		action = uint64(stat.NextRange(int64(this.mdp.GetTask().Act.Ints.Count())))
		return
	}
	node := this.s.GetNode(this.stepsWithPlanner, this.mdpo)
	action = uint64(this.s.GetAction(node))
	this.s.ClearLevel(this.stepsWithPlanner)
	return
}
Example #4
0
func (this MapBelief) SampleWorld() (truth MapBelief, rejects int) {
	truth = make(MapBelief, 16)

	var wumpusLocs []int
	smellCount := 0
	anySmell := false
	for k, v := range this {
		if (v & Stinky) != 0 {
			anySmell = true
			smellCount++
		}
		if v&Wumpus != 0 {
			wumpusLocs = []int{k}
		}
	}

	if len(wumpusLocs) == 0 {
		for x := 0; x < 4; x++ {
			for y := 0; y < 4; y++ {
				if x == 0 && y == 0 {
					continue
				}
				known, c := this.AdjacentStinky(x, y)
				if (anySmell && known && c == smellCount) || (!anySmell && !known) {
					wumpusLocs = append(wumpusLocs, x+4*y)
				}
			}
		}
	}
	rejects = 0
	for {
		for i := range truth {
			truth[i] = 0
		}
		for x := 0; x < 4; x++ {
			for y := 0; y < 4; y++ {
				k := x + y*4
				if k == 0 {
					continue
				}
				if this[k] != 0 {
					truth[k] = this[k]
				} else {
					if this.IsPit(x, y) || (this.CanBePit(x, y) && flip(.2)) {
						truth.SetFlag(x, y, Pit)
						truth.SetAdjacent(x, y, Breezy)
					}
				}
			}
		}
		if this.IsPitConsistent(truth) {
			break
		}
		rejects++
	}
	wk := wumpusLocs[stat.NextRange(int64(len(wumpusLocs)))]
	x := wk % 4
	y := wk / 4
	truth.SetFlag(x, y, Wumpus)
	truth.SetAdjacent(x, y, Stinky)

	for k, v := range this {
		if v != 0 {
			truth[k] = v
		}
	}

	for k, v := range truth {
		if v == 0 {
			truth[k] = Empty
		}
	}

	return
}
Example #5
0
func (this *Belief) ConsiderRandomFlip() {
	child := stat.NextRange(int64(len(this.learners)))
	this.learners[child].ConsiderRandomFlip()
}
Example #6
0
func (this *DepLearner) ConsiderRandomFlip() {
	this.ConsiderFlip(uint32(stat.NextRange(int64(len(this.bg.ranges)))))
}
Example #7
0
func (this *Env) EnvStart() (obs rlglue.Observation) {
	startState := discrete.State(stat.NextRange(int64(this.mdp.GetTask().Obs.Ints.Count())))
	obs = rlglue.NewObservation(this.mdp.GetTask().Obs.Ints.Values(startState.Hashcode()), []float64{}, []byte{})
	this.LastState = startState
	return
}
Example #8
0
func (this *Posterior) SampleRandomState() {
	s := discrete.State(stat.NextRange(int64(this.bg.NumStates)))
	this.ResampleState(s)
}