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
b956d73f
Commit
b956d73f
authored
Aug 05, 2019
by
Vladislav Kiselev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Исправлены ошибки аргументов командной строки.
parent
648a3509
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
56 deletions
+80
-56
src/inport/Main.java
src/inport/Main.java
+80
-56
No files found.
src/inport/Main.java
View file @
b956d73f
...
...
@@ -4,29 +4,38 @@ import java.io.*;
import
java.util.ArrayList
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.util.function.
BiFunction
;
import
java.util.function.
Supplier
;
import
static
inport
.
Testing
.*;
import
inport.ConversionUtils.MZnResultsResolver
;
import
inport.ConversionUtils.ParserException
;
import
inport.ConversionUtils.Solver
;
import
inport.ConversionUtils.Task
;
import
org.kohsuke.args4j.CmdLineException
;
import
org.kohsuke.args4j.CmdLineParser
;
import
org.kohsuke.args4j.Option
;
public
class
Main
{
private
static
final
int
DEFAULT_TIME_LIMIT_S
=
3600
;
@Option
(
name
=
"-fzs"
,
aliases
=
"--flat_zinc_solver"
,
usage
=
"Path to executable file of flat zinc solver."
)
private
String
flatZincSolver
=
""
;
private
enum
ConversionType
{
Undefined
(
""
,
(
TaskCase
t
,
Integer
i
)
->
""
),
WithoutSplitting
(
"Without splitting"
,
Testing:
:
solveTask_2
),
WithSplitting
(
"With splitting"
,
Testing:
:
solveTaskWithPartialCargoOp
),
Greedy
(
"Greedy"
,
Testing:
:
solveTaskWithGreedyConstraints
),
Greedy_v2
(
"Greedy v2"
,
Testing:
:
solveTaskWithGreedyConstraintsV2
);
Undefined
(
""
,
Testing:
:
getTask_2_Solver
),
WithoutSplitting
(
"Without splitting"
,
Testing:
:
getTask_2_Solver
),
WithSplitting
(
"With splitting"
,
Testing:
:
getTaskWithPartialCargoOp_Solver
),
Greedy
(
"Greedy"
,
Testing:
:
getTaskWithGreedyConstraints_Solver
),
Greedy_v2
(
"Greedy v2"
,
Testing:
:
getTaskWithGreedyConstraintsV2_Solver
);
private
final
String
text
;
private
final
BiFunction
<
TaskCase
,
Integer
,
String
>
solver
;
ConversionType
(
String
text
,
BiFunction
<
TaskCase
,
Integer
,
String
>
solver
)
{
private
final
Supplier
<
Solver
>
solversGetter
;
ConversionType
(
String
text
,
Supplier
<
Solver
>
solversGerrer
)
{
this
.
text
=
text
;
this
.
solver
=
solv
er
;
this
.
solver
sGetter
=
solversGerr
er
;
}
public
static
ConversionType
fromString
(
String
text
)
{
for
(
ConversionType
t
:
ConversionType
.
values
())
{
...
...
@@ -50,11 +59,21 @@ public class Main {
return
s
.
toString
();
}
public
static
void
main
(
String
[]
args
)
{
if
(
args
.
length
==
0
)
{
System
.
out
.
println
(
"To few arguments."
);
return
;
private
void
doMain
(
final
String
[]
args
)
throws
IOException
{
final
CmdLineParser
parser
=
new
CmdLineParser
(
this
);
if
(
args
.
length
<
1
)
{
parser
.
printUsage
(
System
.
out
);
System
.
exit
(-
1
);
}
/* TODO
try {
parser.parseArgument(args);
} catch (CmdLineException clEx) {
System.out.println("ERROR: Unable to parse command-line options: " + clEx);
}
*/
// flatZincSolver = "external_tools/or-tools_flatzinc_Ubuntu-18.04-64bit_v7.2.6977/bin/fzn-or-tools";
String
type
=
args
[
0
];
switch
(
type
)
{
...
...
@@ -63,16 +82,11 @@ public class Main {
long
start
=
System
.
currentTimeMillis
();
TaskCase
task
=
new
TaskCase
();
try
{
task
.
deserialize
(
fileName
);
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
break
;
}
S
tring
erro
r
;
S
olver
solve
r
;
if
(!
task
.
isTypified
())
{
error
=
solveTask_1
(
task
,
DEFAULT_TIME_LIMIT_S
);
solver
=
getTask_2_Solver
(
);
}
else
{
ConversionType
t
=
(
args
.
length
==
2
)
?
ConversionType
.
WithoutSplitting
:
ConversionType
.
fromString
(
args
[
2
]);
...
...
@@ -80,9 +94,15 @@ public class Main {
System
.
out
.
println
(
undefinedTypeErrorMess
(
args
[
2
]));
return
;
}
error
=
t
.
solver
.
apply
(
task
,
DEFAULT_TIME_LIMIT_S
);
solver
=
t
.
solversGetter
.
get
(
);
}
solver
.
setTask
(
task
);
solver
.
setTimeLimitS
(
DEFAULT_TIME_LIMIT_S
);
solver
.
setTempDir
(
"temp_data"
);
String
error
=
solver
.
solve
();
long
finish
=
System
.
currentTimeMillis
();
System
.
out
.
println
((
finish
-
start
)
+
" milliseconds"
);
...
...
@@ -97,24 +117,17 @@ public class Main {
String
input
=
args
[
1
];
String
output
=
args
[
2
];
TaskCase
task
=
new
TaskCase
();
try
{
task
.
deserialize
(
input
);
Task
.
portToMiniZinc_0
(
task
,
output
);
}
catch
(
IOException
ex
)
{
System
.
out
.
println
(
ex
.
getMessage
());
}
break
;
}
case
"to_MiniZinc_1"
:
{
String
input
=
args
[
1
];
String
output
=
args
[
2
];
TaskCase
task
=
new
TaskCase
();
try
{
task
.
deserialize
(
input
);
Task
.
portToMiniZinc_1
(
task
,
output
);
}
catch
(
IOException
ex
)
{
System
.
out
.
println
(
ex
.
getMessage
());
}
break
;
}
case
"resolve_result"
:
{
...
...
@@ -129,7 +142,7 @@ public class Main {
MZnResultsResolver
.
resolveMiniZincResults
(
task
,
fileWIthResult
);
task
.
serialize
(
output
);
}
catch
(
IOException
|
ParserException
ex
)
{
}
catch
(
ParserException
ex
)
{
System
.
out
.
println
(
ex
.
getMessage
());
}
break
;
...
...
@@ -141,8 +154,12 @@ public class Main {
System
.
out
.
println
(
undefinedTypeErrorMess
(
args
[
1
]));
return
;
}
System
.
out
.
println
(
t
.
text
);
debug
(
t
.
solver
,
DEFAULT_TIME_LIMIT_S
);
Solver
s
=
t
.
solversGetter
.
get
();
System
.
out
.
println
(
args
[
1
]
+
" "
+
t
.
text
+
" "
+
s
.
getFlatZincSolver
());
s
.
setFlatZincSolver
(
flatZincSolver
);
debug
(
s
,
DEFAULT_TIME_LIMIT_S
);
break
;
}
case
"debug read-write"
:
{
...
...
@@ -156,14 +173,12 @@ public class Main {
System
.
out
.
println
(
undefinedTypeErrorMess
(
args
[
1
]));
return
;
}
testGroup
(
"with_typing"
,
t
.
solver
,
DEFAULT_TIME_LIMIT_S
);
test_2
(
DEFAULT_TIME_LIMIT_S
);
testGroup
(
"with_typing"
,
t
.
solversGetter
.
get
(),
DEFAULT_TIME_LIMIT_S
);
break
;
case
"test_experiment"
:
testGroup
(
"experiments"
,
Testing:
:
solveTask_2
,
DEFAULT_TIME_LIMIT_S
);
testGroup
(
"experiments"
,
getTask_2_Solver
()
,
DEFAULT_TIME_LIMIT_S
);
break
;
case
"different_parameters"
:
try
{
testingWithDiffParameters
(
"tests/with_typing/Case2.tipp"
,
1
,
30
,
...
...
@@ -175,17 +190,22 @@ public class Main {
// 10, 10,
// 32, 32,
// 1.1, 10);
}
catch
(
IOException
ex
)
{
System
.
out
.
println
(
ex
.
getMessage
());
}
break
;
default
:
System
.
out
.
println
(
"Unknown type \""
+
type
+
"\""
);
}
}
private
static
void
debug
(
BiFunction
<
TaskCase
,
Integer
,
String
>
solver
,
int
timeLimitS
)
{
public
static
void
main
(
String
[]
args
)
{
final
Main
instance
=
new
Main
();
try
{
instance
.
doMain
(
args
);
}
catch
(
IOException
ioEx
)
{
System
.
out
.
println
(
"ERROR: I/O Exception encountered: "
+
ioEx
);
}
}
private
static
void
debug
(
Solver
solver
,
int
timeLimitS
)
{
String
fileName
=
"experiment/in.ipp"
;
String
solverResults
=
"temp_data/solver_results.txt"
;
String
output
=
"experiment/debug_info.txt"
;
...
...
@@ -200,7 +220,10 @@ public class Main {
long
start
=
System
.
currentTimeMillis
();
String
error
=
solver
.
apply
(
task
,
timeLimitS
);
solver
.
setTimeLimitS
(
timeLimitS
);
solver
.
setTempDir
(
"temp_data"
);
solver
.
setTask
(
task
);
String
error
=
solver
.
solve
();
long
finish
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
" "
+
(
finish
-
start
)
/
1000.0
+
" s"
);
...
...
@@ -212,7 +235,8 @@ public class Main {
task
.
serialize
(
fileName
);
}
debugInfo
(
task
,
solverResults
,
output
);
// TODO переделать для or-tools
// debugInfo(task, solverResults, output);
}
private
static
void
debugReadWrite
()
{
...
...
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