Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
B4M33PAL
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
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
Filip Štěpánek
B4M33PAL
Commits
bef56ef0
Commit
bef56ef0
authored
3 years ago
by
Filip Štěpánek
Browse files
Options
Downloads
Patches
Plain Diff
Mess
parent
d0cd60a1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
01UtilPipes/.idea/workspace.xml
+2
-28
2 additions, 28 deletions
01UtilPipes/.idea/workspace.xml
01UtilPipes/src/pal/Main.java
+1
-1
1 addition, 1 deletion
01UtilPipes/src/pal/Main.java
01UtilPipes/src/pal/Stepanek.java
+76
-24
76 additions, 24 deletions
01UtilPipes/src/pal/Stepanek.java
with
79 additions
and
53 deletions
01UtilPipes/.idea/workspace.xml
+
2
−
28
View file @
bef56ef0
...
...
@@ -2,28 +2,7 @@
<project
version=
"4"
>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"06de111b-d59a-449a-a632-7194b2043141"
name=
"Changes"
comment=
""
>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub01.in"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub01.out"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub02.in"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub02.out"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub03.in"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub03.out"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub04.in"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub04.out"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub05.in"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub05.out"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub06.in"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub06.out"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub07.in"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub07.out"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub08.in"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub08.out"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub09.in"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub09.out"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub10.in"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/datapub/pub10.out"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/src/pal.zip"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/src/pal.zip"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/src/pal/Main.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/src/pal/Main.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/src/pal/Stepanek.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/src/pal/Stepanek.java"
afterDir=
"false"
/>
</list>
...
...
@@ -137,11 +116,6 @@
<line>
46
</line>
<option
name=
"timeStamp"
value=
"3"
/>
</line-breakpoint>
<line-breakpoint
enabled=
"true"
type=
"java-line"
>
<url>
file://$PROJECT_DIR$/src/pal/Main.java
</url>
<line>
67
</line>
<option
name=
"timeStamp"
value=
"5"
/>
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
<pin-to-top-manager>
...
...
@@ -151,11 +125,11 @@
</pin-to-top-manager>
<watches-manager>
<configuration
name=
"Application"
>
<watch
expression=
"p
rims[0]
"
/>
<watch
expression=
"p
arent
"
/>
</configuration>
</watches-manager>
</component>
<component
name=
"com.intellij.coverage.CoverageDataManagerImpl"
>
<SUITE
FILE_PATH=
"coverage/01UtilPipes$Main.ic"
NAME=
"Main Coverage Results"
MODIFIED=
"1633
262741122
"
SOURCE_PROVIDER=
"com.intellij.coverage.DefaultCoverageFileProvider"
RUNNER=
"idea"
COVERAGE_BY_TEST_ENABLED=
"false"
COVERAGE_TRACING_ENABLED=
"false"
/>
<SUITE
FILE_PATH=
"coverage/01UtilPipes$Main.ic"
NAME=
"Main Coverage Results"
MODIFIED=
"1633
361914477
"
SOURCE_PROVIDER=
"com.intellij.coverage.DefaultCoverageFileProvider"
RUNNER=
"idea"
COVERAGE_BY_TEST_ENABLED=
"false"
COVERAGE_TRACING_ENABLED=
"false"
/>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
01UtilPipes/src/pal/Main.java
+
1
−
1
View file @
bef56ef0
...
...
@@ -11,7 +11,7 @@ public class Main {
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
,
ExecutionException
{
//InputStreamReader in = new InputStreamReader(System.in);
InputStreamReader
in
=
new
InputStreamReader
(
new
FileInputStream
(
"D:\\dev\\VS\\OI\\1\\B4M33PAL\\01UtilPipes\\datapub\\pub0
1
.in"
));
InputStreamReader
in
=
new
InputStreamReader
(
new
FileInputStream
(
"D:\\dev\\VS\\OI\\1\\B4M33PAL\\01UtilPipes\\datapub\\pub0
3
.in"
));
BufferedReader
input
=
new
BufferedReader
(
in
);
...
...
This diff is collapsed.
Click to expand it.
01UtilPipes/src/pal/Stepanek.java
+
76
−
24
View file @
bef56ef0
...
...
@@ -4,13 +4,13 @@ import java.util.*;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
public
class
Stepanek
{
public
int
[]
hubFarms
;
public
ArrayList
<
ArrayList
<
AdjacencyNode
>>
adj
;
public
Road
[]
roads
;
int
farmsCount
,
roadsCount
;
List
<
Integer
>
undecideds
;
Stepanek
(
int
farmsCount
,
int
roadsCount
)
{
this
.
farmsCount
=
farmsCount
;
...
...
@@ -22,10 +22,10 @@ public class Stepanek {
int
[][]
djikstras
=
new
int
[
hubFarms
.
length
][
farmsCount
];
for
(
int
i
=
0
;
i
<
hubFarms
.
length
;
i
++)
{
djikstras
[
i
]
=
Dijkstra
(
hubFarms
[
i
],
null
);
djikstras
[
i
]
=
Dijkstra
(
hubFarms
[
i
],
adj
);
}
List
<
Integer
>
undecided
=
new
ArrayList
<>();
undecided
s
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
farmsCount
;
i
++)
{
int
[]
arr
=
new
int
[
hubFarms
.
length
];
for
(
int
j
=
0
;
j
<
hubFarms
.
length
;
j
++)
{
...
...
@@ -34,14 +34,21 @@ public class Stepanek {
Arrays
.
sort
(
arr
);
if
(
arr
[
0
]
==
arr
[
1
])
undecided
.
add
(
i
);
undecided
s
.
add
(
i
);
}
Fuckerino
[]
prims
=
new
Fuckerino
[
hubFarms
.
length
];
for
(
int
i
=
0
;
i
<
hubFarms
.
length
;
i
++)
{
djikstras
[
i
]
=
Dijkstra
(
hubFarms
[
i
],
undecideds
);
}
System
.
out
.
printf
(
"%d %d"
,
sum
,
undecideds
.
size
());
/*Fuckerino[] prims = new Fuckerino[hubFarms.length];
for (int i = 0; i < hubFarms.length; i++) {
prims[i] = new Fuckerino();
prims
[
i
]
=
Prim
(
hubFarms
[
i
],
undecided
);
prims[i] = Prim(hubFarms[i], undecided
s
);
//prims[i].price = Dijkstra(hubFarms[i],undecided);
prims[i].price = djikstras[i];
}
...
...
@@ -52,7 +59,7 @@ public class Stepanek {
int[] usedParent = new int[farmsCount];
for (Fuckerino fucky : prims) {
for (int i = 0; i < farmsCount; i++) {
if
(
undecided
.
contains
(
i
))
if (undecided
s
.contains(i))
continue;
else if (min[i] > fucky.price[i]) {
min[i] = fucky.price[i];
...
...
@@ -66,13 +73,13 @@ public class Stepanek {
int tubes = 0;
for (int i = 0; i < farmsCount; i++) {
tubes += tube[i];
/*
System.out.printf("%d-%d route for %d %n", usedParent[i],i, tube[i]);
*/
System.out.printf("%d-%d route for %d %n", usedParent[i],i, tube[i]);
}
System
.
out
.
printf
(
"%d %d"
,
tubes
,
undecided
.
size
());
System.out.printf("%d %d", tubes, undecided
s
.size());
long end = System.currentTimeMillis();
long elapsedTime = end - start;
System
.
out
.
printf
(
"%n Elapsed time %d ms"
,
elapsedTime
);
System.out.printf("%n Elapsed time %d ms", elapsedTime);
*/
}
public
CompletableFuture
<
int
[]>
djikstraAsync
(
int
src
,
List
<
Integer
>
undecided
)
throws
InterruptedException
{
...
...
@@ -87,7 +94,7 @@ public class Stepanek {
return
completableFuture
;
}
public
CompletableFuture
<
Fuckerino
>
primAsync
(
int
src
,
List
<
Integer
>
undecided
)
throws
InterruptedException
{
/*
public CompletableFuture<Fuckerino> primAsync(int src, List<Integer> undecided) throws InterruptedException {
CompletableFuture<Fuckerino> completableFuture = new CompletableFuture<>();
Executors.newCachedThreadPool().submit(() -> {
...
...
@@ -97,9 +104,9 @@ public class Stepanek {
});
return completableFuture;
}
}
*/
int
[]
Dijkstra
(
int
src
,
List
<
Integer
>
undecided
)
{
int
[]
Dijkstra
(
int
src
)
{
PriorityQueue
<
Pair
>
pq
=
new
PriorityQueue
<
Pair
>(
new
Comparator
<
Pair
>()
{
@Override
public
int
compare
(
Pair
o1
,
Pair
o2
)
{
...
...
@@ -117,9 +124,6 @@ public class Stepanek {
int
u
=
pq
.
poll
().
item2
;
for
(
AdjacencyNode
node
:
adj
.
get
(
u
))
{
if
(
undecided
!=
null
&&
undecided
.
contains
(
node
.
label
))
continue
;
int
v
=
node
.
label
;
int
weight
=
node
.
cost
;
...
...
@@ -130,11 +134,10 @@ public class Stepanek {
}
}
return
dist
;
}
Fuckerino
Prim
(
int
src
,
List
<
Integer
>
undecided
)
{
List
<
List
<
AdjacencyNode
>>
Prim
(
int
src
,
List
<
Integer
>
undecided
)
{
PriorityQueue
<
Pair
>
pq
=
new
PriorityQueue
<
Pair
>(
new
Comparator
<
Pair
>()
{
@Override
public
int
compare
(
Pair
o1
,
Pair
o2
)
{
...
...
@@ -142,6 +145,7 @@ public class Stepanek {
}
});
int
[]
key
=
new
int
[
farmsCount
];
Arrays
.
fill
(
key
,
Integer
.
MAX_VALUE
);
...
...
@@ -182,12 +186,65 @@ public class Stepanek {
}
}
List
<
List
<
AdjacencyNode
>>
newAdj
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
farmsCount
;
i
++)
newAdj
.
add
(
new
ArrayList
<
AdjacencyNode
>());
for
(
int
i
=
0
;
i
<
farmsCount
;
i
++)
{
int
u
=
i
;
int
v
=
parent
[
i
];
int
w
=
key
[
i
];
if
(
v
<
0
)
continue
;
newAdj
.
get
(
u
).
add
(
new
AdjacencyNode
(
v
,
w
));
newAdj
.
get
(
v
).
add
(
new
AdjacencyNode
(
u
,
w
));
}
Fuckerino
x
=
new
Fuckerino
();
x
.
tube
=
key
;
x
.
parent
=
parent
;
return
x
;
return
newAdj
;
}
/*int Svagruj(List<List<AdjacencyNode>> newAdj) {
int[] nodePrices = new int[farmsCount];
int[] pathParent = new int[farmsCount];
int[] tubePrice = new int[farmsCount];
LinkedList<Integer> toVisit = new LinkedList<>();
Arrays.fill(nodePrices, Integer.MAX_VALUE);
Arrays.fill(pathParent, -1);
Arrays.fill(tubePrice, 0);
for (int hubFarm : hubFarms) {
nodePrices[hubFarm] = 0;
toVisit.add(hubFarm);
}
while (!toVisit.isEmpty()) {
int node = toVisit.removeFirst();
List<AdjacencyNode> neighbors = newAdj.get(node);
for (AdjacencyNode neighbor : neighbors) {
if (nodePrices[neighbor.label] > neighbor.cost + nodePrices[node]) {
nodePrices[neighbor.label] = neighbor.cost + nodePrices[node];
toVisit.add(neighbor.label);
pathParent[neighbor.label] = node;
tubePrice[neighbor.label] = neighbor.cost;
}
}
}
int sum = 0;
for (int tub : tubePrice)
sum += tub;
return sum;
}*/
}
class
Fuckerino
{
...
...
@@ -197,9 +254,4 @@ class Fuckerino {
public
Fuckerino
()
{
}
public
Fuckerino
(
int
[]
tube
,
int
[]
price
)
{
this
.
tube
=
tube
;
this
.
price
=
price
;
}
}
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