Support command-line problem specification

This change uses the first command-line argument as the problem, which is assumed to be a namespace under `propeller.problems`. This will load the `instructions` and `error-function` from that namespace. If no problem is specified, then a (hopefully) helpful error is generated and the programs exits.

This allows us to call Propeller with calls such as:

```
   lein run software.smallest
```
This commit is contained in:
Nic McPhee 2020-11-24 16:42:22 -06:00
parent 0ca5e77d7a
commit e05290d87c

View File

@ -3,18 +3,26 @@
(:require [propeller.gp :as gp] (:require [propeller.gp :as gp]
[propeller.problems.simple-regression :as regression] [propeller.problems.simple-regression :as regression]
[propeller.problems.string-classification :as string-classif] [propeller.problems.string-classification :as string-classif]
[propeller.problems.software.number-io :as number-io]
[propeller.problems.software.smallest :as smallest]
#?(:cljs [cljs.reader :refer [read-string]]))) #?(:cljs [cljs.reader :refer [read-string]])))
(defn eval-problem-var
[problem-name var-name]
(eval (symbol (str "propeller.problems." problem-name "/" var-name))))
(defn -main (defn -main
"Runs propel-gp, giving it a map of arguments." "Runs propel-gp, giving it a map of arguments."
[& args] [& args]
(when (empty? args)
(println "You must specify a problem to run.")
(println "Try, for example:")
(println " lein run software.smallest")
(System/exit 1))
(require (symbol (str "propeller.problems." (first args))))
(gp/gp (gp/gp
(update-in (update-in
(merge (merge
{:instructions number-io/instructions {:instructions (eval-problem-var (first args) "instructions")
:error-function number-io/error-function :error-function (eval-problem-var (first args) "error-function")
:max-generations 500 :max-generations 500
:population-size 500 :population-size 500
:max-initial-plushy-size 100 :max-initial-plushy-size 100
@ -25,6 +33,6 @@
:variation {:umad 0.5 :crossover 0.5} :variation {:umad 0.5 :crossover 0.5}
:elitism false} :elitism false}
(apply hash-map (apply hash-map
(map read-string args))) (map read-string (rest args))))
[:error-function] [:error-function]
identity))) identity)))