diff --git a/run.go b/run.go index 8a5e886..8597bc2 100644 --- a/run.go +++ b/run.go @@ -19,24 +19,43 @@ func run() { doPrint := flag.Bool("printreport", true, "print report.tex to console") generate := flag.Bool("generate", true, "run algos and generate plot pics/statistical tables (anew)") + rS := flag.Bool("randomsearch", false, "run Random Search algorithm") + sHC := flag.Bool("shc", false, "run Stochastic Hill Climbing algorithm") + N100 := flag.Bool("N100", false, "run the \"100 Neighbours\" variant of SHC") + // run jDE by default. + jDE := flag.Bool("jde", true, "run Differential Evolution algorithm with parameter self adaptation") // TODO(me): add flag for plot output format: -plotout=(svg,eps,pdf) flag.Parse() if *generate { - // atm we're only doing Random search and SHC - // algoCount := 2 - algoCount := 1 + if !*jDE && !*sHC && !*rS { + log.Fatalln("at least one algo needs to be specified, exiting...") + } var wg sync.WaitGroup - wg.Add(algoCount) - var m sync.Mutex - // go algo.DoRandomSearch(&wg, &m) - // go algo.DoStochasticHillClimbing(&wg, &m) - // // go algo.DoStochasticHillClimbing100Neigh(&wg, &m) - go algo.DojDE(&wg, &m) + switch { + case *jDE: + wg.Add(1) + + go algo.DojDE(&wg, &m) + + case *rS: + wg.Add(1) + + go algo.DoRandomSearch(&wg, &m) + + case *sHC: + wg.Add(1) + + if *N100 { + go algo.DoStochasticHillClimbing100Neigh(&wg, &m) + } else { + go algo.DoStochasticHillClimbing(&wg, &m) + } + } wg.Wait() diff --git a/run_test.go b/run_test.go index 696b8dc..e17997f 100644 --- a/run_test.go +++ b/run_test.go @@ -3,9 +3,21 @@ package main -import "testing" +import ( + "flag" + "testing" +) func TestRun(t *testing.T) { t.Log("call run() (TODO: improve this test)") + + timeout := "1m10s" + + t.Log("increase test timeout to", timeout) + + if err := flag.Set("test.timeout", timeout); err != nil { + t.Errorf("failed to set timeout to %s", timeout) + } + run() }