Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2024_compilation_Bazizi_Zaynoune
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
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
BAZIZI Zakaria
2024_compilation_Bazizi_Zaynoune
Commits
43f2a2e4
Commit
43f2a2e4
authored
1 year ago
by
Alexis Nasr
Browse files
Options
Downloads
Patches
Plain Diff
ajout de l'implémentation de l'algo de coloration de graphes
parent
7729740d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/util/graph/ColorGraph.java
+124
-0
124 additions, 0 deletions
src/util/graph/ColorGraph.java
with
124 additions
and
0 deletions
src/util/graph/ColorGraph.java
+
124
−
0
View file @
43f2a2e4
...
@@ -34,5 +34,129 @@ public class ColorGraph {
...
@@ -34,5 +34,129 @@ public class ColorGraph {
}
}
}
}
/*-------------------------------------------------------------------------------------------------------------*/
/* associe une couleur à tous les sommets se trouvant dans la pile */
/*-------------------------------------------------------------------------------------------------------------*/
public
void
select
()
{
int
t
;
while
(!
stack
.
empty
()){
t
=
stack
.
pop
();
removed
.
remove
(
t
);
if
(
color
[
t
]
==
NOCOLOR
)
color
[
t
]
=
chooseAvailableColor
(
neighborsColor
(
t
));
if
(
color
[
t
]
==
NOCOLOR
)
System
.
out
.
println
(
"cannot find a color for vertex "
+
t
);
}
}
/*-------------------------------------------------------------------------------------------------------------*/
/* récupère les couleurs des voisins de t */
/*-------------------------------------------------------------------------------------------------------------*/
public
IntSet
neighborsColor
(
int
t
)
{
IntSet
colorSet
=
new
IntSet
(
colorNb
);
for
(
NodeList
p
=
int2Node
[
t
].
succ
();
p
!=
null
;
p
=
p
.
tail
)
if
(
color
[
p
.
head
.
label
()]
!=
NOCOLOR
)
colorSet
.
add
(
color
[
p
.
head
.
label
()]);
return
colorSet
;
}
/*-------------------------------------------------------------------------------------------------------------*/
/* recherche une couleur absente de colorSet */
/*-------------------------------------------------------------------------------------------------------------*/
public
int
chooseAvailableColor
(
IntSet
colorSet
)
{
for
(
int
c
=
0
;
c
<
colorSet
.
getSize
();
c
++)
if
(!
colorSet
.
isMember
(
c
))
return
c
;
return
NOCOLOR
;
}
/*-------------------------------------------------------------------------------------------------------------*/
/* calcule le nombre de voisins du sommet t */
/*-------------------------------------------------------------------------------------------------------------*/
public
int
neighborsNb
(
int
t
)
{
int
nb
=
0
;
for
(
NodeList
p
=
this
.
int2Node
[
t
].
succ
();
p
!=
null
;
p
=
p
.
tail
)
if
(!
removed
.
isMember
(
p
.
head
.
label
()))
nb
++;
return
nb
;
}
/*-------------------------------------------------------------------------------------------------------------*/
/* simplifie le graphe d'interférence g */
/* la simplification consiste à enlever du graphe les temporaires qui ont moins de k voisins */
/* et à les mettre dans une pile */
/* à la fin du processus, le graphe peut ne pas être vide, il s'agit des temporaires qui ont au moins k voisin */
/*-------------------------------------------------------------------------------------------------------------*/
public
int
simplify
()
{
boolean
removedAtLeastOneTemp
=
true
;
while
(
removedAtLeastOneTemp
&&
stack
.
size
()
!=
vertexNb
){
removedAtLeastOneTemp
=
false
;
for
(
int
t
=
0
;
t
<
vertexNb
;
t
++){
if
(!
removed
.
isMember
(
t
)){
int
n
=
neighborsNb
(
t
);
// System.out.println("node " + t + " has " + n + " neighbours");
int
precolored
=
(
color
[
t
]
==
NOCOLOR
)?
0
:
1
;
if
(
n
<
(
colorNb
-
precolored
)){
stack
.
push
(
t
);
removed
.
add
(
t
);
// System.out.println("remove vertex " + t);
removedAtLeastOneTemp
=
true
;
}
}
}
}
return
stack
.
size
();
}
/*-------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------*/
public
void
spill
()
{
int
t
;
while
(
stack
.
size
()
!=
vertexNb
){
/* some nodes have not been pushed */
for
(
t
=
0
;
t
<
vertexNb
;
t
++){
if
(!
removed
.
isMember
(
t
)){
/* t i still in the graph */
System
.
out
.
println
(
"vertex "
+
t
+
" is a potential spill"
);
spill
.
add
(
t
);
removed
.
add
(
t
);
stack
.
push
(
t
);
simplify
();
}
}
}
}
/*-------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------*/
public
void
color
()
{
this
.
simplify
();
this
.
spill
();
this
.
select
();
}
public
void
affiche
()
{
System
.
out
.
println
(
"vertex\tcolor"
);
for
(
int
i
=
0
;
i
<
vertexNb
;
i
++){
System
.
out
.
println
(
i
+
"\t"
+
color
[
i
]);
}
}
}
}
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