Skip to content

Commit

Permalink
Add support for latex output
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubkottnauer committed Apr 8, 2016
1 parent e8a7eba commit f5bd628
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 23 deletions.
5 changes: 3 additions & 2 deletions DomainTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,11 @@ module DomainTypes =

/// Command line options.
type Options = {
fileName: string;
eps: float;
fileName: string;
heuristic: (Constraint * string) list -> (Constraint * string) list -> Variable list -> int;
heuristicName: string;
latex: bool
}

/// An NCSP problem to be solved.
Expand Down Expand Up @@ -362,4 +363,4 @@ module DomainTypes =

mainVars
|> List.map (fun item -> printfn "%s in [%.8f;%.8f]" item.Name item.Domain.a item.Domain.b)
|> ignore
|> ignore
15 changes: 10 additions & 5 deletions Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ module Main =
optionsSoFar

| "-f"::fileName::xs ->
let newOptionsSoFar = { optionsSoFar with fileName=fileName}
parseCommandLineRec xs newOptionsSoFar
{ optionsSoFar with fileName = fileName }
|> parseCommandLineRec xs

| "-p"::eps::xs ->
let success, value = Double.TryParse eps
if success then
let newOptionsSoFar = { optionsSoFar with eps=value}
parseCommandLineRec xs newOptionsSoFar
{ optionsSoFar with eps = value }
|> parseCommandLineRec xs
else
printfn "Invalid precision. Using the default value 1.0 instead."
parseCommandLineRec xs optionsSoFar
Expand All @@ -121,16 +121,21 @@ module Main =
matchHeuristic heuristicCode optionsSoFar
|> parseCommandLineRec xs

| "-l"::xs ->
{ optionsSoFar with latex = true }
|> parseCommandLineRec xs

| x::xs ->
printfn "Option '%s' is unrecognized" x
parseCommandLineRec xs optionsSoFar

let parseCommandLine args =
let defaultOptions = {
fileName = null;
eps = 1.0;
fileName = null;
heuristic = Heuristics.Random;
heuristicName = "Random";
latex = false;
}

parseCommandLineRec args defaultOptions
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ See more info at http://fsharp.org/use/mac/
- `-f` - path to a file with the problem you want to solve
- `-p` - float size under which the domains need to get to finish the calculation - try to fiddle with this value to get good results. If unspecified, 1.0 will be used.
- `-h` - heuristic you want to use, currently supported values are `rand`, `max-cand`, `dom-first`. If unspecified, `rand` will be used.
- `-l` - output in LaTeX-friendly format.

# License
GNU GPL
30 changes: 21 additions & 9 deletions Solver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,28 @@ module Solver =

else
let reducedProblem = hc3 options p
if reducedProblem.HasSolution then
if reducedProblem.HasSolution && not options.latex then
printfn "Volume of solution box: %.32f" reducedProblem.Volume
reducedProblem.Print

let printResults options (p : Problem) runtime =
match options.latex with
| false ->
printfn "Heuristic: %s" options.heuristicName
printfn "Epsilon: %f" options.eps
printfn "File: %s" options.fileName
printfn "Number of narrowings: %i" ind_narrowing_count
printfn "Number of solution halving: %i" ind_halving_count
printfn "Original volume: %.32f" p.Volume
printfn "Duration (s): %.32f" runtime
printfn "---------"
| true ->
printf "%s" options.fileName.[6..]
printf " & %i" ind_halving_count
printf " & %i" ind_narrowing_count
printf " & %.5f" runtime
printfn " & \\\\"

/// Entry function of the solver.
let solve options (p : Problem) =
let stopWatch = System.Diagnostics.Stopwatch.StartNew()
Expand All @@ -101,12 +119,6 @@ module Solver =

stopWatch.Stop()

printfn "Heuristic: %s" options.heuristicName
printfn "Epsilon: %f" options.eps
printfn "File: %s" options.fileName
printfn "Number of narrowings: %i" ind_narrowing_count
printfn "Number of solution halving: %i" ind_halving_count
printfn "Original volume: %.32f" p.Volume
printfn "Duration (s): %.32f" stopWatch.Elapsed.TotalSeconds
printResults options p stopWatch.Elapsed.TotalSeconds

printfn "---------"

20 changes: 17 additions & 3 deletions run.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@ setlocal EnableDelayedExpansion
SET "heuristicName=%1"
SET "testsFolder=tests"
SET "outputFolder=out"
SET "output=%outputFolder%\%heuristicName%_out.txt"
SET "output=%outputFolder%\out.txt"
SET "eps=0.001"

if not exist %outputFolder% mkdir %outputFolder%

> %output% (
for /r %%i in (%testsFolder%\*) do bin\Debug\HullSolver.exe -f %%i -h %heuristicName% -p %eps%
>> %output% (
echo \begin{table}[]
echo \centering
echo \label{!heuristicName!}
echo \begin{tabular}{lllll}
echo \hline
echo Testovací soubor ^& Poèet rozpùlení intervalu ^& Poèet zúžení intervalù ^& Èas ^& \\ \hline

for %%i in (%testsFolder%\*) do bin\Debug\HullSolver.exe -f %%i -h %heuristicName% -p %eps% -l

echo \end{tabular}
echo \caption{!heuristicName!}
echo \end{table}
echo.
echo.
echo.
)
5 changes: 5 additions & 0 deletions runAll.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
setlocal EnableDelayedExpansion

SET "heuristics=(rand dom-first max-right-cand min-right-cand large-int-first small-int-first shrunk-most-first shrunk-least-first fail-first)"
SET "outputFolder=out"
SET "output=%outputFolder%\out.txt"

if not exist %outputFolder% mkdir %outputFolder%
del %output%

for %%i in %heuristics% do run %%i
8 changes: 4 additions & 4 deletions tests/solotarev
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ f - ay = fay
e - ax = eax
a - cb = acb

a in [-1000,1000]
b in [-1000,1000]
x in [-1000,1000]
y in [-1000,1000]
a in [-10000,10000]
b in [-10000,10000]
x in [-10000,10000]
y in [-10000,10000]
c in [2,2]
d in [3,3]
x_2 in [-10000,10000]
Expand Down

0 comments on commit f5bd628

Please sign in to comment.