Exemple #1
0
func (s *Scenario) Run(stdout, stderr io.Writer) (dbfile string, simid []byte, err error) {
	// generate cyclus input file and run cyclus
	ui := uuid.NewRandom()
	cycin := ui.String() + ".cyclus.xml"
	cycout := ui.String() + ".sqlite"

	data, err := s.GenCyclusInfile()
	if err != nil {
		return "", nil, err
	}
	err = ioutil.WriteFile(cycin, data, 0644)
	if err != nil {
		return "", nil, err
	}

	cmd := exec.Command("cyclus", cycin, "-o", cycout)
	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout
	if stdout != nil {
		cmd.Stdout = stdout
	}
	if stderr != nil {
		cmd.Stderr = stderr
	}

	if err := cmd.Run(); err != nil {
		return "", nil, err
	}

	// post process cyclus output db
	db, err := sql.Open("sqlite3", cycout)
	if err != nil {
		return "", nil, err
	}
	defer db.Close()

	simids, err := post.Process(db)
	if err != nil {
		return "", nil, err
	}

	return cycout, simids[0], nil
}
Exemple #2
0
// with no flags specified, compute and run simulation
func main() {
	flag.Parse()

	scn := &scen.Scenario{}
	err := scn.Load(*scenfile)
	check(err)
	parseSchedVars(scn)

	if *stats {
		scn.PrintStats()
	} else if *transform && !*sched {
		tw := tabwriter.NewWriter(os.Stdout, 4, 4, 1, ' ', 0)
		fmt.Fprint(tw, "Prototype\tBuildTime\tLifetime\tNumber\n")
		for _, b := range scn.Builds {
			fmt.Fprintf(tw, "%v\t%v\t%v\t%v\n", b.Proto, b.Time, b.Lifetime(), b.N)
		}
		tw.Flush()
	} else if *transform && *sched {
		vars, err := scn.TransformSched()
		check(err)

		for _, val := range vars {
			fmt.Printf("%v\n", val)
		}
	} else if *db != "" {
		dbh, err := sql.Open("sqlite3", *db)
		check(err)
		defer dbh.Close()
		simids, err := post.Process(dbh)
		val, err := scn.CalcObjective(*db, simids[0])
		check(err)
		fmt.Println(val)
	} else {
		dbfile, simid, err := scn.Run(nil, nil)
		val, err := scn.CalcObjective(dbfile, simid)
		check(err)
		fmt.Println(val)
	}
}