2021-11-04 10:36:31 +01:00
|
|
|
package run
|
2021-10-30 10:19:16 +02:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
|
|
* IMPORTS
|
|
|
|
* ---------------------------------------------------------------- */
|
|
|
|
|
|
|
|
import (
|
2021-11-01 19:58:55 +01:00
|
|
|
"fmt"
|
|
|
|
|
2021-11-03 19:34:57 +01:00
|
|
|
"ads/internal/core/logging"
|
|
|
|
"ads/internal/setup"
|
|
|
|
"ads/internal/types"
|
|
|
|
|
2021-11-05 15:48:06 +01:00
|
|
|
algorithm_search_binary "ads/pkg/algorithms/search/binary"
|
|
|
|
algorithm_search_interpol "ads/pkg/algorithms/search/interpol"
|
|
|
|
algorithm_search_ith_element "ads/pkg/algorithms/search/ith_element"
|
|
|
|
algorithm_search_jump "ads/pkg/algorithms/search/jump"
|
|
|
|
algorithm_search_poison "ads/pkg/algorithms/search/poison"
|
|
|
|
algorithm_search_sequential "ads/pkg/algorithms/search/sequential"
|
|
|
|
algorithm_stacks_next_greater_element "ads/pkg/algorithms/stacks/next_greater_element"
|
|
|
|
algorithm_sum_maxsubsum "ads/pkg/algorithms/sum/maxsubsum"
|
2021-10-30 10:19:16 +02:00
|
|
|
)
|
|
|
|
|
2021-11-04 10:36:31 +01:00
|
|
|
/* ---------------------------------------------------------------- *
|
|
|
|
* ENDPOINT run interactive modus
|
|
|
|
* ---------------------------------------------------------------- */
|
|
|
|
|
|
|
|
// Startet App im interaktiven Modus
|
|
|
|
func RunInteractive() error {
|
2021-11-04 11:06:16 +01:00
|
|
|
logging.Plain(setup.Logo())
|
2021-11-04 10:36:31 +01:00
|
|
|
_, err := menuMain.ShowMenu()
|
2021-11-06 11:16:34 +01:00
|
|
|
logging.Plain("\033[2;3m...Programm terminiert.\033[0m")
|
2021-11-04 10:36:31 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-30 10:19:16 +02:00
|
|
|
/* ---------------------------------------------------------------- *
|
2021-11-03 11:04:59 +01:00
|
|
|
* ENDPOINT run non-interactive modus
|
2021-10-30 10:19:16 +02:00
|
|
|
* ---------------------------------------------------------------- */
|
|
|
|
|
2021-11-01 19:58:55 +01:00
|
|
|
// Liest Config Datei ein und führt Algorithmen auf Fälle durch
|
2021-11-03 16:05:46 +01:00
|
|
|
func RunNonInteractive(path string) error {
|
2021-11-01 19:58:55 +01:00
|
|
|
var err error
|
|
|
|
var err_case error
|
|
|
|
|
|
|
|
// extrahiere user config
|
|
|
|
config := setup.NewUserConfig()
|
|
|
|
err = setup.GetUserConfig(path, &config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-11-04 11:06:16 +01:00
|
|
|
logging.Plain(setup.Logo())
|
2021-11-03 16:05:46 +01:00
|
|
|
|
2021-11-01 19:58:55 +01:00
|
|
|
// Fälle extrahieren
|
2021-11-03 11:04:59 +01:00
|
|
|
cases := []types.UserConfigCase{}
|
2021-11-01 19:58:55 +01:00
|
|
|
if config.Parts != nil && config.Parts.Cases != nil {
|
|
|
|
cases = *config.Parts.Cases
|
|
|
|
}
|
|
|
|
for i := 0; i < len(cases); i++ {
|
|
|
|
err_case = nil
|
|
|
|
problem := cases[i]
|
|
|
|
setup.DisplayStartOfCase(i, problem.Description)
|
2021-11-03 11:04:59 +01:00
|
|
|
inputs := types.UserConfigInputs{}
|
2021-11-01 19:58:55 +01:00
|
|
|
if problem.Inputs != nil {
|
|
|
|
inputs = *problem.Inputs
|
|
|
|
}
|
|
|
|
if problem.Command == nil {
|
|
|
|
err_case = fmt.Errorf("Attribute 'command:' fehlt!")
|
|
|
|
} else {
|
|
|
|
switch *problem.Command {
|
|
|
|
case "algorithm-search-binary":
|
|
|
|
L := inputs.List
|
|
|
|
x := inputs.SearchValue
|
|
|
|
if L != nil && x != nil {
|
|
|
|
_, err_case = algorithm_search_binary.FancyBinarySearch(*L, *x)
|
|
|
|
} else {
|
|
|
|
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
|
|
|
case "algorithm-search-interpolation":
|
|
|
|
L := inputs.List
|
|
|
|
x := inputs.SearchValue
|
|
|
|
if L != nil && x != nil {
|
|
|
|
_, err_case = algorithm_search_interpol.FancyInterpolationSearch(*L, *x, 0, len(*L)-1)
|
|
|
|
} else {
|
|
|
|
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
|
|
|
case "algorithm-search-ith-element":
|
|
|
|
L := inputs.List
|
|
|
|
i := inputs.SearchRank
|
|
|
|
if L != nil && i != nil {
|
|
|
|
_, err_case = algorithm_search_ith_element.FancyFindIthSmallest(*L, *i)
|
|
|
|
} else {
|
|
|
|
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
|
|
|
case "algorithm-search-ith-element-dc":
|
|
|
|
L := inputs.List
|
|
|
|
i := inputs.SearchRank
|
|
|
|
if L != nil && i != nil {
|
|
|
|
_, err_case = algorithm_search_ith_element.FancyFindIthSmallestDC(*L, *i)
|
|
|
|
} else {
|
|
|
|
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
|
|
|
case "algorithm-search-jump":
|
|
|
|
L := inputs.List
|
|
|
|
x := inputs.SearchValue
|
|
|
|
m := inputs.JumpSize
|
|
|
|
if L != nil && x != nil {
|
|
|
|
_, err_case = algorithm_search_jump.FancyJumpSearchLinear(*L, *x, *m)
|
|
|
|
} else {
|
|
|
|
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
|
|
|
case "algorithm-search-jump-exp":
|
|
|
|
L := inputs.List
|
|
|
|
x := inputs.SearchValue
|
|
|
|
if L != nil && x != nil {
|
|
|
|
_, err_case = algorithm_search_jump.FancyJumpSearchExponentiell(*L, *x)
|
|
|
|
} else {
|
|
|
|
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
|
|
|
case "algorithm-search-poison":
|
|
|
|
L := inputs.List
|
|
|
|
if L != nil {
|
|
|
|
_, err_case = algorithm_search_poison.FancyFindPoison(*L)
|
|
|
|
} else {
|
|
|
|
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
|
|
|
case "algorithm-search-poison-fast":
|
|
|
|
L := inputs.List
|
|
|
|
if L != nil {
|
|
|
|
_, err_case = algorithm_search_poison.FancyFindPoisonFast(*L)
|
|
|
|
} else {
|
|
|
|
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
|
|
|
case "algorithm-search-sequential":
|
|
|
|
L := inputs.List
|
|
|
|
x := inputs.SearchValue
|
|
|
|
if L != nil && x != nil {
|
|
|
|
_, err_case = algorithm_search_sequential.FancySequentialSearch(*L, *x)
|
|
|
|
} else {
|
|
|
|
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
2021-11-05 15:43:53 +01:00
|
|
|
case "algorithm-stacks-next-greater-element":
|
|
|
|
L := inputs.List
|
|
|
|
if L != nil {
|
|
|
|
_, err_case = algorithm_stacks_next_greater_element.FancyNextGreaterElement(*L)
|
|
|
|
} else {
|
|
|
|
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
2021-11-01 19:58:55 +01:00
|
|
|
case "algorithm-sum-maxsub":
|
|
|
|
L := inputs.List
|
|
|
|
if L != nil {
|
|
|
|
_, _, _, err_case = algorithm_sum_maxsubsum.FancyMaxSubSum(*L)
|
|
|
|
} else {
|
|
|
|
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
|
|
|
case "algorithm-sum-maxsub-dc":
|
|
|
|
L := inputs.List
|
|
|
|
if L != nil {
|
|
|
|
_, _, _, err_case = algorithm_sum_maxsubsum.FancyMaxSubSumDC(*L)
|
|
|
|
} else {
|
|
|
|
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
err_case = fmt.Errorf("Unbekannter Befehl '%[1]s'.", *problem.Command)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err_case != nil {
|
2021-11-04 11:06:16 +01:00
|
|
|
logging.Error(err_case)
|
2021-11-01 19:58:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
setup.DisplayEndOfCase()
|
2021-10-30 10:19:16 +02:00
|
|
|
return nil
|
|
|
|
}
|