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
e9578ce1
Commit
e9578ce1
authored
Aug 09, 2019
by
Vladislav Kiselev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Улучшен дебажный вывод.
parent
e5a324ff
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
91 deletions
+43
-91
src/inport/ConversionUtils/MZnResultsResolver.java
src/inport/ConversionUtils/MZnResultsResolver.java
+10
-4
src/inport/ConversionUtils/Solver.java
src/inport/ConversionUtils/Solver.java
+10
-2
src/inport/Main.java
src/inport/Main.java
+23
-85
No files found.
src/inport/ConversionUtils/MZnResultsResolver.java
View file @
e9578ce1
...
@@ -17,7 +17,7 @@ public class MZnResultsResolver {
...
@@ -17,7 +17,7 @@ public class MZnResultsResolver {
return
lim2
-
lim1
+
1
;
return
lim2
-
lim1
+
1
;
}
}
p
rivate
static
void
parseArray
(
Map
<
String
,
ArrayList
<
ArrayList
<
String
>>>
arrays
,
int
pos
,
String
line
,
TaskCase
taskCase
,
String
nam
e
)
{
p
ublic
static
ArrayList
<
ArrayList
<
String
>>
parse2dArray
(
int
pos
,
String
line
,
TaskCase
taskCas
e
)
{
int
index
=
line
.
indexOf
(
"array"
,
pos
);
int
index
=
line
.
indexOf
(
"array"
,
pos
);
if
(
index
>=
pos
)
{
// Из flatzinc-а.
if
(
index
>=
pos
)
{
// Из flatzinc-а.
...
@@ -36,7 +36,7 @@ public class MZnResultsResolver {
...
@@ -36,7 +36,7 @@ public class MZnResultsResolver {
res
.
get
(
i
).
add
(
values
[
i
*
dim2
+
j
].
trim
());
res
.
get
(
i
).
add
(
values
[
i
*
dim2
+
j
].
trim
());
}
}
}
}
arrays
.
put
(
name
,
res
)
;
return
res
;
}
}
}
else
{
// Из minizinc-а
}
else
{
// Из minizinc-а
while
((
pos
<
line
.
length
())
&&
(
line
.
charAt
(
pos
)
!=
'['
)
&&
(
line
.
charAt
(
pos
)
!=
'{'
))
{
while
((
pos
<
line
.
length
())
&&
(
line
.
charAt
(
pos
)
!=
'['
)
&&
(
line
.
charAt
(
pos
)
!=
'{'
))
{
...
@@ -81,9 +81,10 @@ public class MZnResultsResolver {
...
@@ -81,9 +81,10 @@ public class MZnResultsResolver {
}
}
res
.
add
(
subRes
);
res
.
add
(
subRes
);
}
}
arrays
.
put
(
name
,
res
)
;
return
res
;
}
}
}
}
return
null
;
}
}
public
static
void
resolveMiniZincResults
(
TaskCase
taskCase
,
String
fileName
)
{
public
static
void
resolveMiniZincResults
(
TaskCase
taskCase
,
String
fileName
)
{
...
@@ -118,7 +119,12 @@ public class MZnResultsResolver {
...
@@ -118,7 +119,12 @@ public class MZnResultsResolver {
if
(
name
.
matches
(
"\\d+"
))
{
if
(
name
.
matches
(
"\\d+"
))
{
continue
;
continue
;
}
}
parseArray
(
arrays
,
pos
,
line
,
taskCase
,
name
);
{
ArrayList
<
ArrayList
<
String
>>
res
=
parse2dArray
(
pos
,
line
,
taskCase
);
if
(
res
!=
null
)
{
arrays
.
put
(
name
,
res
);
}
}
}
}
for
(
String
keyArray
:
Arrays
.
asList
(
"op_status"
,
"participation_as_resource"
))
{
for
(
String
keyArray
:
Arrays
.
asList
(
"op_status"
,
"participation_as_resource"
))
{
...
...
src/inport/ConversionUtils/Solver.java
View file @
e9578ce1
...
@@ -25,6 +25,11 @@ public class Solver {
...
@@ -25,6 +25,11 @@ public class Solver {
private
int
timeLimitS
;
private
int
timeLimitS
;
private
String
flatZincSolver
=
""
;
private
String
flatZincSolver
=
""
;
private
String
solverResults
=
""
;
public
void
setSolverResults
(
String
solverResults
)
{
this
.
solverResults
=
solverResults
;
}
public
void
setTask
(
TaskCase
task
)
{
public
void
setTask
(
TaskCase
task
)
{
this
.
task
=
task
;
this
.
task
=
task
;
}
}
...
@@ -75,7 +80,10 @@ public class Solver {
...
@@ -75,7 +80,10 @@ public class Solver {
tempDir
=
tempDir
+
"/"
+
i
+
"/"
;
tempDir
=
tempDir
+
"/"
+
i
+
"/"
;
String
minizincData
=
tempDir
+
"minizinc_data.dzn"
;
String
minizincData
=
tempDir
+
"minizinc_data.dzn"
;
String
solverResults
=
tempDir
+
"solver_results.txt"
;
if
(
solverResults
.
isEmpty
())
{
solverResults
=
tempDir
+
"solver_results.txt"
;
}
String
constraints
=
tempDir
+
"constraints.mzn"
;
String
constraints
=
tempDir
+
"constraints.mzn"
;
String
flatZincConstraints
=
tempDir
+
"model.fzn"
;
String
flatZincConstraints
=
tempDir
+
"model.fzn"
;
...
@@ -199,7 +207,7 @@ public class Solver {
...
@@ -199,7 +207,7 @@ public class Solver {
}
catch
(
UncheckedIOException
|
IOException
|
InterruptedException
|
ParserException
ex
)
{
}
catch
(
UncheckedIOException
|
IOException
|
InterruptedException
|
ParserException
ex
)
{
return
ex
.
getMessage
();
return
ex
.
getMessage
();
}
finally
{
}
finally
{
removeDirectory
(
candidate
);
//
removeDirectory(candidate);
}
}
return
""
;
return
""
;
}
}
...
...
src/inport/Main.java
View file @
e9578ce1
...
@@ -207,7 +207,7 @@ public class Main {
...
@@ -207,7 +207,7 @@ public class Main {
private
static
void
debug
(
Solver
solver
,
int
timeLimitS
)
{
private
static
void
debug
(
Solver
solver
,
int
timeLimitS
)
{
String
fileName
=
"experiment/in.ipp"
;
String
fileName
=
"experiment/in.ipp"
;
String
solverResults
=
"
temp_data
/solver_results.txt"
;
String
solverResults
=
"
experiment
/solver_results.txt"
;
String
output
=
"experiment/debug_info.txt"
;
String
output
=
"experiment/debug_info.txt"
;
TaskCase
task
=
new
TaskCase
();
TaskCase
task
=
new
TaskCase
();
...
@@ -223,6 +223,7 @@ public class Main {
...
@@ -223,6 +223,7 @@ public class Main {
solver
.
setTimeLimitS
(
timeLimitS
);
solver
.
setTimeLimitS
(
timeLimitS
);
solver
.
setTempDir
(
"temp_data"
);
solver
.
setTempDir
(
"temp_data"
);
solver
.
setTask
(
task
);
solver
.
setTask
(
task
);
solver
.
setSolverResults
(
solverResults
);
String
error
=
solver
.
solve
();
String
error
=
solver
.
solve
();
long
finish
=
System
.
currentTimeMillis
();
long
finish
=
System
.
currentTimeMillis
();
...
@@ -235,8 +236,7 @@ public class Main {
...
@@ -235,8 +236,7 @@ public class Main {
task
.
serialize
(
fileName
);
task
.
serialize
(
fileName
);
}
}
// TODO переделать для or-tools
debugInfo
(
task
,
solverResults
,
output
);
// debugInfo(task, solverResults, output);
}
}
private
static
void
debugReadWrite
()
{
private
static
void
debugReadWrite
()
{
...
@@ -287,115 +287,53 @@ public class Main {
...
@@ -287,115 +287,53 @@ public class Main {
}
}
String
line
;
String
line
;
int
linesNumber
=
0
;
while
(((
line
=
br
.
readLine
())
!=
null
))
{
while
(((
line
=
br
.
readLine
())
!=
null
))
{
System
.
out
.
println
(
"line : "
+
line
);
line
=
line
.
trim
();
line
=
line
.
trim
();
if
(
line
.
equals
(
""
))
{
if
(
line
.
equals
(
""
))
{
continue
;
continue
;
}
}
linesNumber
++;
if
(
linesNumber
<=
1
)
{
continue
;
}
int
pos
=
0
;
int
pos
=
0
;
while
((
pos
<
line
.
length
())
&&
(
line
.
charAt
(
pos
)
!=
' '
))
{
while
((
pos
<
line
.
length
())
&&
(
line
.
charAt
(
pos
)
!=
' '
))
{
pos
++;
pos
++;
}
}
String
name
=
line
.
substring
(
0
,
pos
);
String
name
=
line
.
substring
(
0
,
pos
);
if
(
name
.
equals
(
"----------"
))
{
if
(
(
name
.
equals
(
"----------"
))
||
(
name
.
equals
(
"=====UNSATISFIABLE====="
)
))
{
break
;
break
;
}
}
while
((
pos
<
line
.
length
())
&&
(
line
.
charAt
(
pos
)
!=
'['
)
&&
(
line
.
charAt
(
pos
)
!=
'{'
))
{
System
.
out
.
println
(
name
);
pos
++;
}
int
arrayFirstDim
=
((
int
)
task
.
getPlanningInterval
())
+
2
;
int
arraySecondDim
=
0
;
if
(
line
.
charAt
(
pos
)
==
'{'
)
{
pos
++;
int
nextPos
=
pos
;
while
(
line
.
charAt
(
nextPos
)
!=
'}'
)
{
nextPos
++;
}
String
[]
dimensions
=
line
.
substring
(
pos
,
nextPos
).
trim
().
split
(
" "
);
if
(
dimensions
.
length
>
0
)
{
arrayFirstDim
=
Integer
.
valueOf
(
dimensions
[
0
].
trim
());
}
if
(
dimensions
.
length
>
1
)
{
arraySecondDim
=
Integer
.
valueOf
(
dimensions
[
1
].
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
());
}
{
// bool to int
ArrayList
<
ArrayList
<
String
>>
array
=
MZnResultsResolver
.
parse2dArray
(
pos
,
line
,
task
);
for
(
int
i
=
0
;
i
<
elements
.
size
();
i
++)
{
if
(
array
!=
null
)
{
if
(
elements
.
get
(
i
).
equals
(
"true"
))
{
int
maxSize
=
0
;
elements
.
set
(
i
,
"1"
);
}
if
(
elements
.
get
(
i
).
equals
(
"false"
))
{
elements
.
set
(
i
,
"0"
);
}
}
}
int
maxLength
=
0
;
for
(
ArrayList
<
String
>
a
:
array
)
{
for
(
String
val
:
elements
)
{
for
(
int
j
=
0
;
j
<
a
.
size
();
j
++)
{
maxLength
=
Math
.
max
(
maxLength
,
val
.
length
());
if
(
a
.
get
(
j
).
equals
(
"true"
))
{
a
.
set
(
j
,
"1"
);
}
}
if
(
a
.
get
(
j
).
equals
(
"false"
))
{
if
((
arrayFirstDim
!=
0
)
&&
(
elements
.
size
()
%
arrayFirstDim
==
0
)
&&
((
arraySecondDim
==
0
)
||
(
elements
.
size
()
%
(
arrayFirstDim
*
arraySecondDim
)
!=
0
)))
{
a
.
set
(
j
,
"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
+
" "
);
maxSize
=
Math
.
max
(
maxSize
,
a
.
get
(
j
).
length
()
);
}
}
writer
.
write
(
"\n"
);
}
}
writer
.
write
(
"\n"
);
}
else
if
((
arrayFirstDim
!=
0
)
&&
(
arraySecondDim
!=
0
)
&&
(
elements
.
size
()
%
(
arrayFirstDim
*
arraySecondDim
)
==
0
))
{
writer
.
write
(
name
+
" :\n"
);
writer
.
write
(
name
+
" :\n"
);
for
(
int
i
=
0
;
i
<
elements
.
size
();
i
+=
arrayFirstDim
*
arraySecondDim
)
{
for
(
ArrayList
<
String
>
a
:
array
)
{
for
(
int
j
=
0
;
j
<
arrayFirstDim
;
j
++)
{
writer
.
write
(
" "
);
for
(
int
k
=
0
;
k
<
arraySecondDim
;
k
++)
{
String
val
=
elements
.
get
(
i
+
j
*
arraySecondDim
+
k
);
for
(
int
l
=
val
.
length
();
l
<
maxLength
;
l
++)
{
writer
.
write
(
" "
);
writer
.
write
(
" "
);
}
for
(
String
val
:
a
)
{
writer
.
write
(
val
+
" "
);
writer
.
write
(
new
String
(
new
char
[
maxSize
-
val
.
length
()]).
replace
(
"\0"
,
" "
)
}
+
val
+
" "
);
writer
.
write
(
"\n"
);
}
}
writer
.
write
(
"\n"
);
writer
.
write
(
"\n"
);
}
}
writer
.
write
(
"\n"
);
writer
.
write
(
"\n"
);
}
}
}
}
writer
.
close
();
writer
.
close
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
System
.
out
.
println
(
e
.
getMessage
());
...
...
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