Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IA04binôme2A
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gabrielle Van De Vijver
IA04binôme2A
Commits
a5fe5c10
Commit
a5fe5c10
authored
1 year ago
by
Benoit Chevillon
Browse files
Options
Downloads
Patches
Plain Diff
Gagnant de condorcet
parent
17ead0ce
No related branches found
Branches containing commit
No related tags found
1 merge request
!2
Benoit
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
comsoc/Approval.go
+20
-4
20 additions, 4 deletions
comsoc/Approval.go
comsoc/CondorcetWinner.go
+29
-1
29 additions, 1 deletion
comsoc/CondorcetWinner.go
comsoc/HelpFunctions.go
+5
-4
5 additions, 4 deletions
comsoc/HelpFunctions.go
comsoc/Majority.go
+0
-52
0 additions, 52 deletions
comsoc/Majority.go
with
54 additions
and
61 deletions
comsoc/Approval.go
+
20
−
4
View file @
a5fe5c10
package
comsoc
import
"fmt"
func
Test1
()
{
fmt
.
Println
(
"Hello, World!"
)
}
\ No newline at end of file
// Vote par approbation
// thresholds est un slice d'entiers strictement positifs
func
ApprovalSWF
(
p
Profile
,
thresholds
[]
int
)
(
count
Count
,
err
error
)
{
count
=
make
(
Count
)
for
_
,
pref
:=
range
p
{
for
index
,
alt
:=
range
pref
{
count
[
alt
]
+=
thresholds
[
len
(
thresholds
)
-
1
-
index
]
}
}
return
count
,
nil
}
func
ApprovalSCF
(
p
Profile
,
thresholds
[]
int
)
(
bestAlts
[]
Alternative
,
err
error
)
{
count
,
err
:=
ApprovalSWF
(
p
,
thresholds
)
if
err
!=
nil
{
return
nil
,
err
}
return
maxCount
(
count
),
nil
}
This diff is collapsed.
Click to expand it.
comsoc/CondorcetWinner.go
+
29
−
1
View file @
a5fe5c10
package
comsoc
\ No newline at end of file
package
comsoc
// Gagnant de condorcet, retourne un slice vide ou de 1 élément
// A vérifier avec plus d'exemples
func
CondorcetWinner
(
p
Profile
)
(
bestAlts
[]
Alternative
,
err
error
)
{
for
_
,
alt1
:=
range
p
[
0
]
{
winner
:=
true
for
_
,
alt2
:=
range
p
[
0
]
{
if
alt1
!=
alt2
{
nbAlt1
:=
0
nbAlt2
:=
0
for
_
,
pref
:=
range
p
{
if
isPref
(
alt1
,
alt2
,
pref
)
{
nbAlt1
++
}
else
{
nbAlt2
++
}
}
if
nbAlt1
<=
nbAlt2
{
winner
=
false
}
}
}
if
winner
{
return
[]
Alternative
{
alt1
},
nil
}
}
return
[]
Alternative
{},
nil
}
This diff is collapsed.
Click to expand it.
comsoc/HelpFunctions.go
+
5
−
4
View file @
a5fe5c10
...
...
@@ -114,12 +114,13 @@ func Test_checkProfileAlternative() {
}
func
Test_MajoritySWF
()
{
pref1
:=
[]
Alternative
{
5
,
3
,
1
,
4
,
2
}
pref2
:=
[]
Alternative
{
2
,
1
,
4
,
3
,
5
}
Pref
:=
[][]
Alternative
{
pref1
,
pref2
}
pref1
:=
[]
Alternative
{
1
,
2
,
3
}
pref2
:=
[]
Alternative
{
2
,
3
,
1
}
pref3
:=
[]
Alternative
{
3
,
1
,
2
}
Pref
:=
[][]
Alternative
{
pref1
,
pref2
,
pref3
}
profil
:=
Profile
(
Pref
)
fmt
.
Println
(
MajoritySWF
(
profil
))
c
,
_
:=
ApprovalSWF
(
profil
,
[]
int
{
1
,
2
,
3
,
4
,
5
})
fmt
.
Println
(
c
[
Alternative
(
2
)])
//
fmt.Println(CondorcetWinner(profil))
fmt
.
Println
(
CondorcetWinner
(
profil
))
}
This diff is collapsed.
Click to expand it.
comsoc/Majority.go
+
0
−
52
View file @
a5fe5c10
...
...
@@ -19,55 +19,3 @@ func MajoritySCF(p Profile) (bestAlts []Alternative, err error) {
}
return
maxCount
(
count
),
nil
}
func
ApprovalSWF
(
p
Profile
,
thresholds
[]
int
)
(
count
Count
,
err
error
)
{
count
=
make
(
Count
)
for
_
,
pref
:=
range
p
{
for
index
,
alt
:=
range
pref
{
count
[
alt
]
+=
thresholds
[
len
(
thresholds
)
-
1
-
index
]
}
}
return
count
,
nil
}
func
ApprovalSCF
(
p
Profile
,
thresholds
[]
int
)
(
bestAlts
[]
Alternative
,
err
error
)
{
count
,
err
:=
ApprovalSWF
(
p
,
thresholds
)
if
err
!=
nil
{
return
nil
,
err
}
return
maxCount
(
count
),
nil
}
// Gagnant de condorcet, retourne un slice vide ou de 1 élément
// Utilise la majorité simple sur chaque paire de candidat
/*
func CondorcetWinner(p Profile) (bestAlts []Alternative, err error) {
for _, alt1 := range p[0] {
winner := true
for _, alt2 := range p[0] {
if alt1 != alt2 {
p2 := make(Profile, len(p))
for index, pref := range p {
if isPref(alt1, alt2, pref) {
p2[index] = append(p2[index], alt1)
} else {
p2[index] = append(p2[index], alt2)
}
}
count, err := MajoritySCF(p2)
if err != nil {
return nil, err
}
if count[alt2] >= count[alt1] {
winner = false
break
}
}
}
if winner {
return []Alternative{alt1}, nil
}
}
return []Alternative{}, nil
}
*/
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment