This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
69 lines (62 loc) · 1.66 KB
/
context.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
package main
import (
"fmt"
// "math"
"time"
)
type Context struct {
Libraries []Library
DayMax int
}
func (c *Context) CreatePlan() Plan {
plan := Plan{}
plan.SortedLibraries = make([]Library, len(c.Libraries))
totalScore := 0
remainingDays := c.DayMax
for iSortedLibs := 0; iSortedLibs < len(c.Libraries); iSortedLibs++ {
startTime := time.Now()
maxRentability := 0.0
maxSum := 0
maxSumI := 0
for i := range c.Libraries {
c.Libraries[i].Sort()
sum := c.Libraries[i].BookValueSum(remainingDays)
rentabilityCoef := 0.00000001
if c.Libraries[i].SignupTime > 0 {
rentabilityCoef = float64(c.Libraries[i].SignupTime) / float64(remainingDays)
}
rentability := float64(sum) / rentabilityCoef
// fmt.Printf("rentability: %.2f\n", rentability)
if rentability > maxRentability {
maxRentability = rentability
maxSum = sum
maxSumI = i
}
}
plan.SortedLibraries[iSortedLibs] = c.Libraries[maxSumI]
for i := range c.Libraries[maxSumI].Books {
for j := range c.Libraries {
if j == maxSumI {
continue
}
c.Libraries[j].SetBookAsUsed(c.Libraries[maxSumI].Books[i].ID)
}
}
totalScore += maxSum
// fmt.Printf("\nSum: %d\n", maxSum)
if iSortedLibs%9 == 0 || maxSum == 0 {
fmt.Printf("\rProgress : %d/%d (%dms) (current score: %d)", iSortedLibs+1, len(plan.SortedLibraries), time.Now().Sub(startTime).Milliseconds(), totalScore)
}
if maxSum == 0 {
break
}
remainingDays -= c.Libraries[maxSumI].SignupTime
c.Libraries[maxSumI] = c.Libraries[len(c.Libraries)-1]
c.Libraries = c.Libraries[:len(c.Libraries)-1]
// if iSortedLibs == 1000 {
// break
// }
}
fmt.Printf("\n")
return plan
}