func main() { data, err := ioutil.ReadFile("../tmp/test.json") if err != nil { fmt.Println(err) return } f := jf.NewFactory() err = f.LoadJSON(data) if err != nil { fmt.Println(err) return } machines, err := f.CreateNetwork("main") if err != nil { fmt.Println(err) return } env := engine.NewEnvironment() for _, m := range machines { env.AddMachine(m) } limits := engine.NewLimits() limits.Duration = 1.0 env.Run(limits) }
func main() { r := &Rnd{} r.mt = rnd.MT19937New(uint32(time.Now().UnixNano())) limits := engine.NewLimits() limits.Events = 10000 f := jf.NewFactory() f.SetRnd(hps.IRnd(r)) content, err := ioutil.ReadFile(os.Args[1]) if err != nil { fmt.Println(err) return } run := func() (float64, error) { environment := engine.NewEnvironment() err = f.LoadJSON(content) if err != nil { fmt.Println(err) return 0, err } machines, err := f.CreateNetwork("default") if err != nil { fmt.Println(err) return 0, err } for _, m := range machines { environment.AddMachine(m) } count := 0 environment.Iteration(func(env hps.IEnvironment, evt hps.IEvent) { count++ for _, m := range env.Machines() { property5, _ := m.Property("property5") property5.SetValue("test") } }) begin := time.Now() result := environment.Run(limits) end := time.Now() duration := end.Sub(begin) statusText := "" switch result.Status { case engine.COMPLETED_BY_DURATION: statusText = "duration limit is reached" case engine.COMPLETED_BY_TIME: statusText = "time limit is reached" case engine.COMPLETED_BY_ITERATIONS: statusText = "iterations limit is reached" case engine.COMPLETED_BY_IDLE: statusText = "no more events" } fmt.Printf("%v events in %v, terminated by '%s'\n", count, duration, statusText) return duration.Seconds(), nil } runs := []float64{} for i := 0; i < 10; i++ { duration, _ := run() runs = append(runs, duration) } runsAvg := 0.0 for i := 0; i < len(runs); i++ { runsAvg += runs[i] / float64(len(runs)) } stdDev := 0.0 for i := 0; i < len(runs); i++ { stdDev += (runs[i] - runsAvg) * (runs[i] - runsAvg) / float64(len(runs)) } stdDev = math.Sqrt(stdDev) fmt.Printf("10 runs, avg %f, std dev %f\n", runsAvg, stdDev) }