2021-11-01 19:58:55 +01:00
|
|
|
package setup
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
|
|
* IMPORTS
|
|
|
|
* ---------------------------------------------------------------- */
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"ads/internal/core/logging"
|
|
|
|
"ads/internal/core/metrics"
|
|
|
|
)
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
|
|
* METHOD display case start/end
|
|
|
|
* ---------------------------------------------------------------- */
|
|
|
|
|
|
|
|
func DisplayStartOfCase(index int, descr *string) {
|
|
|
|
DisplayBar(80)
|
|
|
|
if descr == nil || *descr == "" {
|
2021-11-04 11:06:16 +01:00
|
|
|
logging.Plain("\033[92;1mCASE %[1]v\033[0m.", index)
|
2021-11-01 19:58:55 +01:00
|
|
|
} else {
|
2021-11-04 11:06:16 +01:00
|
|
|
logging.Plain("\033[92;1mCASE %[1]v\033[0m (\033[1;2m%[2]s\033[0m).", index, *descr)
|
2021-11-01 19:58:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-03 11:04:59 +01:00
|
|
|
func DisplayStartOfCaseBlank() {
|
|
|
|
DisplayBar(80)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-01 19:58:55 +01:00
|
|
|
func DisplayEndOfCase() {
|
|
|
|
DisplayBar(80)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
|
|
* METHOD display value
|
|
|
|
* ---------------------------------------------------------------- */
|
|
|
|
|
|
|
|
func RepresentValue(value interface{}) interface{} {
|
|
|
|
switch reflect.TypeOf(value).Kind() {
|
|
|
|
case reflect.Ptr:
|
|
|
|
obj := reflect.ValueOf(value)
|
|
|
|
if obj.IsNil() {
|
|
|
|
return fmt.Sprintf("%v", nil)
|
|
|
|
} else {
|
|
|
|
return fmt.Sprintf("&%v", RepresentValue(obj.Elem().Interface()))
|
|
|
|
}
|
|
|
|
case reflect.Slice:
|
|
|
|
obj := reflect.ValueOf(value)
|
|
|
|
n := obj.Len()
|
|
|
|
values := []interface{}{}
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
x := RepresentValue(obj.Index(i).Interface())
|
|
|
|
values = append(values, x)
|
|
|
|
}
|
|
|
|
if n > 10 {
|
|
|
|
values = append(append(values[:3], "..."), values[n-2:]...)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%v", values)
|
|
|
|
case reflect.Map:
|
|
|
|
obj := reflect.ValueOf(value)
|
|
|
|
n := obj.Len()
|
|
|
|
iter := obj.MapRange()
|
|
|
|
m := map[interface{}]interface{}{}
|
|
|
|
parts := []string{}
|
|
|
|
for iter.Next() {
|
|
|
|
key := iter.Key().Interface()
|
|
|
|
x := RepresentValue(iter.Value().Interface())
|
|
|
|
m[key] = x
|
|
|
|
parts = append(parts, fmt.Sprintf("%[1]v: %[2]v", key, x))
|
|
|
|
}
|
|
|
|
if n > 4 {
|
|
|
|
parts = append(append(parts[:3], "..."), parts[n-2:]...)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("{%s}", strings.Join(parts, ", "))
|
|
|
|
}
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
|
|
* METHOD display algorithm start/end
|
|
|
|
* ---------------------------------------------------------------- */
|
|
|
|
|
|
|
|
func DisplayStartOfAlgorithm(name string, inputs map[string]interface{}) {
|
2021-11-04 11:06:16 +01:00
|
|
|
logging.Plain("Ausführung vom Algorithmus: \033[92;1m%[1]s\033[0m", name)
|
|
|
|
logging.Plain("INPUTS")
|
2021-11-01 19:58:55 +01:00
|
|
|
for varname, value := range inputs {
|
2021-11-04 11:06:16 +01:00
|
|
|
logging.Plain(" - %[1]s = %[2]v", varname, RepresentValue(value))
|
2021-11-01 19:58:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DisplayEndOfAlgorithm(outputs map[string]interface{}) {
|
2021-11-04 11:06:16 +01:00
|
|
|
logging.Plain("OUTPUTS:")
|
2021-11-01 19:58:55 +01:00
|
|
|
for varname, value := range outputs {
|
2021-11-04 11:06:16 +01:00
|
|
|
logging.Plain(" - %[1]s = %[2]v", varname, RepresentValue(value))
|
2021-11-01 19:58:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DisplayMetrics() {
|
2021-11-04 11:06:16 +01:00
|
|
|
// logging.Plain("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsed())
|
|
|
|
logging.Plain("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsedLongFormat())
|
2021-11-05 15:44:06 +01:00
|
|
|
logging.Plain("Kosten (Zeit): T(n) = \033[1m%[1]v\033[0m", displayCost(metrics.GetTimeCost()))
|
2021-11-06 18:21:16 +01:00
|
|
|
logging.Plain("Kosten (#Züge): M(n) = \033[1m%[1]v\033[0m", displayCost(metrics.GetMovesCost()))
|
2021-11-05 15:44:06 +01:00
|
|
|
logging.Plain("Kosten (Platz): S(n) = \033[1m%[1]v\033[0m", displayCost(metrics.GetSpaceCost()))
|
2021-11-01 19:58:55 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
|
|
* METHODS Verschiedenes
|
|
|
|
* ---------------------------------------------------------------- */
|
|
|
|
|
|
|
|
func DisplayBar(options ...int) {
|
|
|
|
n := 80
|
|
|
|
if len(options) > 0 {
|
|
|
|
n = options[0]
|
|
|
|
}
|
2021-11-04 11:06:16 +01:00
|
|
|
logging.Plain("+%[1]s+", strings.Repeat("-", n))
|
2021-11-01 19:58:55 +01:00
|
|
|
return
|
|
|
|
}
|
2021-11-05 15:44:06 +01:00
|
|
|
|
|
|
|
func displayCost(cost int) string {
|
|
|
|
if cost > 0 {
|
|
|
|
return fmt.Sprintf("%v", cost)
|
|
|
|
}
|
|
|
|
return "-"
|
|
|
|
}
|