-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
176 lines (155 loc) · 4.68 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package main
import (
"flag"
"fmt"
"math"
"time"
)
const baseTime = 23 * 60
var carry int
var maxScavenge int
var verbose bool
var debug bool
var mode int
type raubzug struct {
timeFact float64
carryFact float64
name string
}
func main() {
flag.IntVar(&carry, "t", 1000, "Die Gesamte Tragekapazität der freien Einheiten, die aufgeteilt werden soll")
flag.IntVar(&maxScavenge, "m", 4, "Falls noch nicht alle Raubzüge freigeschalten wurden, kann hier eine Zahl von 1 bis 4 übergeben werden")
flag.IntVar(&mode, "mode", 0, "Der Modus, der für die Berechnung verwendet werden soll. 0) Alles berechnen 1) Maximale Ressourcen pro Stunde 2) Identische Zeit")
flag.BoolVar(&verbose, "verbose", false, "Mehr Informationen ausgeben")
flag.BoolVar(&debug, "debug", false, "Technische Informationen ausgeben")
flag.Parse()
if maxScavenge > 4 || maxScavenge < 1 {
fmt.Println("Der maximale Raubzug muss zwischen 1 und 4 liegen")
return
}
step := 25
for carry >= step*1000 {
step = step * 10
}
for carry >= step*200 {
step = step * 2
}
if carry%step != 0 {
oldCarry := carry
carry += step - carry%step
fmt.Printf("Tragekapazität %d ist nicht durch %d teilbar, wurde auf %d erhöht\n", oldCarry, step, carry)
}
if verbose {
fmt.Printf("Using stepsize of %d\n", step)
}
var scavenges []raubzug
scavenges = append(scavenges, raubzug{
name: "1",
timeFact: 1,
carryFact: 0.1,
})
scavenges = append(scavenges, raubzug{
name: "2",
timeFact: 2.5,
carryFact: 0.25,
})
scavenges = append(scavenges, raubzug{
name: "3",
timeFact: 5,
carryFact: 0.5,
})
scavenges = append(scavenges, raubzug{
name: "4",
timeFact: 7.5,
carryFact: 0.75,
})
ch := make(chan []int)
total := carry
var partial []int
go func() {
subset_sum(ch, total, partial, 0, step)
close(ch)
}()
var bestScore float64 = 0
var bestScoreThing []int
var bestTimeDifference float64 = 9999999999999999999
var bestTimeDifferenceScore float64 = 0
var bestTimeDifferenceThing []int
for thing := range ch {
var thisScore float64 = 0
var thisMinTime float64 = 9999999999999999999
var thisMaxTime float64 = 0
for i := 0; i < len(thing); i++ {
t, _, sc := scavenges[i].calc(thing[i])
if t > thisMaxTime {
thisMaxTime = t
}
if t < thisMinTime {
thisMinTime = t
}
thisScore += sc
}
if mode == 0 || mode == 2 {
if (thisMaxTime-thisMinTime) < bestTimeDifference && len(thing) == maxScavenge {
if verbose {
fmt.Printf("%7.0f with config %v\n", thisMaxTime-thisMinTime, thing)
}
bestTimeDifference = thisMaxTime - thisMinTime
bestTimeDifferenceScore = thisScore
bestTimeDifferenceThing = thing
}
}
if mode == 0 || mode == 1 {
if thisScore > bestScore {
if verbose {
fmt.Printf("%7.0f res/h with config %v\n", thisScore, thing)
}
bestScore = thisScore + 0.01
bestScoreThing = thing
}
}
}
if mode == 0 || mode == 1 {
fmt.Println("Maximum Ressources per Minute:")
for i := 0; i < len(bestScoreThing); i++ {
seconds, carry, sc := scavenges[i].calc(bestScoreThing[i])
userTime := time.Duration(seconds) * time.Second
fmt.Printf("Scavenge %s: %8d @ %7.0f res/h (%.0f resources in %s)\n", scavenges[i].name, bestScoreThing[i], sc, carry, userTime.String())
}
fmt.Printf("Total @ %7.0f res/h:\n\n", bestScore)
}
if mode == 0 || mode == 2 {
fmt.Println("Identical Time:")
for i := 0; i < len(bestTimeDifferenceThing); i++ {
seconds, carry, sc := scavenges[i].calc(bestTimeDifferenceThing[i])
userTime := time.Duration(seconds) * time.Second
fmt.Printf("Scavenge %s: %8d @ %7.0f res/h (%.0f resources in %s)\n", scavenges[i].name, bestTimeDifferenceThing[i], sc, carry, userTime.String())
}
fmt.Printf("Total @ %7.0f res/h:\n\n", bestTimeDifferenceScore)
}
}
func (scav raubzug) calc(total int) (float64, float64, float64) {
time := math.Pow(float64(total)*scav.timeFact, 0.881) + baseTime
carry := float64(total) * scav.carryFact
score := carry / time * 60 * 60
return time, carry, score
}
func subset_sum(result chan []int, max int, partial []int, partial_sum int, step int) {
if debug {
fmt.Printf("%v %v %v %v\n", max, partial, partial_sum, step)
}
if partial_sum == max {
tmp := make([]int, len(partial))
copy(tmp, partial)
result <- tmp
}
if partial_sum >= max {
return
}
if len(partial) == maxScavenge {
return
}
for i := 0; i <= max; i += step {
subset_sum(result, max, append(partial, i), partial_sum+i, int(math.Min(float64(step), float64(max-i))))
}
}