Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tp3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AREZKI Celia
Tp3
Commits
c96750e8
Commit
c96750e8
authored
6 months ago
by
AREZKI Celia
Browse files
Options
Downloads
Patches
Plain Diff
Graph : completing the class methods
parent
dbd09d2e
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.idea/misc.xml
+1
-1
1 addition, 1 deletion
.idea/misc.xml
src/Graph/Arc.java
+4
-4
4 additions, 4 deletions
src/Graph/Arc.java
src/Graph/Graph.java
+68
-13
68 additions, 13 deletions
src/Graph/Graph.java
with
73 additions
and
18 deletions
.idea/misc.xml
+
1
−
1
View file @
c96750e8
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_13"
default=
"false"
project-jdk-name=
"
13
"
project-jdk-type=
"JavaSDK"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_13"
project-jdk-name=
"
jbr-17
"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/out"
/>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Graph/Arc.java
+
4
−
4
View file @
c96750e8
This diff is collapsed.
Click to expand it.
src/Graph/Graph.java
+
68
−
13
View file @
c96750e8
...
...
@@ -27,42 +27,97 @@ public class Graph {
// par suppression de sommet, ou l'opération de contraction d’arête.
// Autrement, on pourra asssumer que upperBound==order.
// à compléter
this
.
upperBound
=
upperBound
;
this
.
order
=
0
;
this
.
edgeCardinality
=
0
;
this
.
incidency
=
new
ArrayList
<>(
upperBound
);
this
.
inIncidency
=
new
ArrayList
<>(
upperBound
);
this
.
outIncidency
=
new
ArrayList
<>(
upperBound
);
for
(
int
i
=
0
;
i
<
upperBound
;
i
++)
{
incidency
.
add
(
new
LinkedList
<>());
inIncidency
.
add
(
new
LinkedList
<>());
outIncidency
.
add
(
new
LinkedList
<>());
}
}
public
boolean
isVertex
(
int
vertex
)
{
// Après avori supprimé certains sommets
// pas tous le sommets numerotés 0,...,n-1 sont 'vivant'.
// à compléter
return
true
;
return
vertex
>=
0
&&
vertex
<
order
&&
incidency
.
get
(
vertex
)
!=
null
;
}
public
void
addVertex
(
int
vertex
)
{
// à compléter
if
(
vertex
>=
upperBound
)
{
throw
new
IllegalArgumentException
(
"Sommet hors limites."
);
}
while
(
incidency
.
size
()
<=
vertex
)
{
incidency
.
add
(
new
LinkedList
<>());
inIncidency
.
add
(
new
LinkedList
<>());
outIncidency
.
add
(
new
LinkedList
<>());
}
order
=
Math
.
max
(
order
,
vertex
+
1
);
}
public
void
deleteVertex
(
int
vertex
)
{
// à compléter
if
(
vertex
>=
incidency
.
size
()
||
incidency
.
get
(
vertex
)
==
null
)
{
throw
new
IllegalArgumentException
(
"Sommet inexistant."
);
}
for
(
Edge
edge
:
incidency
.
get
(
vertex
))
{
int
other
=
edge
.
oppositeExtremity
(
vertex
);
incidency
.
get
(
other
).
remove
(
edge
);
}
incidency
.
set
(
vertex
,
null
);
inIncidency
.
set
(
vertex
,
null
);
outIncidency
.
set
(
vertex
,
null
);
}
public
void
ensureVertex
(
int
vertex
)
{
// Synonime de addVertex ?
// à compléter
public
void
ensureVertex
(
int
vertex
)
{
if
(
vertex
>=
upperBound
)
{
throw
new
IllegalArgumentException
(
"Sommet hors limites."
);
}
if
(
incidency
.
size
()
<=
vertex
){
addVertex
(
vertex
);
}
}
public
void
addArc
(
Arc
arc
)
{
// à compléter
int
source
=
arc
.
getSource
();
int
dest
=
arc
.
getDest
();
ensureVertex
(
source
);
ensureVertex
(
dest
);
outIncidency
.
get
(
source
).
add
(
arc
);
inIncidency
.
get
(
dest
).
add
(
arc
);
}
public
void
addEdge
(
Edge
edge
)
{
// à compléter
int
source
=
edge
.
getSource
();
int
dest
=
edge
.
getDest
();
addVertex
(
source
);
addVertex
(
dest
);
incidency
.
get
(
source
).
add
(
edge
);
incidency
.
get
(
dest
).
add
(
edge
);
addArc
(
new
Arc
(
edge
,
false
));
addArc
(
new
Arc
(
edge
,
true
));
edgeCardinality
++;
}
public
Arc
[]
outEdges
(
int
vertex
)
{
// à modifier, si nécessaire
public
Arc
[]
outEdges
(
int
vertex
)
{
if
(!
isVertex
(
vertex
))
{
throw
new
IllegalArgumentException
(
"Sommet inexistant."
);
}
// Pour la prochaine ligne voir
// https://www.baeldung.com/java-collection-toarray-methods
return
outIncidency
.
get
(
vertex
).
toArray
(
new
Arc
[
0
]);
...
...
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