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
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
...
@@ -275,7 +275,9 @@ public class ConversionUtil {
...
@@ -275,7 +275,9 @@ public class ConversionUtil {
private
final
ArrayList
<
Berth
>
berths
;
private
final
ArrayList
<
Berth
>
berths
;
private
final
Map
<
Pair
<
Integer
,
Boolean
>,
Integer
>
locationNumberById
;
private
final
Map
<
Pair
<
Integer
,
Boolean
>,
Integer
>
locationNumberById
;
private
final
BiFunction
<
Integer
,
Boolean
,
Integer
>
getLocNById
;
private
int
getLocNById
(
int
id
,
boolean
isMoored
)
{
return
locationNumberById
.
get
(
new
Pair
<>(
id
,
isMoored
));
}
private
final
ArrayList
<
MovingObject
>
movingObjects
;
private
final
ArrayList
<
MovingObject
>
movingObjects
;
private
final
Function
<
MovingObject
,
Integer
>
mObjToN
;
private
final
Function
<
MovingObject
,
Integer
>
mObjToN
;
...
@@ -303,8 +305,6 @@ public class ConversionUtil {
...
@@ -303,8 +305,6 @@ public class ConversionUtil {
locationNumberById
.
put
(
new
Pair
<>(
berth
.
getId
(),
true
),
locationNumberById
.
size
());
locationNumberById
.
put
(
new
Pair
<>(
berth
.
getId
(),
true
),
locationNumberById
.
size
());
}
}
getLocNById
=
(
Integer
id
,
Boolean
isMoored
)
->
locationNumberById
.
get
(
new
Pair
<>(
id
,
isMoored
));
movingObjects
=
new
ArrayList
<>();
movingObjects
=
new
ArrayList
<>();
Map
<
Integer
,
Integer
>
mObjNumberById
=
new
TreeMap
<>();
Map
<
Integer
,
Integer
>
mObjNumberById
=
new
TreeMap
<>();
for
(
MovingObject
obj
:
task
.
getShips
())
{
for
(
MovingObject
obj
:
task
.
getShips
())
{
...
@@ -363,8 +363,8 @@ public class ConversionUtil {
...
@@ -363,8 +363,8 @@ public class ConversionUtil {
movingObjN
.
add
(
mObjToN
.
apply
(
op
.
getMover
()));
movingObjN
.
add
(
mObjToN
.
apply
(
op
.
getMover
()));
for
(
Integer
n
:
movingObjN
)
{
for
(
Integer
n
:
movingObjN
)
{
arrivalOp
.
get
(
n
).
get
(
getLocNById
.
apply
(
op
.
getDestination
().
getId
(),
false
)).
add
(
i
+
1
);
arrivalOp
.
get
(
n
).
get
(
getLocNById
(
op
.
getDestination
().
getId
(),
false
)).
add
(
i
+
1
);
departureOp
.
get
(
n
).
get
(
getLocNById
.
apply
(
op
.
getStartLocation
().
getId
(),
false
)).
add
(
i
+
1
);
departureOp
.
get
(
n
).
get
(
getLocNById
(
op
.
getStartLocation
().
getId
(),
false
)).
add
(
i
+
1
);
}
}
}
else
if
(
operationTemplates
.
get
(
i
)
instanceof
MooringTemplate
)
{
}
else
if
(
operationTemplates
.
get
(
i
)
instanceof
MooringTemplate
)
{
MooringTemplate
op
=
(
MooringTemplate
)
operationTemplates
.
get
(
i
);
MooringTemplate
op
=
(
MooringTemplate
)
operationTemplates
.
get
(
i
);
...
@@ -376,8 +376,8 @@ public class ConversionUtil {
...
@@ -376,8 +376,8 @@ public class ConversionUtil {
movingObjN
.
add
(
mObjToN
.
apply
(
op
.
getMoorer
()));
movingObjN
.
add
(
mObjToN
.
apply
(
op
.
getMoorer
()));
for
(
Integer
n
:
movingObjN
)
{
for
(
Integer
n
:
movingObjN
)
{
arrivalOp
.
get
(
n
).
get
(
getLocNById
.
apply
(
op
.
getStartLocation
().
getId
(),
op
.
isDirect
())).
add
(
i
+
1
);
arrivalOp
.
get
(
n
).
get
(
getLocNById
(
op
.
getStartLocation
().
getId
(),
op
.
isDirect
())).
add
(
i
+
1
);
departureOp
.
get
(
n
).
get
(
getLocNById
.
apply
(
op
.
getStartLocation
().
getId
(),
!
op
.
isDirect
())).
add
(
i
+
1
);
departureOp
.
get
(
n
).
get
(
getLocNById
(
op
.
getStartLocation
().
getId
(),
!
op
.
isDirect
())).
add
(
i
+
1
);
}
}
}
}
}
}
...
@@ -390,7 +390,7 @@ public class ConversionUtil {
...
@@ -390,7 +390,7 @@ public class ConversionUtil {
private
void
initialLocations
()
throws
IOException
{
private
void
initialLocations
()
throws
IOException
{
ArrayList
<
Integer
>
initialStates
=
integerArray
(
movingObjects
.
size
(),
0
);
ArrayList
<
Integer
>
initialStates
=
integerArray
(
movingObjects
.
size
(),
0
);
for
(
MovingObjectState
state
:
task
.
getVesselInitialState
())
{
for
(
MovingObjectState
state
:
task
.
getVesselInitialState
())
{
initialStates
.
set
(
mObjToN
.
apply
(
state
.
getVessel
()),
getLocNById
.
apply
(
state
.
getLocation
().
getId
(),
false
));
initialStates
.
set
(
mObjToN
.
apply
(
state
.
getVessel
()),
getLocNById
(
state
.
getLocation
().
getId
(),
false
));
}
}
writeArray
(
writer
,
"initial_m_obj_loc"
,
initialStates
,
(
Integer
p
)
->
p
+
1
);
writeArray
(
writer
,
"initial_m_obj_loc"
,
initialStates
,
(
Integer
p
)
->
p
+
1
);
writer
.
write
(
"\n"
);
writer
.
write
(
"\n"
);
...
@@ -446,7 +446,7 @@ public class ConversionUtil {
...
@@ -446,7 +446,7 @@ public class ConversionUtil {
private
void
finalLocations
()
throws
IOException
{
private
void
finalLocations
()
throws
IOException
{
ArrayList
<
Integer
>
finalStates
=
integerArray
(
movingObjects
.
size
(),
-
1
);
ArrayList
<
Integer
>
finalStates
=
integerArray
(
movingObjects
.
size
(),
-
1
);
for
(
MovingObjectState
state
:
task
.
getVesselEndState
())
{
for
(
MovingObjectState
state
:
task
.
getVesselEndState
())
{
finalStates
.
set
(
mObjToN
.
apply
(
state
.
getVessel
()),
getLocNById
.
apply
(
state
.
getLocation
().
getId
(),
false
));
finalStates
.
set
(
mObjToN
.
apply
(
state
.
getVessel
()),
getLocNById
(
state
.
getLocation
().
getId
(),
false
));
}
}
writeArray
(
writer
,
"final_m_obj_loc"
,
finalStates
,
(
Integer
p
)
->
p
+
1
);
writeArray
(
writer
,
"final_m_obj_loc"
,
finalStates
,
(
Integer
p
)
->
p
+
1
);
}
}
...
@@ -467,21 +467,21 @@ public class ConversionUtil {
...
@@ -467,21 +467,21 @@ public class ConversionUtil {
if
(
operationTemplate
instanceof
MovingTemplate
)
{
// Перемещение.
if
(
operationTemplate
instanceof
MovingTemplate
)
{
// Перемещение.
MovingTemplate
op
=
(
MovingTemplate
)
operationTemplate
;
MovingTemplate
op
=
(
MovingTemplate
)
operationTemplate
;
addResource
.
accept
(
op
.
getMover
(),
getLocNById
.
apply
(
op
.
getStartLocation
().
getId
(),
false
));
addResource
.
accept
(
op
.
getMover
(),
getLocNById
(
op
.
getStartLocation
().
getId
(),
false
));
for
(
MovingObject
obj
:
op
.
getResources
())
{
for
(
MovingObject
obj
:
op
.
getResources
())
{
addResource
.
accept
(
obj
,
getLocNById
.
apply
(
op
.
getStartLocation
().
getId
(),
false
));
addResource
.
accept
(
obj
,
getLocNById
(
op
.
getStartLocation
().
getId
(),
false
));
}
}
}
else
if
(
operationTemplate
instanceof
MooringTemplate
)
{
// Швартовка.
}
else
if
(
operationTemplate
instanceof
MooringTemplate
)
{
// Швартовка.
MooringTemplate
op
=
(
MooringTemplate
)
operationTemplate
;
MooringTemplate
op
=
(
MooringTemplate
)
operationTemplate
;
addResource
.
accept
(
op
.
getMoorer
(),
getLocNById
.
apply
(
op
.
getStartLocation
().
getId
(),
!
op
.
isDirect
()));
addResource
.
accept
(
op
.
getMoorer
(),
getLocNById
(
op
.
getStartLocation
().
getId
(),
!
op
.
isDirect
()));
for
(
MovingObject
obj
:
op
.
getResources
())
{
for
(
MovingObject
obj
:
op
.
getResources
())
{
addResource
.
accept
(
obj
,
getLocNById
.
apply
(
op
.
getStartLocation
().
getId
(),
false
));
addResource
.
accept
(
obj
,
getLocNById
(
op
.
getStartLocation
().
getId
(),
false
));
}
}
}
else
if
(
operationTemplate
instanceof
LoadingTemplate
)
{
// Погрузка.
}
else
if
(
operationTemplate
instanceof
LoadingTemplate
)
{
// Погрузка.
LoadingTemplate
op
=
(
LoadingTemplate
)
operationTemplate
;
LoadingTemplate
op
=
(
LoadingTemplate
)
operationTemplate
;
addResource
.
accept
(
op
.
getLoader
(),
getLocNById
.
apply
(
op
.
getStartLocation
().
getId
(),
op
.
getWithMooring
()));
addResource
.
accept
(
op
.
getLoader
(),
getLocNById
(
op
.
getStartLocation
().
getId
(),
op
.
getWithMooring
()));
for
(
MovingObject
obj
:
op
.
getResources
())
{
for
(
MovingObject
obj
:
op
.
getResources
())
{
addResource
.
accept
(
obj
,
getLocNById
.
apply
(
op
.
getStartLocation
().
getId
(),
false
));
addResource
.
accept
(
obj
,
getLocNById
(
op
.
getStartLocation
().
getId
(),
false
));
}
}
}
}
}
}
...
@@ -748,13 +748,12 @@ public class ConversionUtil {
...
@@ -748,13 +748,12 @@ public class ConversionUtil {
}
}
if
(
t
instanceof
MovingTemplate
)
{
if
(
t
instanceof
MovingTemplate
)
{
MovingTemplate
op
=
(
MovingTemplate
)
t
;
MovingTemplate
op
=
(
MovingTemplate
)
t
;
operationsDestination
.
add
(
getLocNById
.
apply
(
op
.
getDestination
().
getId
(),
false
));
operationsDestination
.
add
(
getLocNById
(
op
.
getDestination
().
getId
(),
false
));
}
else
if
(
t
instanceof
MooringTemplate
)
{
}
else
if
(
t
instanceof
MooringTemplate
)
{
MooringTemplate
op
=
(
MooringTemplate
)
t
;
MooringTemplate
op
=
(
MooringTemplate
)
t
;
operationsDestination
.
add
(
getLocNById
.
apply
(
op
.
getStartLocation
().
getId
(),
op
.
isDirect
()));
operationsDestination
.
add
(
getLocNById
(
op
.
getStartLocation
().
getId
(),
op
.
isDirect
()));
}
else
{
}
else
{
// TODO аккуратно обработать погрузку.
operationsDestination
.
add
(
getLocNById
(
t
.
getStartLocation
().
getId
(),
false
));
operationsDestination
.
add
(
getLocNById
.
apply
(
t
.
getStartLocation
().
getId
(),
false
));
}
}
}
}
...
@@ -764,6 +763,9 @@ public class ConversionUtil {
...
@@ -764,6 +763,9 @@ public class ConversionUtil {
}
}
void
portToMiniZinc_0
()
throws
IOException
{
void
portToMiniZinc_0
()
throws
IOException
{
if
(
task
.
isTypified
())
{
throw
new
ParserException
(
"Attempt to convert typified task as untyped."
);
}
try
{
try
{
writer
=
new
FileWriter
(
fileName
,
false
);
writer
=
new
FileWriter
(
fileName
,
false
);
...
@@ -799,6 +801,9 @@ public class ConversionUtil {
...
@@ -799,6 +801,9 @@ public class ConversionUtil {
}
}
void
portToMiniZinc_1
()
throws
IOException
{
void
portToMiniZinc_1
()
throws
IOException
{
if
(
task
.
isTypified
())
{
throw
new
ParserException
(
"Attempt to convert typified task as untyped."
);
}
try
{
try
{
writer
=
new
FileWriter
(
fileName
,
false
);
writer
=
new
FileWriter
(
fileName
,
false
);
...
@@ -832,6 +837,44 @@ public class ConversionUtil {
...
@@ -832,6 +837,44 @@ public class ConversionUtil {
}
}
}
}
}
}
/* С типизацией. */
void
portToMiniZinc_2
()
throws
IOException
{
if
(!
task
.
isTypified
())
{
throw
new
ParserException
(
"Attempt to convert untyped task as typified."
);
}
try
{
writer
=
new
FileWriter
(
fileName
,
false
);
writer
.
write
(
"n_intervals = "
+
n_intervals
+
";\n"
);
writer
.
write
(
"n_operations = "
+
task
.
getTemplates
().
size
()
+
";\n"
);
writer
.
write
(
"n_locations = "
+
locationNumberById
.
size
()
+
";\n"
);
writer
.
write
(
"n_moving_obj = "
+
movingObjects
.
size
()
+
";\n"
);
writer
.
write
(
"\n"
);
movingObjectLocationDefinition
();
initialLocations
();
weatherWindows
();
operationsContinuity
();
finalLocations
();
presenceOfResourcesInLocation
();
conflictingOperations
();
writer
.
write
(
"n_obj_with_storage = "
+
nObjWithStorage
+
";\n"
);
writer
.
write
(
"n_cargo_types = "
+
cargoes
.
size
()
+
";\n"
);
maxStorageVolume
();
boundaryStorageStates
();
cargoFlows
();
cargoOperations
();
}
finally
{
if
(
writer
!=
null
)
{
writer
.
close
();
}
}
}
}
}
static
public
void
portToMiniZinc_0
(
TaskCase
task
,
String
fileName
)
throws
IOException
{
static
public
void
portToMiniZinc_0
(
TaskCase
task
,
String
fileName
)
throws
IOException
{
...
@@ -839,9 +882,13 @@ public class ConversionUtil {
...
@@ -839,9 +882,13 @@ public class ConversionUtil {
taskData
.
portToMiniZinc_0
();
taskData
.
portToMiniZinc_0
();
}
}
static
public
void
portToMiniZinc_1
(
TaskCase
task
,
String
fileName
)
throws
IOException
{
static
public
void
portToMiniZinc_1
(
TaskCase
task
,
String
fileName
)
{
Task
taskData
=
new
Task
(
task
,
fileName
);
try
{
taskData
.
portToMiniZinc_1
();
Task
taskData
=
new
Task
(
task
,
fileName
);
taskData
.
portToMiniZinc_1
();
}
catch
(
IOException
e
)
{
throw
new
UncheckedIOException
(
e
);
}
}
}
private
static
class
OperationsComparator
implements
Comparator
<
Operation
>
{
private
static
class
OperationsComparator
implements
Comparator
<
Operation
>
{
...
@@ -850,7 +897,7 @@ public class ConversionUtil {
...
@@ -850,7 +897,7 @@ public class ConversionUtil {
}
}
}
}
static
public
void
resolveMiniZincResults
(
TaskCase
task
,
String
fileName
)
throws
IOException
,
ParserException
{
static
public
void
resolveMiniZincResults
(
TaskCase
task
,
String
fileName
)
{
ArrayList
<
Operation
>
operations
=
null
;
ArrayList
<
Operation
>
operations
=
null
;
Integer
result
=
null
;
Integer
result
=
null
;
...
@@ -911,19 +958,25 @@ public class ConversionUtil {
...
@@ -911,19 +958,25 @@ public class ConversionUtil {
continue
;
continue
;
}
}
if
(
line
.
equals
(
"=====UNSATISFIABLE====="
))
{
if
(
line
.
equals
(
"=====UNSATISFIABLE====="
))
{
throw
new
ParserException
(
"No solution."
)
;
result
=
-
1
;
}
}
break
;
break
;
}
}
if
(
operations
==
null
)
{
throw
new
ParserException
(
"No \"op_status\" in input"
);
}
if
(
result
==
null
)
{
if
(
result
==
null
)
{
throw
new
ParserException
(
"No result in input"
);
throw
new
ParserException
(
"No result in input"
);
}
}
if
(
operations
==
null
)
{
if
(
result
==
-
1
)
{
operations
=
new
ArrayList
<>();
}
else
{
throw
new
ParserException
(
"No \"op_status\" in input"
);
}
}
operations
.
sort
(
new
OperationsComparator
());
operations
.
sort
(
new
OperationsComparator
());
task
.
setSolution
(
operations
);
task
.
setSolution
(
operations
);
task
.
setSolution_result
(
result
);
task
.
setSolution_result
(
result
);
}
catch
(
IOException
e
)
{
throw
new
UncheckedIOException
(
e
);
}
}
}
}
}
}
src/inport/Main.java
View file @
ef1aa7f0
...
@@ -2,19 +2,10 @@ package inport;
...
@@ -2,19 +2,10 @@ package inport;
import
java.io.*
;
import
java.io.*
;
public
class
Main
{
import
static
inport
.
Testing
.
solveTask_1
;
import
static
inport
.
Testing
.
test_1
;
private
static
void
removeDirectory
(
File
dir
)
{
public
class
Main
{
if
(
dir
.
isDirectory
())
{
File
[]
files
=
dir
.
listFiles
();
if
(
files
!=
null
&&
files
.
length
>
0
)
{
for
(
File
aFile
:
files
)
{
removeDirectory
(
aFile
);
}
}
}
dir
.
delete
();
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
if
(
args
.
length
==
0
)
{
if
(
args
.
length
==
0
)
{
...
@@ -26,55 +17,26 @@ public class Main {
...
@@ -26,55 +17,26 @@ public class Main {
switch
(
type
)
{
switch
(
type
)
{
case
"solve"
:
{
case
"solve"
:
{
String
fileName
=
args
[
1
];
String
fileName
=
args
[
1
];
long
start
=
System
.
currentTimeMillis
();
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"
;
TaskCase
task
=
new
TaskCase
();
TaskCase
task
=
new
TaskCase
();
try
{
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
);
task
.
deserialize
(
fileName
);
ConversionUtil
.
portToMiniZinc_1
(
task
,
minizincData
);
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
long
start
=
System
.
currentTimeMillis
();
break
;
}
ProcessBuilder
pb
=
new
ProcessBuilder
(
"minizinc"
,
"--solver"
,
"Chuffed"
,
constraints
,
minizincData
,
"-o"
,
solverResults
);
Process
process
=
pb
.
start
();
int
exitCode
=
process
.
waitFor
();
assert
exitCode
==
0
;
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
);
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
;
break
;
}
}
case
"to_MiniZinc_0"
:
{
case
"to_MiniZinc_0"
:
{
...
@@ -131,6 +93,9 @@ public class Main {
...
@@ -131,6 +93,9 @@ public class Main {
}
}
break
;
break
;
}
}
case
"testing"
:
test_1
();
break
;
default
:
default
:
System
.
out
.
println
(
"Unknown type \""
+
type
+
"\""
);
System
.
out
.
println
(
"Unknown type \""
+
type
+
"\""
);
}
}
...
...
src/inport/MovingTemplate.java
View file @
ef1aa7f0
...
@@ -13,7 +13,7 @@ import java.util.OptionalInt;
...
@@ -13,7 +13,7 @@ import java.util.OptionalInt;
public
class
MovingTemplate
extends
TowUsingTemplate
{
public
class
MovingTemplate
extends
TowUsingTemplate
{
private
MovingObject
mover
;
private
MovingObject
mover
;
private
OptionalInt
moverType
;
private
OptionalInt
moverType
=
OptionalInt
.
empty
()
;
private
Berth
destination
;
private
Berth
destination
;
...
...
src/inport/ParserException.java
View file @
ef1aa7f0
package
inport
;
package
inport
;
public
class
ParserException
extends
Exception
{
public
class
ParserException
extends
Runtime
Exception
{
ParserException
(
String
mess
)
{
ParserException
(
String
mess
)
{
super
(
mess
);
super
(
mess
);
}
}
...
...
src/inport/TaskCase.java
View file @
ef1aa7f0
...
@@ -626,31 +626,34 @@ public class TaskCase {
...
@@ -626,31 +626,34 @@ public class TaskCase {
templates
.
add
(
mt
);
templates
.
add
(
mt
);
m_template
.
put
(
mt
.
getId
(),
mt
);
m_template
.
put
(
mt
.
getId
(),
mt
);
}
}
break
;
break
;
case
Time_Windows:
case
Time_Windows:
break
;
break
;
case
Cargo_Flows:
cargoFlows
.
add
(
new
CargoFlow
(
strLine
,
m_storage
,
m_cargo
));
case
Cargo_Flows:
cargoFlows
.
add
(
new
CargoFlow
(
strLine
,
m_storage
,
m_cargo
));
break
;
break
;
case
Initial_Vessel_State:
vesselInitialState
.
add
(
fromString
(
strLine
,
m_berth
,
m_vessel
));
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
));
case
Initial_Storage_State:
storageInitialState
.
add
(
new
StorageState
(
strLine
,
m_storage
,
m_vessel
,
m_cargo
));
break
;
break
;
case
Final_Vessel_State:
vesselEndState
.
add
(
fromString
(
strLine
,
m_berth
,
m_vessel
));
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
));
case
Final_Storage_State:
storageEndState
.
add
(
new
StorageState
(
strLine
,
m_storage
,
m_vessel
,
m_cargo
));
break
;
break
;
case
Task_Properties:
case
Task_Properties:
{
{
String
[]
rs
=
strLine
.
split
(
";"
);
String
[]
rs
=
strLine
.
split
(
";"
);
planningInterval
=
Double
.
parseDouble
(
rs
[
0
].
trim
());
planningInterval
=
Double
.
parseDouble
(
rs
[
0
].
trim
());
criterionType
=
Integer
.
parseInt
(
rs
[
1
].
trim
());
criterionType
=
Integer
.
parseInt
(
rs
[
1
].
trim
());
}
}
break
;
break
;
case
Solution:
// Тут чтение операций если надо. Потом подумаем
case
Solution:
// Тут чтение операций если надо. Потом подумаем
break
;
if
(
numInside
==
1
)
{
solution_result
=
Double
.
parseDouble
(
strLine
.
trim
());
}
break
;
default
:
default
:
break
;
break
;
}
}
}
}
//Close the input stream
//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
...
@@ -45,7 +45,7 @@ Final Storage State
0; 11; 2.0
0; 11; 2.0
Task Properties
Task Properties
15
.0;0
20
.0;0
Solution
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