48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
![]() |
package main
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
"math/rand"
|
||
|
)
|
||
|
|
||
|
// Initialize participants and workshops
|
||
|
func initializeParticipantsAndWorkshops(numParticipants, numWorkshops int) ([]Participant, []Workshop) {
|
||
|
rand.Seed(time.Now().UnixNano())
|
||
|
|
||
|
participants := make([]Participant, numParticipants)
|
||
|
for i := range participants {
|
||
|
prefs := rand.Perm(numWorkshops)[:3] // Pick 3 unique workshops
|
||
|
participants[i] = Participant{
|
||
|
ID: i + 1,
|
||
|
Preferences: []int{prefs[0] + 1, prefs[1] + 1, prefs[2] + 1}, // Convert to 1-based index
|
||
|
AssignedTo: -1,
|
||
|
RejectedFrom: make(map[int]bool),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
workshops := make([]Workshop, numWorkshops)
|
||
|
for i := range workshops {
|
||
|
workshops[i] = Workshop{
|
||
|
ID: i + 1,
|
||
|
Capacity: rand.Intn(10) + 15, // Capacity between 15 and 25
|
||
|
Participants: []int{},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return participants, workshops
|
||
|
}
|
||
|
|
||
|
// Main function
|
||
|
func main() {
|
||
|
numParticipants := 600
|
||
|
numWorkshops := 30
|
||
|
|
||
|
participants, workshops := initializeParticipantsAndWorkshops(numParticipants, numWorkshops)
|
||
|
startTime := time.Now()
|
||
|
StableMatch(participants, workshops)
|
||
|
duration := time.Since(startTime)
|
||
|
PrintAssignments(participants, workshops)
|
||
|
PrintStatistics(participants, workshops, duration)
|
||
|
}
|