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
5242395e
Commit
5242395e
authored
1 year ago
by
Balthazar Wilson
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of gitlab.utc.fr:gvandevi/ia04binome2a into copeland_and_stv
parents
fd7d3385
23126687
No related branches found
No related tags found
1 merge request
!9
Copeland and stv
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmd/main.go
+3
-1
3 additions, 1 deletion
cmd/main.go
comsoc/HelpFunctions.go
+0
-1
0 additions, 1 deletion
comsoc/HelpFunctions.go
comsoc/Majority.go
+17
-5
17 additions, 5 deletions
comsoc/Majority.go
comsoc/TieBreak.go
+32
-28
32 additions, 28 deletions
comsoc/TieBreak.go
with
52 additions
and
35 deletions
cmd/main.go
+
3
−
1
View file @
5242395e
...
@@ -10,5 +10,7 @@ func main() {
...
@@ -10,5 +10,7 @@ func main() {
//comsoc.Test_maxCount()
//comsoc.Test_maxCount()
//comsoc.Test_checkProfile()
//comsoc.Test_checkProfile()
//comsoc.Test_checkProfileAlternative()
//comsoc.Test_checkProfileAlternative()
comsoc
.
Test_MajoritySWF
()
//comsoc.Test_MajoritySWF()
//comsoc.Test_sWFFactory()
comsoc
.
Test_majority
()
}
}
This diff is collapsed.
Click to expand it.
comsoc/HelpFunctions.go
+
0
−
1
View file @
5242395e
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"fmt"
"fmt"
)
)
// cours TODO
func
plusN
(
n
int
)
func
(
i
int
)
int
{
func
plusN
(
n
int
)
func
(
i
int
)
int
{
f
:=
func
(
i
int
)
int
{
f
:=
func
(
i
int
)
int
{
return
(
i
+
n
)
return
(
i
+
n
)
...
...
This diff is collapsed.
Click to expand it.
comsoc/Majority.go
+
17
−
5
View file @
5242395e
package
comsoc
package
comsoc
import
(
"fmt"
)
// majorité simple
// Majorité simple
// fonctions de bien-être social (social welfare function, SWF) :
// retournent un décompte à partir d'un profil
// En utilisation la méthode de la majorité simple
func
MajoritySWF
(
p
Profile
)
(
count
Count
,
err
error
)
{
func
MajoritySWF
(
p
Profile
)
(
count
Count
,
err
error
)
{
count
=
make
(
Count
)
err
=
checkProfileFromProfile
(
p
)
err
=
checkProfileFromProfile
(
p
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
//initialisation de la map : comptes à 0
count
=
make
(
Count
,
len
(
p
))
for
_
,
alt
:=
range
p
[
0
]{
count
[
alt
]
=
0
}
//actualisation du compte à l'aide du scrutin
for
_
,
pref
:=
range
p
{
for
_
,
pref
:=
range
p
{
count
[
pref
[
0
]]
++
count
[
pref
[
0
]]
++
}
}
...
@@ -23,3 +26,12 @@ func MajoritySCF(p Profile) (bestAlts []Alternative, err error) {
...
@@ -23,3 +26,12 @@ func MajoritySCF(p Profile) (bestAlts []Alternative, err error) {
}
}
return
maxCount
(
count
),
err
return
maxCount
(
count
),
err
}
}
func
Test_majority
()
{
profil
:=
GenerateProfile
(
3
,
5
)
fmt
.
Println
(
"Profil :"
,
profil
)
count
,
_
:=
MajoritySWF
(
profil
)
fmt
.
Println
(
"Décompte :"
,
count
)
//winners, _ := MajoritySCF(profil)
//fmt.Println("Vainqueur(s) :", winners)
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
comsoc/TieBreak.go
+
32
−
28
View file @
5242395e
...
@@ -62,6 +62,28 @@ func SWFFactory(swf func(Profile) (Count, error), tb func([]Alternative) (Altern
...
@@ -62,6 +62,28 @@ func SWFFactory(swf func(Profile) (Count, error), tb func([]Alternative) (Altern
}
}
}
}
func
Test_sWFFactory
()
{
//Définition de l'Ordre strict
orderedAlts
:=
[]
Alternative
{
8
,
9
,
6
,
1
,
3
,
2
}
fmt
.
Println
(
"Ordre strict :"
,
orderedAlts
)
//Construction d'un profil avec alternatives ex aequo
profil
:=
make
([][]
Alternative
,
2
)
profil
[
0
]
=
[]
Alternative
{
1
,
2
,
3
,
4
,
5
,
6
}
profil
[
1
]
=
[]
Alternative
{
3
,
2
,
1
,
4
,
5
,
6
}
fmt
.
Println
(
"Profil :"
,
profil
)
//Construction de la fonction Tie Break
lambda
:=
TieBreakFactory
(
orderedAlts
)
//Construction de la Social Welfare Factory à partir de la fonction swf + la fonction de TieBreak
mu
:=
SWFFactory
(
MajoritySWF
,
lambda
)
// mu := SWFFactory(BordaSWF, lambda)
//Construction d'une fonction
sorted_alts
,
_
:=
mu
(
profil
)
fmt
.
Println
(
"Alternatives strictement ordonnées selon la méthode de Borda :"
,
sorted_alts
)
}
func
SWFFactoryWithOptions
(
func
SWFFactoryWithOptions
(
swf
func
(
Profile
,
[]
int
)
(
Count
,
error
),
swf
func
(
Profile
,
[]
int
)
(
Count
,
error
),
tb
func
([]
Alternative
)
(
Alternative
,
error
),
tb
func
([]
Alternative
)
(
Alternative
,
error
),
...
@@ -103,30 +125,14 @@ func SWFFactoryWithOptions(
...
@@ -103,30 +125,14 @@ func SWFFactoryWithOptions(
}
}
}
}
func
Test_sWFFactory
()
{
//Définition de l'Ordre strict
orderedAlts
:=
[]
Alternative
{
8
,
9
,
6
,
1
,
3
,
2
}
fmt
.
Println
(
"Ordre strict :"
,
orderedAlts
)
//Construction d'un profil avec alternatives ex aequo
func
SCFFactoryWithOptions
(
profil
:=
make
([][]
Alternative
,
2
)
scf
func
(
Profile
,
[]
int
)
([]
Alternative
,
error
),
profil
[
0
]
=
[]
Alternative
{
1
,
2
,
3
,
4
,
5
,
6
}
tb
func
([]
Alternative
)
(
Alternative
,
error
),
profil
[
1
]
=
[]
Alternative
{
3
,
2
,
1
,
4
,
5
,
6
}
)
func
(
Profile
,
[]
int
)
(
Alternative
,
error
)
{
fmt
.
Println
(
"Profil :"
,
profil
)
return
func
(
p
Profile
,
o
[]
int
)
(
Alternative
,
error
)
{
//Construction de la fonction Tie Break
lambda
:=
TieBreakFactory
(
orderedAlts
)
//Construction de la Social Welfare Factory à partir de la fonction swf + la fonction de TieBreak
mu
:=
SWFFactory
(
BordaSWF
,
lambda
)
//Construction d'une fonction
sorted_alts
,
_
:=
mu
(
profil
)
fmt
.
Println
(
"Alternatives strictement ordonnées selon la méthode de Borda :"
,
sorted_alts
)
}
func
SCFFactory
(
scf
func
(
p
Profile
)
([]
Alternative
,
error
),
tb
func
([]
Alternative
)
(
Alternative
,
error
))
func
(
Profile
)
(
Alternative
,
error
)
{
return
func
(
p
Profile
)
(
Alternative
,
error
)
{
//récupération des meilleures alternatives
//récupération des meilleures alternatives
bestAlts
,
errSCF
:=
scf
(
p
)
bestAlts
,
errSCF
:=
scf
(
p
,
o
)
if
errSCF
!=
nil
{
if
errSCF
!=
nil
{
return
Alternative
(
0
),
errSCF
return
Alternative
(
0
),
errSCF
}
}
...
@@ -136,13 +142,10 @@ func SCFFactory(scf func(p Profile) ([]Alternative, error), tb func([]Alternativ
...
@@ -136,13 +142,10 @@ func SCFFactory(scf func(p Profile) ([]Alternative, error), tb func([]Alternativ
}
}
}
}
func
SCFFactoryWithOptions
(
func
SCFFactory
(
scf
func
(
p
Profile
)
([]
Alternative
,
error
),
tb
func
([]
Alternative
)
(
Alternative
,
error
))
func
(
Profile
)
(
Alternative
,
error
)
{
scf
func
(
Profile
,
[]
int
)
([]
Alternative
,
error
),
return
func
(
p
Profile
)
(
Alternative
,
error
)
{
tb
func
([]
Alternative
)
(
Alternative
,
error
),
)
func
(
Profile
,
[]
int
)
(
Alternative
,
error
)
{
return
func
(
p
Profile
,
o
[]
int
)
(
Alternative
,
error
)
{
//récupération des meilleures alternatives
//récupération des meilleures alternatives
bestAlts
,
errSCF
:=
scf
(
p
,
o
)
bestAlts
,
errSCF
:=
scf
(
p
)
if
errSCF
!=
nil
{
if
errSCF
!=
nil
{
return
Alternative
(
0
),
errSCF
return
Alternative
(
0
),
errSCF
}
}
...
@@ -152,6 +155,7 @@ func SCFFactoryWithOptions(
...
@@ -152,6 +155,7 @@ func SCFFactoryWithOptions(
}
}
}
}
func
Test_sCFFactory
()
{
func
Test_sCFFactory
()
{
//Définition de l'Ordre strict
//Définition de l'Ordre strict
orderedAlts
:=
[]
Alternative
{
8
,
9
,
6
,
1
,
3
,
2
}
orderedAlts
:=
[]
Alternative
{
8
,
9
,
6
,
1
,
3
,
2
}
...
...
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