Ejemplo n.º 1
0
func printSimPerfs(simPerf *[]util.SimPerf) {
	fmt.Printf("PERFORMANCE\n")
	fmt.Printf("Num simulations               -> %d\n", len(*simPerf))
	fmt.Printf("Ticks per simulation          -> %d\n", arg.NumRounds())

	fmt.Printf("ATTRIBUTE                     AVG       MIN       MAX\n")

	printPerfStat("Total score", simPerf, util.GetTotalScore)
	printPerfStat("Agent moves", simPerf, util.GetAgentMoves)
	printPerfStat("Agent cleans", simPerf, util.GetAgentCleans)
	printPerfStat("Agent clean %", simPerf, util.GetAgentCleanPercent)
	printPerfStat("Dirty entry %", simPerf, util.GetDirtyEntryPercent)
	printPerfStat("Dirty duration", simPerf, util.GetAvgDirtyTicks)
	print("-----------------------------------\n")
	printPerfStat("Clean tile-tick", simPerf, util.GetCleanTicks)
	printPerfStat("Simple score", simPerf, util.GetSimpleScore)

	print("\n\n")
}
Ejemplo n.º 2
0
func (s *SimPerf) AgentEnteredTile(dirty bool) {
	if dirty {
		s.dirtyEntry += 1.0 / float64(arg.NumRounds())
	}
}
Ejemplo n.º 3
0
func GetAgentCleanPercent(s SimPerf) float64 {
	return (float64(s.agentCleans) / float64(arg.NumRounds())) * 100.0
}
Ejemplo n.º 4
0
func main() {
	arg.BindArgs()
	rand.Seed(time.Now().UTC().UnixNano())

	var visual bool = arg.Visual()
	var rounds int = arg.NumRounds()
	var delay int = arg.DelayMS()

	var renderer t_renderer
	if visual {
		renderer.createWindow()
	}

	// Initialize the controller and the agent
	controller := createController()

	var perfs []util.SimPerf
	var max = controller.GetMaxPermCount()
	fmt.Printf("Max permutations: %d\n", max)
	perfs = make([]util.SimPerf, controller.GetMaxPermCount())

	var posPerm, dirtPerm uint64 = 0, 0
	for controller.CanPermute(posPerm, dirtPerm) {
		a := new(agent.Agent)
		a.Initialize(controller.GetStartingTile())

		controller.Permute(posPerm, dirtPerm)
		permNo := controller.GetPermNumber(posPerm, dirtPerm)

		// Run the simulation
		for i := 0; i < rounds; i++ {
			if visual {
				renderer.pollEvents()
				if renderer.shouldExit {
					break
				}

				renderer.renderFrame(controller, a)

				if arg.Manual() {
					reader := bufio.NewReader(os.Stdin)
					_, _ = reader.ReadString('\n')
				} else {
					time.Sleep(time.Duration(delay) * time.Millisecond)
				}
			}

			controller.Tick()
			a.Tick(&perfs[permNo])

			perfs[permNo].SetCleanTilesThisTick(controller.GetCleanTilesCount())
		}

		if arg.Verbose() {
			printSimPerf(perfs[permNo])
		}

		// Increment the permutations - if no more permutations
		// are allowed with the incremented dirtPerm, increment
		// posPerm. If posPerm now holds an invalid value, the
		// embracing for-loop will terminate.
		dirtPerm++
		if !controller.CanPermute(posPerm, dirtPerm) {
			dirtPerm = 0
			posPerm++
		}
	}

	printSimPerfs(&perfs)
}