Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
Conversion
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Vladislav Kiselev
Conversion
Commits
ef1aa7f0
Commit
ef1aa7f0
authored
Feb 02, 2019
by
Vladislav Kiselev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавлено автоматическое тестирование и новые тесты.
parent
873682ad
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
509 additions
and
91 deletions
+509
-91
src/inport/ConversionUtil.java
src/inport/ConversionUtil.java
+80
-27
src/inport/Main.java
src/inport/Main.java
+17
-52
src/inport/MovingTemplate.java
src/inport/MovingTemplate.java
+1
-1
src/inport/ParserException.java
src/inport/ParserException.java
+1
-1
src/inport/TaskCase.java
src/inport/TaskCase.java
+11
-8
src/inport/Testing.java
src/inport/Testing.java
+120
-0
tests/without_typing/Case2.ipp
tests/without_typing/Case2.ipp
+82
-0
tests/without_typing/InitDataTopaj4.ipp
tests/without_typing/InitDataTopaj4.ipp
+48
-0
tests/without_typing/TaskBK.ipp
tests/without_typing/TaskBK.ipp
+43
-0
tests/without_typing/TaskT.ipp
tests/without_typing/TaskT.ipp
+63
-0
tests/without_typing/cargo_handling_and_moving.ipp
tests/without_typing/cargo_handling_and_moving.ipp
+2
-2
tests/without_typing/shortest_path_with_weather.ipp
tests/without_typing/shortest_path_with_weather.ipp
+0
-0
tests/without_typing/simple_cargo_flow.ipp
tests/without_typing/simple_cargo_flow.ipp
+0
-0
tests/without_typing/simple_shortest_path.ipp
tests/without_typing/simple_shortest_path.ipp
+0
-0
tests/without_typing/test_0.ipp
tests/without_typing/test_0.ipp
+41
-0
No files found.
src/inport/ConversionUtil.java
View file @
ef1aa7f0
This diff is collapsed.
Click to expand it.
src/inport/Main.java
View file @
ef1aa7f0
...
...
@@ -2,19 +2,10 @@ package inport;
import
java.io.*
;
public
class
Main
{
import
static
inport
.
Testing
.
solveTask_1
;
import
static
inport
.
Testing
.
test_1
;
private
static
void
removeDirectory
(
File
dir
)
{
if
(
dir
.
isDirectory
())
{
File
[]
files
=
dir
.
listFiles
();
if
(
files
!=
null
&&
files
.
length
>
0
)
{
for
(
File
aFile
:
files
)
{
removeDirectory
(
aFile
);
}
}
}
dir
.
delete
();
}
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
if
(
args
.
length
==
0
)
{
...
...
@@ -26,55 +17,26 @@ public class Main {
switch
(
type
)
{
case
"solve"
:
{
String
fileName
=
args
[
1
];
File
directory
=
new
File
(
"temp_data"
);
if
(!
directory
.
exists
())
{
directory
.
mkdir
();
}
String
tempDir
=
"temp_data/"
;
String
minizincData
=
tempDir
+
"minizinc_data.dzn"
;
String
solverResults
=
tempDir
+
"solver_results.txt"
;
String
constraints
=
tempDir
+
"constraints.mzn"
;
long
start
=
System
.
currentTimeMillis
();
TaskCase
task
=
new
TaskCase
();
try
{
try
(
FileWriter
res
=
new
FileWriter
(
constraints
))
{
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
Main
.
class
.
getResourceAsStream
(
"/constraints/conversion_1.mzn"
)));
String
line
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
res
.
write
(
line
+
"\n"
);
}
}
task
.
deserialize
(
fileName
);
ConversionUtil
.
portToMiniZinc_1
(
task
,
minizincData
);
long
start
=
System
.
currentTimeMillis
();
ProcessBuilder
pb
=
new
ProcessBuilder
(
"minizinc"
,
"--solver"
,
"Chuffed"
,
constraints
,
minizincData
,
"-o"
,
solverResults
);
Process
process
=
pb
.
start
();
int
exitCode
=
process
.
waitFor
();
assert
exitCode
==
0
;
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
break
;
}
long
finish
=
System
.
currentTimeMillis
(
);
String
error
=
solveTask_1
(
task
);
System
.
out
.
println
((
finish
-
start
)
+
" milliseconds"
);
long
finish
=
System
.
currentTimeMillis
();
System
.
out
.
println
((
finish
-
start
)
+
" milliseconds"
);
ConversionUtil
.
resolveMiniZincResults
(
task
,
solverResults
);
if
(!
error
.
isEmpty
())
{
System
.
out
.
println
(
"Error : "
+
error
);
}
else
{
task
.
serialize
(
fileName
);
}
catch
(
IOException
|
InterruptedException
ex
)
{
System
.
out
.
println
(
ex
.
getMessage
());
}
catch
(
ParserException
ex
)
{
if
(
ex
.
getMessage
().
equals
(
"No solution."
))
{
System
.
out
.
println
(
ex
.
getMessage
());
}
else
{
System
.
out
.
println
(
"ParserException : "
+
ex
.
getMessage
());
}
}
removeDirectory
(
directory
);
break
;
}
case
"to_MiniZinc_0"
:
{
...
...
@@ -131,6 +93,9 @@ public class Main {
}
break
;
}
case
"testing"
:
test_1
();
break
;
default
:
System
.
out
.
println
(
"Unknown type \""
+
type
+
"\""
);
}
...
...
src/inport/MovingTemplate.java
View file @
ef1aa7f0
...
...
@@ -13,7 +13,7 @@ import java.util.OptionalInt;
public
class
MovingTemplate
extends
TowUsingTemplate
{
private
MovingObject
mover
;
private
OptionalInt
moverType
;
private
OptionalInt
moverType
=
OptionalInt
.
empty
()
;
private
Berth
destination
;
...
...
src/inport/ParserException.java
View file @
ef1aa7f0
package
inport
;
public
class
ParserException
extends
Exception
{
public
class
ParserException
extends
Runtime
Exception
{
ParserException
(
String
mess
)
{
super
(
mess
);
}
...
...
src/inport/TaskCase.java
View file @
ef1aa7f0
...
...
@@ -626,31 +626,34 @@ public class TaskCase {
templates
.
add
(
mt
);
m_template
.
put
(
mt
.
getId
(),
mt
);
}
break
;
}
break
;
case
Time_Windows:
break
;
case
Cargo_Flows:
cargoFlows
.
add
(
new
CargoFlow
(
strLine
,
m_storage
,
m_cargo
));
break
;
case
Initial_Vessel_State:
vesselInitialState
.
add
(
fromString
(
strLine
,
m_berth
,
m_vessel
));
break
;
break
;
case
Initial_Storage_State:
storageInitialState
.
add
(
new
StorageState
(
strLine
,
m_storage
,
m_vessel
,
m_cargo
));
break
;
case
Final_Vessel_State:
vesselEndState
.
add
(
fromString
(
strLine
,
m_berth
,
m_vessel
));
break
;
break
;
case
Final_Storage_State:
storageEndState
.
add
(
new
StorageState
(
strLine
,
m_storage
,
m_vessel
,
m_cargo
));
break
;
break
;
case
Task_Properties:
{
String
[]
rs
=
strLine
.
split
(
";"
);
planningInterval
=
Double
.
parseDouble
(
rs
[
0
].
trim
());
criterionType
=
Integer
.
parseInt
(
rs
[
1
].
trim
());
}
break
;
break
;
case
Solution:
// Тут чтение операций если надо. Потом подумаем
break
;
if
(
numInside
==
1
)
{
solution_result
=
Double
.
parseDouble
(
strLine
.
trim
());
}
break
;
default
:
break
;
break
;
}
}
//Close the input stream
...
...
src/inport/Testing.java
0 → 100644
View file @
ef1aa7f0
package
inport
;
import
java.io.*
;
import
java.util.ArrayList
;
import
java.util.function.BiConsumer
;
import
java.util.stream.Collectors
;
public
class
Testing
{
private
static
void
removeDirectory
(
File
dir
)
{
if
(
dir
.
isDirectory
())
{
File
[]
files
=
dir
.
listFiles
();
if
(
files
!=
null
&&
files
.
length
>
0
)
{
for
(
File
aFile
:
files
)
{
removeDirectory
(
aFile
);
}
}
}
dir
.
delete
();
}
public
static
String
solveTask_1
(
TaskCase
task
)
{
return
solveTask
(
task
,
"conversion_1.mzn"
,
ConversionUtil:
:
portToMiniZinc_1
,
ConversionUtil:
:
resolveMiniZincResults
);
}
/* Возвращает описание ошибки, если ошибки не было, то пустую строку. */
public
static
String
solveTask
(
TaskCase
task
,
String
constraintName
,
BiConsumer
<
TaskCase
,
String
>
converterToMinizincFormat
,
BiConsumer
<
TaskCase
,
String
>
interpreter
)
{
File
directory
=
new
File
(
"temp_data"
);
if
(!
directory
.
exists
())
{
directory
.
mkdir
();
}
String
tempDir
=
"temp_data/"
;
String
minizincData
=
tempDir
+
"minizinc_data.dzn"
;
String
solverResults
=
tempDir
+
"solver_results.txt"
;
String
constraints
=
tempDir
+
"constraints.mzn"
;
try
{
try
(
FileWriter
res
=
new
FileWriter
(
constraints
))
{
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
Main
.
class
.
getResourceAsStream
(
"/constraints/"
+
constraintName
)));
String
line
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
res
.
write
(
line
+
"\n"
);
}
}
converterToMinizincFormat
.
accept
(
task
,
minizincData
);
ProcessBuilder
pb
=
new
ProcessBuilder
(
"minizinc"
,
"--solver"
,
"Chuffed"
,
constraints
,
minizincData
,
"-o"
,
solverResults
);
Process
process
=
pb
.
start
();
int
exitCode
=
process
.
waitFor
();
assert
exitCode
==
0
;
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
String
output
=
br
.
lines
().
collect
(
Collectors
.
joining
(
"\n"
));
if
(
output
.
trim
().
equals
(
"=====UNSATISFIABLE====="
))
{
task
.
setSolution
(
new
ArrayList
<>());
task
.
setSolution_result
(-
1
);
}
else
{
interpreter
.
accept
(
task
,
solverResults
);
}
}
catch
(
UncheckedIOException
|
IOException
|
InterruptedException
|
ParserException
ex
)
{
return
ex
.
getMessage
();
}
finally
{
removeDirectory
(
directory
);
}
return
""
;
}
public
static
String
testCase
(
String
file
)
{
TaskCase
task
=
new
TaskCase
();
try
{
task
.
deserialize
(
file
);
}
catch
(
IOException
e
)
{
return
"Error : "
+
e
.
getMessage
();
}
double
expected_result
=
task
.
getSolution_result
();
String
error
=
solveTask_1
(
task
);
double
result
=
task
.
getSolution_result
();
if
(!
error
.
isEmpty
())
{
return
"Error : "
+
error
;
}
if
(
expected_result
!=
result
)
{
return
"WA : expected "
+
expected_result
+
", found "
+
result
;
}
return
"OK"
;
}
public
static
void
test_1
()
{
File
testDir
=
new
File
(
"tests/without_typing/"
);
System
.
out
.
println
(
testDir
.
toString
()
+
" :"
);
int
nPassedTests
=
0
;
for
(
File
file
:
testDir
.
listFiles
())
{
System
.
out
.
println
(
" "
+
file
.
getName
()
+
" : "
);
long
start
=
System
.
currentTimeMillis
();
String
res
=
testCase
(
testDir
.
toString
()
+
"/"
+
file
.
getName
());
long
finish
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
" "
+
res
+
", "
+
(
finish
-
start
)
+
" ms"
);
if
(
res
.
equals
(
"OK"
))
{
nPassedTests
++;
}
}
System
.
out
.
println
(
"Passed tests : "
+
nPassedTests
+
"/"
+
testDir
.
listFiles
().
length
);
}
}
tests/without_typing/Case2.ipp
0 → 100644
View file @
ef1aa7f0
Cargoes
83;Груз1;0.0
84;Груз2;0.0
85;Груз3;0.0
Berths
86;Рейд
87;Терминал1
88;Терминал2
Storages
89;Хранилище1;83;1000.0
90;Хранилище2;84;1000.0
91;Хранилище3;85;1000.0
Bunkers
Tows
94;Буксир1;1000000
95;Буксир2;1000000
Loading Equipments
99;Плавучий кран 1
100;Плавучий кран 2
101;Плавучий кран 3
Transport Ships
96;Судно1;1000000.0
Templates
10;mrn;[];96;88;[94,95];1.0
13;mov;[];94;86;88;[];1.0
16;mov;[];94;87;88;[];3.0
15;mov;[];94;87;86;[];1.0
11;mov;[];94;88;86;[];1.0
12;mov;[];95;88;86;[];1.0
17;mov;[];95;87;88;[];3.0
14;mov;[];95;86;88;[];1.0
8;mov;[];96;86;88;[94];2.0
9;mov;[];96;86;88;[95];2.0
2;loa;[];96;83;89;88;[99,100];20.0;U
4;loa;[];96;84;90;88;[99,101];10.0;U
5;loa;[];96;84;90;88;[100,101];10.0;U
7;loa;[];96;85;91;88;[101];10.0;U
Cargo Flows
Initial Vessel State
96;86
99;88
100;88
101;88
94;87
95;88
Initial Storage State
83;89;0.0
84;90;0.0
85;91;0.0
83;96;60.0
84;96;60.0
85;96;60.0
Final Vessel State
Final Storage State
83;96;0.0
84;96;0.0
85;96;0.0
Task Properties
20.0;0
Solution
15.0
15; R; 0.0; 1.0
8; R; 1.0; 2.0
12; R; 2.0; 1.0
14; R; 3.0; 1.0
2; R; 3.0; 2.0
7; R; 3.0; 5.0
4; R; 8.0; 1.0
12; R; 9.0; 1.0
2; R; 9.0; 1.0
7; R; 9.0; 1.0
11; R; 10.0; 1.0
4; R; 10.0; 1.0
13; R; 11.0; 1.0
5; R; 11.0; 1.0
14; R; 12.0; 1.0
4; R; 12.0; 3.0
11; R; 14.0; 1.0
tests/without_typing/InitDataTopaj4.ipp
0 → 100644
View file @
ef1aa7f0
Cargoes
10; Груз1
Berths
6; Рейд
7; Терминал1
8; Терминал2
Storages
9; Хранилище1; 10; 5000
Transport Ships
12; Судно1; 1000
13; Судно2; 1000
Loading Equipments
Templates
4367; mov; []; 12; 6; 7; []; 1
4374; mov; []; 13; 8; 7; []; 1
4369; mov; []; 12; 6; 8; []; 1
4372; mov; []; 13; 7; 8; []; 1
4370; mov; []; 13; 6; 8; []; 1
4371; mov; []; 12; 7; 8; []; 1
4368; mov; []; 13; 6; 7; []; 1
4373; mov; []; 12; 8; 7; []; 1
4360; loa; []; 9; 10; 12; 7; []; 100; U
4364; loa; []; 9; 10; 13; 7; []; 100; U
4362; loa; []; 9; 10; 12; 8; []; 50; U
4366; loa; []; 9; 10; 13; 8; []; 50; U
Initial Vessel State
12; 6
13; 6
Final Vessel State
Initial Storage State
10; 12; 0
10; 13; 0
10; 9; 5000
Final Storage State
10; 12; 1000
10; 13; 1000
Task Properties
50; 0
Solution
15.0
4367; R; 0.0; 1.0
4370; R; 0.0; 1.0
4360; R; 1.0; 7.0
4366; R; 1.0; 6.0
4374; R; 7.0; 1.0
4371; R; 8.0; 1.0
4364; R; 8.0; 7.0
4362; R; 9.0; 6.0
tests/without_typing/TaskBK.ipp
0 → 100644
View file @
ef1aa7f0
Cargoes
0;LNG;1.0
Berths
1;Raid
2;Pier 1
3;Pier 2
Storages
4;Storage 1;0;270.0
Bunkers
Tows
6;Tow 1
Loading Equipments
5;Плавучий кран
Transport Ships
7;Ship 1;2000.0
Templates
8;mov;[];7;1;2;[6];2.0
9;mov;[];7;2;1;[6];2.0
10;mov;[];6;3;1;[];2.0
11;mov;[];6;2;1;[];2.0
12;mov;[];6;2;3;[];1.0
13;mov;[];5;3;2;[6];2.0
14;loa;[];7;0;4;2;[5];20.0; U
Cargo Flows
Initial Vessel State
7;1
6;2
5;3
Initial Storage State
0;4;0.0
0;7;100.0
Final Vessel State
7;1
Final Storage State
0;7;0.0
Task Properties
18.0;0
Solution
14.0
tests/without_typing/TaskT.ipp
0 → 100644
View file @
ef1aa7f0
Cargoes
0;LNG;0.0
Berths
1;Raid
2;Pier 1
3;Pier 2
Storages
4;Storage 1;0;10000.0
Bunkers
Tows
Loading Equipments
Transport Ships
5;Ship 1;2000.0
6;Ship 2;2000.0
Templates
7;mov;[];5;1;2;[];1.0
8;mov;[];5;2;1;[];1.0
9;mov;[];5;1;3;[];1.0
10;mov;[];5;3;1;[];1.0
11;mov;[];5;2;3;[];1.0
12;mov;[];5;3;2;[];1.0
13;mov;[];6;1;2;[];1.0
14;mov;[];6;2;1;[];1.0
15;mov;[];6;1;3;[];1.0
16;mov;[];6;3;1;[];1.0
17;mov;[];6;2;3;[];1.0
18;mov;[];6;3;2;[];1.0
19;loa;[];4;0;5;2;[];100.0; U
20;loa;[];4;0;5;3;[];50.0; U
21;loa;[];4;0;6;2;[];100.0; U
22;loa;[];4;0;6;3;[];50.0; U
Cargo Flows
Initial Vessel State
5;1
6;1
Initial Storage State
0;5;0.0
0;6;0.0
0;4;10000.0
Final Vessel State
5;1
6;1
Final Storage State
0;5;1000.0
0;6;1000.0
Task Properties
24.0;0
Solution
16.0
7; R; 1.0; 1.0
10; R; 16.0; 1.0
11; R; 9.0; 1.0
14; R; 16.0; 1.0
15; R; 1.0; 1.0
18; R; 8.0; 1.0
19; R; 2.0; 7.0
20; R; 10.0; 6.0
21; R; 9.0; 7.0
22; R; 2.0; 6.0
tests/cargo_handling_and_moving.ipp
→
tests/
without_typing/
cargo_handling_and_moving.ipp
View file @
ef1aa7f0
...
...
@@ -45,7 +45,7 @@ Final Storage State
0; 11; 2.0
Task Properties
15
.0;0
20
.0;0
Solution
1
2
.0
1
5
.0
tests/shortest_path_with_weather.ipp
→
tests/
without_typing/
shortest_path_with_weather.ipp
View file @
ef1aa7f0
File moved
tests/simple_cargo_flow.ipp
→
tests/
without_typing/
simple_cargo_flow.ipp
View file @
ef1aa7f0
File moved
tests/simple_shortest_path.ipp
→
tests/
without_typing/
simple_shortest_path.ipp
View file @
ef1aa7f0
File moved
tests/without_typing/test_0.ipp
0 → 100644
View file @
ef1aa7f0
Cargoes
83; Груз1
Berths
86; Рейд
88; Терминал2
Storages
89; Хранилище1; 83; 1000.0
Bunkers
Tows
Loading Equipments
Transport Ships
96; Судно1; 1000000.0
Templates
10;mrn;[]; 96; 88; []; 1.0
8;mov;[]; 96; 86; 88; []; 2.0
2;loa;[]; 96; 83; 89; 88; []; 20.0; M
Cargo Flows
Initial Vessel State
96; 86
Initial Storage State
83; 89; 0.0
83; 96; 60.0
Final Vessel State
Final Storage State
83; 89; 60.0
Task Properties
20.0;0
Solution
6.0
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment