Skip to content

Instantly share code, notes, and snippets.

@emineker
Last active December 17, 2015 07:59
Show Gist options
  • Save emineker/5576723 to your computer and use it in GitHub Desktop.
Save emineker/5576723 to your computer and use it in GitHub Desktop.
Atama algoritması 2: gruptan proje atama
package main
import (
"fmt"
"math"
)
// grup bilgileri
// id, grup adı, not ortalaması, kişi sayısı, proje tercihleri(id)
type Group struct {
id string
name string
not_avg float64
scount int
choices []string
}
// projelerin bilgileri
// id, kod adı, kişi sayısı
type Project struct {
id string
name string
scount int
}
type Assignment struct {
group_id string
project_id string
}
var (
groups_list = []Group{
{"1", "Gizem Hergüner", 61.44, 4, []string{"9", "2", "15", "14", "3", "1", "8", "11", "6", "12", "17", "4", "3", "10", "16", "18", "5", "7", "19", "20"}},
{"2", "Emre Can Yılmaz", 65.48, 4, []string{"11", "13", "8", "12", "14", "7", "18", "16", "4", "3", "15", "6", "2", "10", "9", "5", "17", "19", "1", "20"}},
{"3", "Seda Çağlar", 57.12, 4, []string{"3", "19", "9", "16", "14", "13", "4", "10", "17", "5", "2", "18", "15", "8", "7", "6", "12", "11", "1", "20"}},
{"4", "Canan Demirel", 67.99, 4, []string{"14", "13", "20", "19", "9", "2", "17", "18", "3", "15", "12", "11", "16", "10", "1", "7", "6", "5", "4", "8"}},
{"5", "Eldar Fayzulov", 61.70, 4, []string{"2", "16", "1", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "17", "18", "19", "20"}},
{"6", "Faruk Can", 70.75, 3, []string{"12", "13", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "14", "15", "16", "17", "18", "19", "20"}},
{"7", "Ali Burak Öncül", 65.19, 4, []string{"9", "16", "1", "2", "3", "4", "5", "6", "7", "8", "10", "11", "12", "13", "14", "15", "17", "18", "19", "20"}},
{"8", "Meltem Aydoğan", 68.72, 3, []string{"13", "14", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "15", "16", "17", "18", "19", "20"}},
{"9", "Atakan Erdal", 43.96, 4, []string{"12", "14", "3", "4", "13", "7", "8", "11", "18", "5", "9", "16", "17", "19", "15", "2", "6", "10", "1", "20"}},
{"10", "Ali Uslucan", 68.41, 2, []string{"7", "9", "1", "2", "3", "4", "5", "6", "8", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"}},
{"11", "Ali Daşbaşı", 65.16, 4, []string{"8", "14", "13", "1", "2", "3", "4", "5", "6", "7", "9", "10", "11", "12", "15", "16", "17", "18", "19", "20"}},
{"12", "Hasan Arslan", 67.49, 3, []string{"6", "8", "1", "2", "3", "4", "5", "7", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"}},
{"13", "Bahar Temiz", 46.47, 4, []string{"14", "12", "4", "3", "13", "7", "11", "8", "18", "5", "16", "9", "17", "19", "15", "2", "10", "6", "1", "20"}},
{"14", "Tarık Baki", 65.07, 4, []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"}},
{"15", "Derya Uzun", 71.44, 4, []string{"14", "9", "13", "4", "12", "3", "19", "1", "11", "18", "16", "17", "15", "8", "5", "7", "2", "10", "6", "20"}},
}
projects_list = []Project{
{"1", "EK-lego", 4},
{"2", "KE-plaka", 4},
{"3", "SA-kep", 4},
{"4", "SA-drop", 4},
{"5", "SA-kript", 4},
{"6", "NŞ-maket", 3},
{"7", "NŞ-sanal", 2},
{"8", "NŞ-pys", 4},
{"9", "EE-m2ses", 4},
{"10", "EE-3d", 4},
{"11", "RO-pys", 4},
{"12", "RO-web", 3},
{"13", "OB-uzman", 3},
{"14", "OB-mezun", 3},
{"15", "KE-dhcp", 4},
{"16", "KE-ubs", 4},
{"17", "İİ-wminer", 4},
{"18", "KE-pass", 4},
{"19", "İİ-learn", 4},
{"20", "GK-NŞ-SYS", 4},
}
)
// students'in orijinal tercih bilgileri kullanarak grup-proje uyumluluk puanını hesapla
func project_compatibility(group Group, project Project) float64 {
// tercih listesindeki proje sayısı
group_choices := group.choices
project_id := project.id
pcount := len(group_choices)
choice_index := 0
// proje listede kaçıncı sırada tercih edilmiş (tersten)
for index, choice := range group_choices {
if choice == project_id {
choice_index = index
break
}
}
// grubun puanlarının ortalamasını döndür
return float64(((pcount - choice_index) * 100) / pcount)
}
// grup ve projenin kişi sayısı uyumluluğu
func n_compatibility(group Group, project Project) float64 {
count := project.scount - group.scount
score := 100.0
if count != 0 {
score /= (math.Abs(float64(count)) + 1)
}
return score
}
// verilen grupların kriterlere göre puanlar
func score(group Group, project Project) float64 {
// kriterlerin ağırlıkları
weights := []float64{0.20, 0.50, 0.30}
// kriterleri ve ağırlıkları kullanarak puanı hesapla
score := group.not_avg * weights[0]
score += n_compatibility(group, project) * weights[1]
score += project_compatibility(group, project) * weights[2]
return score
}
func calculate_scores(groups_list []Group, projects_list []Project) [][]float64 {
scores := [][]float64{}
n_groups := len(groups_list)
n_projects := len(projects_list)
for i := 0; i < n_groups; i++ {
new_array := []float64{}
for j := 0; j < n_projects; j++ {
new_array = append(new_array, score(groups_list[i], projects_list[j]))
}
scores = append(scores, new_array)
}
return scores
}
func find_max(scores [][]float64) []int {
all_max := 0.0
group_index := 0
project_index := 0
for gi, score := range scores {
row_max, pi := 0.0, 0
// satırdaki max değeri bul
for i, s := range score {
if s > float64(row_max) {
row_max = s
pi = i
}
}
// tüm satırlardaki max değeri bul
if row_max > all_max {
all_max = row_max
group_index = gi
project_index = pi
}
}
return []int{group_index, project_index}
}
func clean(scores [][]float64, winner []int) [][]float64 {
group_index, project_index := winner[0], winner[1]
for i := range scores[group_index] {
scores[group_index][i] = 0
}
for i := range scores {
scores[i][project_index] = 0
}
return scores
}
func index2id(winner []int) []string {
group_id, project_id := "", ""
for i, group := range groups_list {
if i == winner[0] {
group_id = group.id
break
}
}
for i, project := range projects_list {
if i == winner[1] {
project_id = project.id
break
}
}
return []string{group_id, project_id}
}
func main() {
// atamalar
assignments := []Assignment{}
// öğrenci listesinin uzunluğu 0 olana kadar
scores := calculate_scores(groups_list, projects_list)
// tüm atamalar yapılana kadar
for len(assignments) != len(groups_list) {
// en yüksek uyumluluğu bul
winner := find_max(scores)
// kazananları temizle
scores = clean(scores, winner)
// indislerden id'leri bul
winner_ids := index2id(winner)
// ata
assignments = append(assignments, Assignment{winner_ids[0], winner_ids[1]})
}
fmt.Println("\nAtamalar:\n-----------------------------------")
for _, assignment := range assignments {
group_name, project_name := "", ""
for _, group := range groups_list {
if group.id == assignment.group_id {
group_name = group.name
}
}
for _, project := range projects_list {
if project.id == assignment.project_id {
project_name = project.name
}
}
fmt.Println(group_name, "\t|", project_name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment