예제 #1
0
//
// to start with haiti
// go run sim_server.go -sourceCountry=hti -sourceCountryNbBodies=82990
//
func main() {

	// flags  for source country
	sourceCountryPtr := flag.String("sourceCountry", "fra", "iso 3166 sourceCountry code")
	sourceCountryNbBodiesPtr := flag.String("sourceCountryNbBodies", "34413", "nb of bodies")
	sourceCountryStepPtr := flag.String("sourceCountryStep", "0", "simulation step for the spread bodies for source country")

	cutoffPtr := flag.String("cutoff", "2", "cutoff code distance")

	maxStepPtr := flag.String("maxStep", "10000", "at what step do the simulation stop")

	portPtr := flag.String("port", "8000", "listening port")

	flag.Parse()

	// init sourceCountry from flags
	var sourceCountry translation.Country
	sourceCountry.Name = *sourceCountryPtr
	{
		_, errScan := fmt.Sscanf(*sourceCountryNbBodiesPtr, "%d", &sourceCountry.NbBodies)
		if errScan != nil {
			log.Fatal(errScan)
			return
		}
	}
	{
		_, errScan := fmt.Sscanf(*sourceCountryStepPtr, "%d", &sourceCountry.Step)
		if errScan != nil {
			log.Fatal(errScan)
			return
		}
	}
	{
		_, errScan := fmt.Sscanf(*cutoffPtr, "%f", &barnes_hut.CutoffDistance)
		if errScan != nil {
			log.Fatal(errScan)
			return
		}
	}
	server.Info.Printf("CutoffDistance %f", barnes_hut.CutoffDistance)
	{
		_, errScan := fmt.Sscanf(*maxStepPtr, "%d", &barnes_hut.MaxStep)
		if errScan != nil {
			log.Fatal(errScan)
			return
		}
	}
	server.Info.Printf("Max step %d", barnes_hut.MaxStep)
	var port int = 8000
	{
		_, errScan := fmt.Sscanf(*portPtr, "%d", &port)
		if errScan != nil {
			log.Fatal(errScan)
			return
		}
	}
	server.Info.Printf("will listen on port %d", port)
	r = barnes_hut.NewRun()

	// load configuration files.
	filename := fmt.Sprintf(barnes_hut.CountryBodiesNamePattern, sourceCountry.Name, sourceCountry.NbBodies, sourceCountry.Step)
	server.Info.Printf("filename for init %s", filename)
	r.LoadConfig(filename)

	r.SetState(barnes_hut.RUNNING)

	output, _ := os.Create(r.OutputDir + "/" + "essai200Kbody_6Ksteps.gif")
	go r.OutputGif(output, barnes_hut.MaxStep)

	mux := http.NewServeMux()
	mux.HandleFunc("/status", status)

	mux.HandleFunc("/toggleManualAuto", toggleManualAuto)

	mux.HandleFunc("/play", play)
	mux.HandleFunc("/pause", pause)
	mux.HandleFunc("/oneStep", oneStep)
	mux.HandleFunc("/captureConfig", captureConfig)

	mux.HandleFunc("/render", render)
	mux.HandleFunc("/renderSVG", renderSVG)

	mux.HandleFunc("/stats", stats)
	mux.HandleFunc("/area", area)
	mux.HandleFunc("/dt", dt)
	mux.HandleFunc("/theta", theta)
	mux.HandleFunc("/dirConfig", dirConfig)
	mux.HandleFunc("/loadConfig", loadConfig)
	mux.HandleFunc("/loadConfigOrig", loadConfigOrig)
	mux.HandleFunc("/getDensityTenciles", getDensityTenciles)
	mux.HandleFunc("/minDistanceCoord", minDistanceCoord)
	mux.HandleFunc("/nbVillagesPerAxe", nbVillagesPerAxe)
	mux.HandleFunc("/nbRoutines", nbRoutines)
	mux.HandleFunc("/fieldGridNb", fieldGridNb)
	mux.HandleFunc("/updateRatioBorderBodies", updateRatioBorderBodies)
	mux.HandleFunc("/toggleRenderChoice", toggleRenderChoice)
	mux.HandleFunc("/toggleFieldRendering", toggleFieldRendering)

	mux.Handle("/", http.FileServer(http.Dir("../tkv-client/")))
	adressToListen := fmt.Sprintf("localhost:%d", port)
	server.Info.Printf("adressToListen %s", adressToListen)
	log.Fatal(http.ListenAndServe(adressToListen, mux))
}
예제 #2
0
//
//
// on pc
// go run runtime_server.go -targetCountryStep=43439
//
func main() {

	// flags  for source country
	sourceCountryPtr := flag.String("sourceCountry", "fra", "iso 3166 sourceCountry code")
	sourceCountryNbBodiesPtr := flag.String("sourceCountryNbBodiesPtr", "34413", "nb of bodies")
	sourceCountryStepPtr := flag.String("sourceCountryStep", "3563", "simulation step for the spread bodies for source country")

	// flags  for target country
	targetCountryPtr := flag.String("targetCountry", "hti", "iso 3166 targetCountry code")
	targetCountryNbBodiesPtr := flag.String("targetCountryNbBodiesPtr", "82990", "nb of bodies for target country")
	targetCountryStepPtr := flag.String("targetCountryStep", "36719", "simulation step for the spread bodies for target country")

	flag.Parse()

	// init sourceCountry from flags
	var sourceCountry translation.Country
	sourceCountry.Name = *sourceCountryPtr
	{
		_, errScan := fmt.Sscanf(*sourceCountryNbBodiesPtr, "%d", &sourceCountry.NbBodies)
		if errScan != nil {
			log.Fatal(errScan)
			return
		}
	}
	{
		_, errScan := fmt.Sscanf(*sourceCountryStepPtr, "%d", &sourceCountry.Step)
		if errScan != nil {
			log.Fatal(errScan)
			return
		}
	}

	// init targetCountry from flags
	var targetCountry translation.Country
	targetCountry.Name = *targetCountryPtr
	{
		_, errScan := fmt.Sscanf(*targetCountryNbBodiesPtr, "%d", &targetCountry.NbBodies)
		if errScan != nil {
			log.Fatal(errScan)
			return
		}
	}
	{
		_, errScan := fmt.Sscanf(*targetCountryStepPtr, "%d", &targetCountry.Step)
		if errScan != nil {
			log.Fatal(errScan)
			return
		}
	}

	server.Info.Printf("sourceCountry to parse %s", sourceCountry.Name)
	server.Info.Printf("nbBodies to parse %d", sourceCountry.NbBodies)
	server.Info.Printf("step to parse %d", sourceCountry.Step)

	server.Info.Printf("targetCountry to parse %s", targetCountry.Name)
	server.Info.Printf("nbBodies to parse %d", targetCountry.NbBodies)
	server.Info.Printf("step to parse %d", targetCountry.Step)

	t.Init(sourceCountry, targetCountry)

	port := "localhost:8001"

	server.Info.Printf("begin listen on port %s", port)
	mux := http.NewServeMux()

	mux.Handle("/", http.FileServer(http.Dir("../tkv-client/")))

	mux.HandleFunc("/villageCoordinates", villageCoordinates)
	mux.HandleFunc("/villageTargetBorder", villageTargetBorder)
	mux.HandleFunc("/villageSourceBorder", villageSourceBorder)

	log.Fatal(http.ListenAndServe(port, mux))
	server.Info.Printf("end")
}