-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (43 loc) · 1.26 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"github.com/rodrigo-brito/facility-location/model/network"
"github.com/rodrigo-brito/facility-location/model/solver"
"github.com/spf13/cobra"
"github.com/rodrigo-brito/facility-location/util/log"
)
func run(inputFile string, asyncLimit int, verbose bool, targetValue float64) {
log.Init(verbose)
network, err := network.FromFile(inputFile)
if err != nil {
log.Fatal(err)
}
network.MaxAsyncTask = asyncLimit
solver := solver.New(
solver.WithNetworkData(network),
solver.WithMaxAsyncTasks(asyncLimit),
solver.WithTarget(targetValue),
solver.WithVerboseMode(verbose),
)
solver.Solve()
}
func main() {
var (
async int
verbose bool
targetValue float64
)
var rootCmd = &cobra.Command{
Use: "hub-spoke-go [input-file]",
Short: "Read input file and create a network design",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
run(args[0], async, verbose, targetValue)
},
}
rootCmd.Flags().IntVarP(&async, "async", "a", 4, "number of async tasks")
rootCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "active verbose mode")
rootCmd.Flags().Float64VarP(&targetValue, "best", "b", 0, "value of the best solution")
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
}