コード例 #1
0
ファイル: Main.go プロジェクト: jeffallen/go-warp
// each event in the system is generated in this function
func generateEvent(oldev *warp.Event) *warp.Event {
	var mitt int
	var dest int
	var id int32
	var t warp.Time

	if oldev == nil {
		mitt = int(randGen.RandIntUniform(0, int32(entitynum)))
		t = 0 // basetime
	} else {
		mitt = oldev.Type.To
		t = oldev.Time // basetime
	}

	dest = int(randGen.RandIntUniform(0, int32(entitynum-1)))
	for mitt == dest {
		dest = int(randGen.RandIntUniform(0, int32(entitynum-1)))
	}
	id = idcount
	idcount++
	t += warp.Time(randGen.RandIntExponential())

	e := warp.CreateEvent(id, t, warp.Info{mitt, dest, 0})
	return e
}
コード例 #2
0
ファイル: Main.go プロジェクト: jeffallen/go-warp
func initPhold(nlp int, nent int) {
	var rdErr error
	var line string
	var str []string = make([]string, 2)

	file, err := os.Open(conf)
	if err != nil {
		fmt.Println("GO-WARP, error opening the PHOLD configuration file:", err)
		os.Exit(1)
	}
	rd := bufio.NewReader(file)

	stop := false
	for i := 0; rdErr == nil; i++ {
		line, rdErr = rd.ReadString('\n')
		if len(line) > 0 {
			str = strings.SplitN(line, "#", 2)
			num := strings.Replace(str[0], "\t", "", -1)
			num = strings.Replace(num, " ", "", -1)
			if i == 0 {
				var err error
				density, err = strconv.ParseFloat(num, 64)
				if err != nil {
					fmt.Printf("line %v: error parsing float %v: %v", i, num, err)
					stop = true
					break
				}
			} else if i == 1 {
				t, err := strconv.Atoi(num)
				if err != nil {
					fmt.Printf("line %v: error parsing int %v: %v", i, num, err)
					stop = true
					break
				}
				endtime = warp.Time(t)
			} else if i == 2 {
				nFPops, err = strconv.Atoi(num)
				if err != nil {
					fmt.Printf("line %v: error parsing int %v: %v", i, num, err)
					stop = true
					break
				}
			}
		}
	}
	if stop {
		fmt.Println("GO-WARP: config file parse error.")
		os.Exit(1)
	}
	fmt.Println("GO-WARP: read from file:", density, endtime, nFPops)

	lpnum = nlp
	entitynum = nent
	n_events = int(float64(nent) * density)
	randGen = lcg16807.RandInit(int64(lpnum + entitynum))
	idcount = 0

	initEv = make([]warp.Event, n_events)

	warp.SimSetup(lpnum, endtime, ProcessEvent)

	for i := 0; i < n_events; i++ {
		e := generateEvent(nil)
		initEv[i] = *e
	}

	simterm = false
	n_term = 0
}