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
c8542a5d
Commit
c8542a5d
authored
Mar 28, 2019
by
Vladislav Kiselev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Типизация.
parent
7098b577
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
796 additions
and
158 deletions
+796
-158
src/constraints/conversion_2.mzn
src/constraints/conversion_2.mzn
+114
-56
src/inport/ConversionUtil.java
src/inport/ConversionUtil.java
+441
-82
src/inport/LoadingEquipment.java
src/inport/LoadingEquipment.java
+2
-2
src/inport/LoadingTemplate.java
src/inport/LoadingTemplate.java
+5
-2
src/inport/Main.java
src/inport/Main.java
+168
-4
src/inport/MooringTemplate.java
src/inport/MooringTemplate.java
+3
-1
src/inport/MovingTemplate.java
src/inport/MovingTemplate.java
+4
-2
src/inport/Operation.java
src/inport/Operation.java
+38
-3
src/inport/TaskCase.java
src/inport/TaskCase.java
+1
-1
src/inport/Testing.java
src/inport/Testing.java
+16
-1
src/inport/Tow.java
src/inport/Tow.java
+2
-2
src/inport/TransportShip.java
src/inport/TransportShip.java
+2
-2
No files found.
src/constraints/conversion_2.mzn
View file @
c8542a5d
This diff is collapsed.
Click to expand it.
src/inport/ConversionUtil.java
View file @
c8542a5d
This diff is collapsed.
Click to expand it.
src/inport/LoadingEquipment.java
View file @
c8542a5d
...
...
@@ -22,9 +22,9 @@ public class LoadingEquipment extends MovingObject{
@Override
public
String
toString
()
{
String
res
=
getId
()
+
";"
+
getName
();
String
res
=
getId
()
+
";
"
+
getName
();
if
(
getType
().
isPresent
())
{
res
+=
";"
+
getType
().
getAsInt
();
res
+=
";
"
+
getType
().
getAsInt
();
}
return
res
;
}
...
...
src/inport/LoadingTemplate.java
View file @
c8542a5d
...
...
@@ -95,13 +95,16 @@ public class LoadingTemplate extends OperationTemplate {
return
cargo
;
}
public
LoadingTemplate
(
TransportShip
loader
,
Berth
berth
,
Storage
storage
,
double
intensity
,
int
id
)
{
public
LoadingTemplate
(
TransportShip
loader
,
Berth
berth
,
Storage
storage
,
Cargo
cargo
,
List
<
Integer
>
resourcesTypes
,
boolean
withMooring
,
double
intensity
,
int
id
)
{
super
(
id
,
berth
);
this
.
loader
=
loader
;
this
.
storage
=
storage
;
this
.
resources
=
new
ArrayList
<>();
this
.
resourcesTypes
=
new
ArrayList
<>();
this
.
resourcesTypes
=
new
ArrayList
<>(
resourcesTypes
);
this
.
withMooring
=
withMooring
;
this
.
intensity
=
intensity
;
this
.
cargo
=
cargo
;
}
public
LoadingTemplate
()
{
...
...
src/inport/Main.java
View file @
c8542a5d
package
inport
;
import
java.io.*
;
import
java.util.ArrayList
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
static
inport
.
Testing
.
solveTask_1
;
import
static
inport
.
Testing
.
solveTask_2
;
import
static
inport
.
Testing
.
test_1
;
import
inport.ConversionUtil.*
;
public
class
Main
{
...
...
@@ -27,7 +32,12 @@ public class Main {
break
;
}
String
error
=
solveTask_1
(
task
);
String
error
;
if
(!
task
.
isTypified
())
{
error
=
solveTask_1
(
task
);
}
else
{
error
=
solveTask_2
(
task
);
}
long
finish
=
System
.
currentTimeMillis
();
System
.
out
.
println
((
finish
-
start
)
+
" milliseconds"
);
...
...
@@ -81,16 +91,29 @@ public class Main {
break
;
}
case
"debug"
:
{
String
fileName
=
args
[
1
];
String
output
=
args
[
2
];
String
fileName
=
"experiment/in.ipp"
;
String
solverResults
=
"temp_data/solver_results.txt"
;
String
output
=
"experiment/debug_info.txt"
;
TaskCase
task
=
new
TaskCase
();
try
{
task
.
deserialize
(
fileName
);
task
.
serialize
(
output
);
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
break
;
}
String
error
=
solveTask_2
(
task
);
if
(!
error
.
isEmpty
())
{
System
.
out
.
println
(
"Error : "
+
error
);
break
;
}
else
{
task
.
serialize
(
fileName
);
}
debugInfo
(
task
,
solverResults
,
output
);
break
;
}
case
"testing"
:
...
...
@@ -100,4 +123,145 @@ public class Main {
System
.
out
.
println
(
"Unknown type \""
+
type
+
"\""
);
}
}
private
static
void
debugInfo
(
TaskCase
task
,
String
solverResults
,
String
output
)
{
try
(
FileInputStream
fstream
=
new
FileInputStream
(
solverResults
))
{
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
fstream
));
FileWriter
writer
=
new
FileWriter
(
output
,
false
);
{
ArrayList
<
OperationTemplate
>
operations
=
new
ArrayList
<>(
task
.
getTemplates
());
if
(
task
.
isTypified
())
{
operations
=
Task
.
renumberOperations
(
task
);
}
writer
.
write
(
"operations :\n"
);
int
no
=
1
;
for
(
OperationTemplate
op
:
operations
)
{
writer
.
write
(
" "
+
no
+
" "
+
op
.
toString
()
+
"\n"
);
no
++;
}
writer
.
write
(
"\n"
);
}
Task
t
=
new
Task
(
task
,
""
);
{
ArrayList
<
MovingObject
>
movingObjects
=
new
ArrayList
<>();
movingObjects
.
addAll
(
task
.
getShips
());
movingObjects
.
addAll
(
task
.
getTows
());
movingObjects
.
addAll
(
task
.
getEquipments
());
Map
<
Integer
,
MovingObject
>
objByNo
=
new
TreeMap
<>();
for
(
MovingObject
obj
:
movingObjects
)
{
objByNo
.
put
(
t
.
getMObjNumberById
().
get
(
obj
.
getId
()),
obj
);
}
writer
.
write
(
"moving_objects : \n"
);
for
(
int
i
=
0
;
i
<
movingObjects
.
size
();
i
++)
{
writer
.
write
(
" "
+
(
i
+
1
)
+
" "
+
objByNo
.
get
(
i
).
toString
()
+
"\n"
);
}
writer
.
write
(
"\n"
);
}
String
line
;
int
linesNumber
=
0
;
while
(((
line
=
br
.
readLine
())
!=
null
))
{
line
=
line
.
trim
();
if
(
line
.
equals
(
""
))
{
continue
;
}
linesNumber
++;
if
(
linesNumber
<=
1
)
{
continue
;
}
int
pos
=
0
;
while
((
pos
<
line
.
length
())
&&
(
line
.
charAt
(
pos
)
!=
' '
))
{
pos
++;
}
String
name
=
line
.
substring
(
0
,
pos
);
if
(
name
.
equals
(
"----------"
))
{
break
;
}
while
((
pos
<
line
.
length
())
&&
(
line
.
charAt
(
pos
)
!=
'['
)
&&
(
line
.
charAt
(
pos
)
!=
'{'
))
{
pos
++;
}
int
arrayFirstDim
=
((
int
)
task
.
getPlanningInterval
())
+
2
;
if
(
line
.
charAt
(
pos
)
==
'{'
)
{
pos
++;
int
nextPos
=
pos
;
while
(
line
.
charAt
(
nextPos
)
!=
'}'
)
{
nextPos
++;
}
arrayFirstDim
=
Integer
.
valueOf
(
line
.
substring
(
pos
,
nextPos
).
trim
());
pos
=
nextPos
+
1
;
while
(
line
.
charAt
(
pos
)
!=
'['
)
{
pos
++;
}
}
int
pos2
=
pos
;
while
((
pos2
<
line
.
length
())
&&
(
line
.
charAt
(
pos2
)
!=
']'
))
{
pos2
++;
}
String
values
=
line
.
substring
(
pos
+
1
,
pos2
);
ArrayList
<
String
>
elements
=
new
ArrayList
<>();
for
(
String
val
:
values
.
split
(
","
))
{
elements
.
add
(
val
.
trim
());
}
if
(
name
.
equals
(
"current_moving_operation"
))
{
ArrayList
<
ArrayList
<
Integer
>>
movingOpOfObj
=
t
.
getMovingOpOfObj
();
for
(
int
i
=
0
;
i
<
elements
.
size
();
i
+=
arrayFirstDim
)
{
for
(
int
j
=
0
;
j
<
arrayFirstDim
;
j
++)
{
int
val
=
Integer
.
valueOf
(
elements
.
get
(
i
+
j
));
if
(
val
!=
0
)
{
elements
.
set
(
i
+
j
,
Integer
.
toString
(
movingOpOfObj
.
get
(
i
/
arrayFirstDim
).
get
(
val
-
1
)));
}
}
}
name
=
name
+
" *"
;
}
{
// bool to int
for
(
int
i
=
0
;
i
<
elements
.
size
();
i
++)
{
if
(
elements
.
get
(
i
).
equals
(
"true"
))
{
elements
.
set
(
i
,
"1"
);
}
if
(
elements
.
get
(
i
).
equals
(
"false"
))
{
elements
.
set
(
i
,
"0"
);
}
}
}
int
maxLength
=
0
;
for
(
String
val
:
elements
)
{
maxLength
=
Math
.
max
(
maxLength
,
val
.
length
());
}
if
((
arrayFirstDim
!=
0
)
&&
(
elements
.
size
()
%
arrayFirstDim
==
0
))
{
writer
.
write
(
name
+
" :\n"
);
for
(
int
i
=
0
;
i
<
elements
.
size
();
i
+=
arrayFirstDim
)
{
writer
.
write
(
" "
);
for
(
int
j
=
0
;
j
<
arrayFirstDim
;
j
++)
{
String
val
=
elements
.
get
(
i
+
j
);
for
(
int
k
=
val
.
length
();
k
<
maxLength
;
k
++)
{
writer
.
write
(
" "
);
}
writer
.
write
(
val
+
" "
);
}
writer
.
write
(
"\n"
);
}
writer
.
write
(
"\n"
);
}
}
writer
.
close
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
}
}
src/inport/MooringTemplate.java
View file @
c8542a5d
...
...
@@ -4,6 +4,7 @@
*/
package
inport
;
import
java.util.List
;
import
java.util.OptionalInt
;
/**
...
...
@@ -59,10 +60,11 @@ public class MooringTemplate extends TowUsingTemplate {
this
.
moorer
=
moorer
;
}
public
MooringTemplate
(
TransportShip
moorer
,
Berth
berth
,
double
duration
,
boolean
direct
,
int
id
)
{
public
MooringTemplate
(
TransportShip
moorer
,
Berth
berth
,
List
<
Integer
>
resourcesTypes
,
double
duration
,
boolean
direct
,
int
id
)
{
super
(
duration
,
id
,
berth
);
this
.
moorer
=
moorer
;
this
.
direct
=
direct
;
this
.
setResourcesTypes
(
resourcesTypes
);
}
public
MooringTemplate
()
{
...
...
src/inport/MovingTemplate.java
View file @
c8542a5d
...
...
@@ -4,6 +4,7 @@
*/
package
inport
;
import
java.util.List
;
import
java.util.OptionalInt
;
/**
...
...
@@ -60,10 +61,11 @@ public class MovingTemplate extends TowUsingTemplate {
this
.
moverType
=
moverType
;
}
public
MovingTemplate
(
MovingObject
mover
,
Berth
source
,
Berth
destination
,
double
duration
,
int
id
)
{
public
MovingTemplate
(
MovingObject
mover
,
Berth
source
,
Berth
destination
,
List
<
Integer
>
resourcesTypes
,
double
duration
,
int
id
)
{
super
(
duration
,
id
,
source
);
this
.
mover
=
mover
;
this
.
destination
=
destination
;
this
.
destination
=
destination
;
this
.
setResourcesTypes
(
resourcesTypes
);
}
public
MovingTemplate
()
{
...
...
src/inport/Operation.java
View file @
c8542a5d
...
...
@@ -4,6 +4,8 @@
*/
package
inport
;
import
java.util.List
;
/**
*
* @author topazh_ag
...
...
@@ -13,6 +15,22 @@ public class Operation {
private
OperationTemplate
template
;
private
double
start
;
private
double
duration
;
private
MovingObject
executor
;
private
List
<
MovingObject
>
resources
;
public
List
<
MovingObject
>
getResources
()
{
return
resources
;
}
public
void
setResources
(
List
<
MovingObject
>
resources
)
{
this
.
resources
=
resources
;
}
public
MovingObject
getExecutor
()
{
return
executor
;
}
public
void
setExecutor
(
MovingObject
executor
)
{
this
.
executor
=
executor
;
}
/**
* Get the value of duration
...
...
@@ -75,8 +93,25 @@ public class Operation {
@Override
public
String
toString
()
{
return
template
.
getId
()
+
"; R; "
+
start
+
"; "
+
duration
;
if
(
executor
==
null
)
{
executor
=
ConversionUtil
.
getExecutor
(
template
);
}
if
(
resources
==
null
)
{
resources
=
ConversionUtil
.
getResources
(
template
);
}
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
template
.
getId
()).
append
(
"; R; "
).
append
(
start
).
append
(
"; "
).
append
(
duration
);
sb
.
append
(
" ("
).
append
(
executor
.
getId
()).
append
(
" ["
);
boolean
isFirst
=
true
;
for
(
MovingObject
obj
:
resources
)
{
if
(
isFirst
)
{
isFirst
=
false
;
}
else
{
sb
.
append
(
", "
);
}
sb
.
append
(
obj
.
getId
());
}
sb
.
append
(
"])"
);
return
sb
.
toString
();
}
}
src/inport/TaskCase.java
View file @
c8542a5d
...
...
@@ -660,7 +660,7 @@ public class TaskCase {
br
.
close
();
}
catch
(
FileNotFoundException
ex
)
{
Logger
.
getLogger
(
TaskCase
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
}
public
void
serialize
(
String
fileName
)
...
...
src/inport/Testing.java
View file @
c8542a5d
...
...
@@ -26,6 +26,14 @@ public class Testing {
ConversionUtil:
:
resolveMiniZincResults
);
}
public
static
String
solveTask_2
(
TaskCase
task
)
{
return
solveTask
(
task
,
"conversion_2.mzn"
,
ConversionUtil:
:
portToMiniZinc_2
,
ConversionUtil:
:
resolveMiniZincResults
);
}
/* Возвращает описание ошибки, если ошибки не было, то пустую строку. */
public
static
String
solveTask
(
TaskCase
task
,
String
constraintName
,
...
...
@@ -63,6 +71,13 @@ public class Testing {
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
String
output
=
br
.
lines
().
collect
(
Collectors
.
joining
(
"\n"
));
BufferedReader
br2
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getErrorStream
()));
String
errors
=
br
.
lines
().
collect
(
Collectors
.
joining
(
"\n"
));
System
.
out
.
println
(
"output : "
+
output
);
System
.
out
.
println
(
"errors : "
+
errors
);
if
(
output
.
trim
().
equals
(
"=====UNSATISFIABLE====="
))
{
task
.
setSolution
(
new
ArrayList
<>());
task
.
setSolution_result
(-
1
);
...
...
@@ -72,7 +87,7 @@ public class Testing {
}
catch
(
UncheckedIOException
|
IOException
|
InterruptedException
|
ParserException
ex
)
{
return
ex
.
getMessage
();
}
finally
{
removeDirectory
(
directory
);
//
removeDirectory(directory);
}
return
""
;
}
...
...
src/inport/Tow.java
View file @
c8542a5d
...
...
@@ -21,9 +21,9 @@ public class Tow extends MovingObject {
@Override
public
String
toString
()
{
String
res
=
getId
()
+
";
"
+
getName
()
+
";
1000000"
;
String
res
=
getId
()
+
";
"
+
getName
()
+
";
1000000"
;
if
(
getType
().
isPresent
())
{
res
+=
";"
+
getType
().
getAsInt
();
res
+=
";
"
+
getType
().
getAsInt
();
}
return
res
;
}
...
...
src/inport/TransportShip.java
View file @
c8542a5d
...
...
@@ -32,9 +32,9 @@ public class TransportShip extends MovingObject {
@Override
public
String
toString
()
{
String
res
=
getId
()
+
";
"
+
getName
()
+
";
"
+
cargoMax
;
String
res
=
getId
()
+
";
"
+
getName
()
+
";
"
+
cargoMax
;
if
(
getType
().
isPresent
())
{
res
+=
";"
+
getType
().
getAsInt
();
res
+=
";
"
+
getType
().
getAsInt
();
}
return
res
;
}
...
...
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