Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlgoTP03
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TOUMERT Said
AlgoTP03
Commits
f8d92e03
Commit
f8d92e03
authored
3 years ago
by
Luigi Santocanale
Browse files
Options
Downloads
Patches
Plain Diff
modified: src/GraphClasses/Complete.java
modified: src/GraphClasses/Grid.java modified: src/Main.java
parent
29107204
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/GraphClasses/Complete.java
+12
-14
12 additions, 14 deletions
src/GraphClasses/Complete.java
src/GraphClasses/Grid.java
+89
-88
89 additions, 88 deletions
src/GraphClasses/Grid.java
src/Main.java
+5
-4
5 additions, 4 deletions
src/Main.java
with
106 additions
and
106 deletions
src/GraphClasses/Complete.java
+
12
−
14
View file @
f8d92e03
package
GraphClasses
;
import
Graph.*
;
import
Graph.*
;
public
class
Complete
{
public
Graph
graph
;
public
Complete
(
int
order
)
{
this
.
graph
=
new
Graph
(
order
);
for
(
int
i
=
0
;
i
<
order
;
i
++)
for
(
int
j
=
i
+
1
;
j
<
order
;
j
++)
graph
.
addEdge
(
new
Edge
(
i
,
j
,
0
));
}
public
Graph
graph
;
public
Complete
(
int
order
)
{
this
.
graph
=
new
Graph
(
order
);
for
(
int
i
=
0
;
i
<
order
;
i
++)
for
(
int
j
=
i
+
1
;
j
<
order
;
j
++)
graph
.
addEdge
(
new
Edge
(
i
,
j
,
0
));
}
}
This diff is collapsed.
Click to expand it.
src/GraphClasses/Grid.java
+
89
−
88
View file @
f8d92e03
package
GraphClasses
;
import
Graph.*
;
import
java.util.BitSet
;
...
...
@@ -6,93 +7,93 @@ import java.util.BitSet;
public
class
Grid
{
int
width
;
int
height
;
int
maxVertex
;
public
Graph
graph
;
public
int
abscissaOfVertex
(
int
vertex
)
{
return
vertex
%
width
;
}
public
int
ordinateOfVertex
(
int
vertex
)
{
return
vertex
/
width
;
}
private
int
vertexOfCoordinate
(
int
abscissa
,
int
ordinate
)
{
return
ordinate
*
width
+
abscissa
;
}
public
Grid
(
int
width
,
int
height
)
{
this
.
width
=
width
;
this
.
height
=
height
;
maxVertex
=
width
*
height
-
1
;
graph
=
new
Graph
(
maxVertex
);
for
(
int
i
=
0
;
i
<
width
;
i
++)
{
for
(
int
j
=
0
;
j
<
height
;
j
++)
{
if
(
i
<
width
-
1
)
graph
.
addEdge
(
new
Edge
(
vertexOfCoordinate
(
i
,
j
),
vertexOfCoordinate
(
i
+
1
,
j
),
0.0
));
if
(
j
<
height
-
1
)
graph
.
addEdge
(
new
Edge
(
vertexOfCoordinate
(
i
,
j
),
vertexOfCoordinate
(
i
,
j
+
1
),
0.0
));
}
}
}
public
boolean
isHorizontal
(
Edge
e
)
{
return
Math
.
abs
(
e
.
source
-
e
.
dest
)
==
1
;
}
public
boolean
isVertical
(
Edge
e
)
{
return
Math
.
abs
(
e
.
source
-
e
.
dest
)
==
width
;
}
private
void
drawLine
(
int
h
,
BitSet
right
)
{
for
(
int
i
=
0
;
i
<
width
-
1
;
i
++)
{
System
.
out
.
print
(
"o"
);
if
(
right
.
get
(
vertexOfCoordinate
(
i
,
h
)))
System
.
out
.
print
(
"--"
);
else
System
.
out
.
print
(
" "
);
}
System
.
out
.
println
(
"o"
);
}
private
void
drawInterline
(
int
h
,
BitSet
up
)
{
for
(
int
i
=
0
;
i
<
width
;
i
++)
{
if
(
up
.
get
(
vertexOfCoordinate
(
i
,
h
)))
System
.
out
.
print
(
"|"
);
else
System
.
out
.
print
(
" "
);
if
(
i
<
width
-
1
)
System
.
out
.
print
(
" "
);
}
System
.
out
.
println
();
}
public
void
drawSubgrid
(
Iterable
<
Edge
>
edges
)
{
BitSet
up
=
new
BitSet
(
maxVertex
);
BitSet
right
=
new
BitSet
(
maxVertex
);
for
(
Edge
e
:
edges
)
{
int
width
;
int
height
;
int
maxVertex
;
public
Graph
graph
;
public
int
abscissaOfVertex
(
int
vertex
)
{
return
vertex
%
width
;
}
public
int
ordinateOfVertex
(
int
vertex
)
{
return
vertex
/
width
;
}
private
int
vertexOfCoordinate
(
int
abscissa
,
int
ordinate
)
{
return
ordinate
*
width
+
abscissa
;
}
public
Grid
(
int
width
,
int
height
)
{
this
.
width
=
width
;
this
.
height
=
height
;
maxVertex
=
width
*
height
-
1
;
graph
=
new
Graph
(
maxVertex
+
1
);
for
(
int
i
=
0
;
i
<
width
;
i
++)
{
for
(
int
j
=
0
;
j
<
height
;
j
++)
{
if
(
i
<
width
-
1
)
graph
.
addEdge
(
new
Edge
(
vertexOfCoordinate
(
i
,
j
),
vertexOfCoordinate
(
i
+
1
,
j
),
0.0
));
if
(
j
<
height
-
1
)
graph
.
addEdge
(
new
Edge
(
vertexOfCoordinate
(
i
,
j
),
vertexOfCoordinate
(
i
,
j
+
1
),
0.0
));
}
}
}
public
boolean
isHorizontal
(
Edge
e
)
{
return
Math
.
abs
(
e
.
source
-
e
.
dest
)
==
1
;
}
public
boolean
isVertical
(
Edge
e
)
{
return
Math
.
abs
(
e
.
source
-
e
.
dest
)
==
width
;
}
private
void
drawLine
(
int
h
,
BitSet
right
)
{
for
(
int
i
=
0
;
i
<
width
-
1
;
i
++)
{
System
.
out
.
print
(
"o"
);
if
(
right
.
get
(
vertexOfCoordinate
(
i
,
h
)))
System
.
out
.
print
(
"--"
);
else
System
.
out
.
print
(
" "
);
}
System
.
out
.
println
(
"o"
);
}
private
void
drawInterline
(
int
h
,
BitSet
up
)
{
for
(
int
i
=
0
;
i
<
width
;
i
++)
{
if
(
up
.
get
(
vertexOfCoordinate
(
i
,
h
)))
System
.
out
.
print
(
"|"
);
else
System
.
out
.
print
(
" "
);
if
(
i
<
width
-
1
)
System
.
out
.
print
(
" "
);
}
System
.
out
.
println
();
}
public
void
drawSubgrid
(
Iterable
<
Edge
>
edges
)
{
BitSet
up
=
new
BitSet
(
maxVertex
);
BitSet
right
=
new
BitSet
(
maxVertex
);
for
(
Edge
e
:
edges
)
{
// System.out.println(e.fromVertex + " -- " + e.toVertex);
if
(
isHorizontal
(
e
))
right
.
set
(
Math
.
min
(
e
.
source
,
e
.
dest
));
if
(
isVertical
(
e
))
up
.
set
(
Math
.
min
(
e
.
source
,
e
.
dest
));
}
for
(
int
j
=
0
;
j
<
height
;
j
++)
{
drawLine
(
j
,
right
);
if
(
j
<
height
-
1
)
drawInterline
(
j
,
up
);
}
}
if
(
isHorizontal
(
e
))
right
.
set
(
Math
.
min
(
e
.
source
,
e
.
dest
));
if
(
isVertical
(
e
))
up
.
set
(
Math
.
min
(
e
.
source
,
e
.
dest
));
}
for
(
int
j
=
0
;
j
<
height
;
j
++)
{
drawLine
(
j
,
right
);
if
(
j
<
height
-
1
)
drawInterline
(
j
,
up
);
}
}
}
This diff is collapsed.
Click to expand it.
src/Main.java
+
5
−
4
View file @
f8d92e03
...
...
@@ -39,10 +39,10 @@ public class Main {
grid
=
new
Grid
(
1920
/
11
,
1080
/
11
);
Graph
graph
=
grid
.
graph
;
//
Graph graph = new Complete(400).graph;
//
Graph graph = new ErdosRenyi(1_000, 100).graph;
//
Graph graph = new Lollipop(1_000).graph;
return
grid
.
graph
;
//Graph graph = new Complete(400).graph;
//Graph graph = new ErdosRenyi(1_000, 100).graph;
//Graph graph = new Lollipop(1_000).graph;
return
graph
;
}
public
static
ArrayList
<
Edge
>
genTree
(
Graph
graph
)
{
...
...
@@ -54,6 +54,7 @@ public class Main {
// Non-random BFS
ArrayList
<
Arc
>
randomArcTree
=
BreadthFirstSearch
.
generateTree
(
graph
,
0
);
randomTree
=
new
ArrayList
<>();
for
(
Arc
a
:
randomArcTree
)
randomTree
.
add
(
a
.
support
);
return
randomTree
;
...
...
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