Skip to content

Commit

Permalink
Add new heuristic and two new problems
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubkottnauer committed May 4, 2016
1 parent f7bd014 commit eebf2b6
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 82 deletions.
21 changes: 16 additions & 5 deletions Heuristics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@ module Heuristics =

/// Selects the first pair containing a dominant variable. Selects the first pair if no such is available.
static member DominantFirst (q: (Constraint * string) list) pairs (vars: Variable list) =
let dominantList = q
|> List.map(fun (c, v) -> vars |> findVar v)
|> List.filter(fun v -> v.IsDominant)
let l = q
|> List.map(fun (c, v) -> vars |> findVar v)
|> List.filter(fun v -> v.IsDominant)

if dominantList.Length = 0 then
if l.Length = 0 then
0
else
q |> List.findIndex(fun (c, v) -> v = dominantList.Head.Name)
q |> List.findIndex(fun (c, v) -> v = l.Head.Name)

/// Selects the first pair containing a non-dominant variable. Selects the first pair if no such is available.
static member NonDominantFirst (q: (Constraint * string) list) pairs (vars: Variable list) =
let l = q
|> List.map(fun (c, v) -> vars |> findVar v)
|> List.filter(fun v -> not v.IsDominant)

if l.Length = 0 then
0
else
q |> List.findIndex(fun (c, v) -> v = l.Head.Name)

/// Selects the pair whose variable's domain has the highest right bound.
static member MaxRightCand (q: (Constraint * string) list) pairs (vars: Variable list) =
Expand Down
3 changes: 3 additions & 0 deletions Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ module Main =
| "dom-first" ->
{ options with heuristic=Heuristics.DominantFirst
heuristicName="dominant-first"}
| "nondom-first" ->
{ options with heuristic=Heuristics.NonDominantFirst
heuristicName="nondominant-first"}
| "max-right-cand" ->
{ options with heuristic=Heuristics.MaxRightCand
heuristicName="max-right-cand"}
Expand Down
2 changes: 1 addition & 1 deletion runAll.cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@echo off
setlocal EnableDelayedExpansion

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

Expand Down
58 changes: 58 additions & 0 deletions tests/conform1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// http://homepages.math.uic.edu/~jan/Demo/conform1.html

t1 t2 t3

t2 * t3 = t2t3
t1 * t2 = t1t2
t1 * t3 = t1t3
d * t2t3 = 8t2t3
d * t1t2 = 8t1t2
d * t1t3 = 8t1t3
t1 * t1 = t1_2
t2 * t2 = t2_2
t3 * t3 = t3_2
t2_2 * t3_2 = t2_2t3_2
t3_2 * t1_2 = t3_2t1_2
t1_2 * t2_2 = t1_2t2_2
b * t2_2t3_2 = 3t2_2t3_2
b * t3_2t1_2 = 3t3_2t1_2
b * t1_2t2_2 = 3t1_2t2_2
t2_2 + t3_2 = i1
t3_2 + t1_2 = i2
t1_2 + t2_2 = i3
a + i1 = j1
a + i2 = j2
a + i3 = j3
j1 + 3t2_2t3_2 = 8t2t3
j2 + 3t3_2t1_2 = 8t1t2
j3 + 3t1_2t2_2 = 8t1t3


a in [9,9]
b in [3,3]
c in [2,2]
d in [8,8]
t1 in [-1000,1000]
t2 in [-1000,1000]
t3 in [-1000,1000]
t2t3 in [-1000,1000]
t1t2 in [-1000,1000]
t1t3 in [-1000,1000]
8t2t3 in [-1000,1000]
8t1t2 in [-1000,1000]
8t1t3 in [-1000,1000]
t1_2 in [-1000,1000]
t2_2 in [-1000,1000]
t3_2 in [-1000,1000]
t2_2t3_2 in [-1000,1000]
t3_2t1_2 in [-1000,1000]
t1_2t2_2 in [-1000,1000]
3t2_2t3_2 in [-1000,1000]
3t3_2t1_2 in [-1000,1000]
3t1_2t2_2 in [-1000,1000]
i1 in [-1000,1000]
i2 in [-1000,1000]
i3 in [-1000,1000]
j1 in [-1000,1000]
j2 in [-1000,1000]
j3 in [-1000,1000]
1 change: 0 additions & 1 deletion tests/polyn1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ a * x_2 = ax_2
a in [20,20]
b in [-64,-64]
x in [-5,5]
// TODO: Narrowing breaks (no solutions are found) when x_2's initial domain is allowed to be negative. Why?
x_2 in [0,10000]
x_4 in [-1000,10000]
ax_2 in [-1000,100000]
16 changes: 16 additions & 0 deletions tests/polyn2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// x^3 - 2x = 0
// Solutions: x in {0; -sqrt(2); sqrt(2)}

x

x * x = x_2
x_2 * x = x_3
a * x = ax
x_3 - ax = b

a in [2,2]
b in [0,0]
x in [-500,500]
x_2 in [0,10000]
x_3 in [-1000,10000]
ax in [-1000,1000]
Loading

0 comments on commit eebf2b6

Please sign in to comment.