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
51f93abe
Commit
51f93abe
authored
Jul 05, 2019
by
Vladislav Kiselev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Вторая версия жадного алгоритма.
parent
aee5e993
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
181 additions
and
48 deletions
+181
-48
src/constraints/conversion_2_greedy_v2.mzn
src/constraints/conversion_2_greedy_v2.mzn
+115
-43
src/inport/ConversionUtils/MZnResultsResolver.java
src/inport/ConversionUtils/MZnResultsResolver.java
+4
-2
src/inport/ConversionUtils/Task.java
src/inport/ConversionUtils/Task.java
+61
-2
src/inport/Testing.java
src/inport/Testing.java
+1
-1
No files found.
src/constraints/conversion_2_greedy_v2.mzn
View file @
51f93abe
This diff is collapsed.
Click to expand it.
src/inport/ConversionUtils/MZnResultsResolver.java
View file @
51f93abe
...
@@ -115,8 +115,10 @@ public class MZnResultsResolver {
...
@@ -115,8 +115,10 @@ public class MZnResultsResolver {
}
}
ArrayList
<
ArrayList
<
String
>>
cargoOpIntensity
;
ArrayList
<
ArrayList
<
String
>>
cargoOpIntensity
;
if
(
arrays
.
containsKey
(
"cargo_op_intensity"
))
{
if
(
arrays
.
containsKey
(
"cargo_op_intensity"
))
{
// Явные нецелые операции.
cargoOpIntensity
=
arrays
.
get
(
"cargo_op_intensity"
);
cargoOpIntensity
=
arrays
.
get
(
"cargo_op_intensity"
);
}
else
if
(
arrays
.
containsKey
(
"real_cargo_value"
))
{
// Жадный алгоритм.
cargoOpIntensity
=
arrays
.
get
(
"real_cargo_value"
);
}
else
{
}
else
{
cargoOpIntensity
=
new
ArrayList
<>();
cargoOpIntensity
=
new
ArrayList
<>();
for
(
int
opNo
=
0
;
opNo
<
opStatus
.
size
();
opNo
++)
{
for
(
int
opNo
=
0
;
opNo
<
opStatus
.
size
();
opNo
++)
{
...
@@ -205,7 +207,7 @@ public class MZnResultsResolver {
...
@@ -205,7 +207,7 @@ public class MZnResultsResolver {
}
}
if
(!
cargoOpIntensity
.
get
(
opNo
).
get
(
t
-
1
).
equals
(
"0"
))
{
if
(!
cargoOpIntensity
.
get
(
opNo
).
get
(
t
-
1
).
equals
(
"0"
))
{
op
.
setIntensity
(
Optional
.
of
(
Integer
.
valueOf
(
cargoOpIntensity
.
get
(
opNo
).
get
(
t
-
1
))));
op
.
setIntensity
(
Optional
.
of
(
Math
.
abs
(
Integer
.
valueOf
(
cargoOpIntensity
.
get
(
opNo
).
get
(
t
-
1
)
))));
}
}
op
.
setFixation
(
true
);
op
.
setFixation
(
true
);
...
...
src/inport/ConversionUtils/Task.java
View file @
51f93abe
...
@@ -10,7 +10,6 @@ import java.io.UncheckedIOException;
...
@@ -10,7 +10,6 @@ import java.io.UncheckedIOException;
import
java.util.*
;
import
java.util.*
;
import
java.util.function.BiConsumer
;
import
java.util.function.BiConsumer
;
import
java.util.function.Consumer
;
import
java.util.function.Consumer
;
import
java.util.function.Function
;
import
static
inport
.
ConversionUtils
.
MZnFormat
.*;
import
static
inport
.
ConversionUtils
.
MZnFormat
.*;
import
static
inport
.
ConversionUtils
.
Utils
.*;
import
static
inport
.
ConversionUtils
.
Utils
.*;
...
@@ -1347,7 +1346,7 @@ public class Task {
...
@@ -1347,7 +1346,7 @@ public class Task {
}
}
}
}
void
dataForGreediness
()
throws
IOException
{
private
void
dataForGreediness
()
throws
IOException
{
ArrayList
<
ArrayList
<
Integer
>>
connectedSections
=
arrayOfIntegerArrays
(
sectionNById
.
size
());
ArrayList
<
ArrayList
<
Integer
>>
connectedSections
=
arrayOfIntegerArrays
(
sectionNById
.
size
());
ArrayList
<
Set
<
Integer
>>
connectedSectionsSet
=
arrayOfIntegerSet
(
sectionNById
.
size
());
ArrayList
<
Set
<
Integer
>>
connectedSectionsSet
=
arrayOfIntegerSet
(
sectionNById
.
size
());
...
@@ -1466,6 +1465,50 @@ public class Task {
...
@@ -1466,6 +1465,50 @@ public class Task {
}
}
}
}
private
void
addIsOpUsedStorAsSecondary
()
throws
IOException
{
ArrayList
<
ArrayList
<
Boolean
>>
is_op_used_stor_as_secondary
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
nSectionsOfRealStorageAndBunkers
;
i
++)
{
is_op_used_stor_as_secondary
.
add
(
new
ArrayList
<>());
for
(
int
j
=
0
;
j
<=
operationTemplates
.
size
();
j
++)
{
is_op_used_stor_as_secondary
.
get
(
i
).
add
(
false
);
}
}
for
(
int
j
=
0
;
j
<
operationTemplates
.
size
();
j
++)
{
if
(
operationTemplates
.
get
(
j
)
instanceof
LoadingTemplate
)
{
LoadingTemplate
op
=
(
LoadingTemplate
)
operationTemplates
.
get
(
j
);
int
section
;
if
(
op
.
getBunker
().
isPresent
())
{
section
=
sectionIdToN
(
op
.
getBunker
().
get
(),
op
.
getCargo
());
}
else
{
section
=
sectionIdToN
(
op
.
getStorage
(),
op
.
getCargo
());
}
is_op_used_stor_as_secondary
.
get
(
section
+
1
).
set
(
j
+
1
,
true
);
}
}
locWrite2DArray
(
writer
,
"is_op_used_stor_as_secondary"
,
is_op_used_stor_as_secondary
,
Objects:
:
toString
,
true
);
}
private
void
addInvolvedOperations
()
throws
IOException
{
ArrayList
<
Set
<
Integer
>>
involved_operations_as_main_stor
=
arrayOfIntegerSet
(
sectionNById
.
size
());
ArrayList
<
Set
<
Integer
>>
involved_operations_as_sec_stor
=
arrayOfIntegerSet
(
sectionNById
.
size
());
for
(
int
i
=
0
;
i
<
operationTemplates
.
size
();
i
++)
{
if
(
operationTemplates
.
get
(
i
)
instanceof
LoadingTemplate
)
{
LoadingTemplate
op
=
(
LoadingTemplate
)
operationTemplates
.
get
(
i
);
int
section_1
=
sectionIdToN
(
op
.
getLoader
(),
op
.
getCargo
());
int
section_2
;
if
(
op
.
getBunker
().
isPresent
())
{
section_2
=
sectionIdToN
(
op
.
getBunker
().
get
(),
op
.
getCargo
());
}
else
{
section_2
=
sectionIdToN
(
op
.
getStorage
(),
op
.
getCargo
());
}
involved_operations_as_main_stor
.
get
(
section_1
).
add
(
i
+
1
);
involved_operations_as_sec_stor
.
get
(
section_2
).
add
(
i
+
1
);
}
}
writeArray
(
writer
,
"involved_operations_as_main_stor"
,
involved_operations_as_main_stor
,
MZnFormat:
:
setToString
);
writeArray
(
writer
,
"involved_operations_as_sec_stor"
,
involved_operations_as_sec_stor
,
MZnFormat:
:
setToString
);
}
void
portToMiniZinc_2_greedy
()
{
void
portToMiniZinc_2_greedy
()
{
if
(!
task
.
isTypified
())
{
if
(!
task
.
isTypified
())
{
throw
new
ParserException
(
"Attempt to convert untyped task as typified."
);
throw
new
ParserException
(
"Attempt to convert untyped task as typified."
);
...
@@ -1478,6 +1521,19 @@ public class Task {
...
@@ -1478,6 +1521,19 @@ public class Task {
}
}
}
}
void
portToMiniZinc_2_greedy_v2
()
{
if
(!
task
.
isTypified
())
{
throw
new
ParserException
(
"Attempt to convert untyped task as typified."
);
}
try
{
portToMiniZinc_2_greedy
();
addIsOpUsedStorAsSecondary
();
addInvolvedOperations
();
}
catch
(
IOException
e
)
{
throw
new
UncheckedIOException
(
e
);
}
}
static
public
void
portToMiniZinc_0
(
TaskCase
task
,
String
fileName
)
{
static
public
void
portToMiniZinc_0
(
TaskCase
task
,
String
fileName
)
{
startConversion
(
task
,
fileName
,
Task:
:
portToMiniZinc_0
);
startConversion
(
task
,
fileName
,
Task:
:
portToMiniZinc_0
);
}
}
...
@@ -1490,6 +1546,9 @@ public class Task {
...
@@ -1490,6 +1546,9 @@ public class Task {
static
public
void
portToMiniZincGreedy
(
TaskCase
task
,
String
fileName
)
{
static
public
void
portToMiniZincGreedy
(
TaskCase
task
,
String
fileName
)
{
startConversion
(
task
,
fileName
,
Task:
:
portToMiniZinc_2_greedy
);
startConversion
(
task
,
fileName
,
Task:
:
portToMiniZinc_2_greedy
);
}
}
static
public
void
portToMiniZincGreedyV2
(
TaskCase
task
,
String
fileName
)
{
startConversion
(
task
,
fileName
,
Task:
:
portToMiniZinc_2_greedy_v2
);
}
static
private
void
startConversion
(
TaskCase
task
,
String
fileName
,
Consumer
<
Task
>
conversion
)
{
static
private
void
startConversion
(
TaskCase
task
,
String
fileName
,
Consumer
<
Task
>
conversion
)
{
try
{
try
{
...
...
src/inport/Testing.java
View file @
51f93abe
...
@@ -68,7 +68,7 @@ public class Testing {
...
@@ -68,7 +68,7 @@ public class Testing {
return
solveTask
(
return
solveTask
(
task
,
task
,
"conversion_2_greedy_v2.mzn"
,
"conversion_2_greedy_v2.mzn"
,
Task:
:
portToMiniZincGreedy
,
Task:
:
portToMiniZincGreedy
V2
,
MZnResultsResolver:
:
resolveMiniZincResults
,
MZnResultsResolver:
:
resolveMiniZincResults
,
timeLimitS
);
timeLimitS
);
}
}
...
...
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