func genDakotaFile(tmplName string, addr string) { scen := &scen.Scenario{} err := scen.Load(*scenfile) check(err) scen.Addr = addr tmpl, err := template.ParseFiles(tmplName) check(err) n := 100 + 1*len(scen.LowerBounds()) if *npop != 0 { n = *npop } else if n < 100 { n = 100 } config := &Config{ Scenario: scen, MaxIter: *maxiter, MaxEval: *maxeval, PopSize: n, MaxConcurr: *parallel, Seed: *seed, } err = tmpl.Execute(os.Stdout, config) check(err) }
func main() { var err error flag.Parse() params := make([]float64, flag.NArg()) for i, s := range flag.Args() { params[i], err = strconv.ParseFloat(s, 64) check(err) } // load problem scen file scen := &scen.Scenario{} err = scen.Load(*scenfile) check(err) if len(params) > 0 { _, err = scen.TransformVars(params) if err != nil { log.Fatal(err) } } // perform action if *gen { j := buildjob(scen) data, err := json.Marshal(j) check(err) fmt.Printf("%s\n", data) } else if !*obj { j := buildjob(scen) submitjob(scen, j) } else { runjob(scen) } }
func main() { var err error flag.Parse() optim.Rand = rand.New(rand.NewSource(int64(*seed))) if _, err := os.Stat(*dbname); !os.IsNotExist(err) && *restart < 0 { log.Fatalf("db file '%v' already exists", *dbname) } db, err = sql.Open("sqlite3", *dbname) check(err) defer db.Close() if *addr != "" { client, err = cloudlus.Dial(*addr) check(err) defer client.Close() } params := make([]int, flag.NArg()) for i, s := range flag.Args() { params[i], err = strconv.Atoi(s) check(err) } // load problem scen file scen := &scen.Scenario{} err = scen.Load(*scenfile) check(err) f1, err := os.Create(*objlog) check(err) defer f1.Close() f4, err := os.Create(*runlog) check(err) defer f4.Close() // create and initialize solver lb := scen.LowerBounds() ub := scen.UpperBounds() step := (ub[0] - lb[0]) / 10 var it optim.Method if *restart >= 0 { it, step = loadIter(lb, ub, *restart) } else { it = buildIter(lb, ub) } obj := &optim.ObjectiveLogger{Obj: &obj{scen, f4}, W: f1} m := &optim.BoxMesh{Mesh: &optim.InfMesh{StepSize: step}, Lower: lb, Upper: ub} // this is here so that signals goroutine can close over it solv := &optim.Solver{ Method: it, Obj: obj, Mesh: m, MaxIter: *maxiter, MaxEval: *maxeval, MaxNoImprove: *maxnoimprove, } // handle signals start := time.Now() sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) go func() { <-sigs f1.Close() f4.Close() fmt.Println("\n*** optimizer killed early ***") final(solv, start) os.Exit(1) }() // solve and print results for solv.Next() { fmt.Printf("Iter %v (%v evals): %v\n", solv.Niter(), solv.Neval(), solv.Best()) } final(solv, start) }