0

I want to find a solution for set of numerical equations and I wondering whether Alloy could be used for that.

I've found limited information on alloy that seem to suggest (to me, at least) that it could be done, but I've found no examples of similar problems.

It certainly isn't easy, so before investing time and some money in literature I'd like to know if this is doable or not.

Simplified example:

(1) a + b = c, (2) a > b, (3) a > 0, (4) b > 0,  (5) c > 0 

One solution would be

a = 2, b = 1, c = 3

Any insights on the usability of Alloy or better tools / solutions would be greatly appreciated.

Kind regards,

Paul.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Paul
  • 37
  • 5

2 Answers2

1

Daniel Jackson discourage using Alloy for numeric problems. The reason is that Alloy uses a SAT solver and this does not scale well since it severely limits the range of available integers. By default Alloy uses 4 bits for an integer: -8..7. (This can be enlarged with the run command but will of course slow down finding an answer.) The mindset of not to use numbers also influenced the syntax, there are no nice operators for numbers. I.e. addition is 5.plus[6].

That said, your problem would look like:

pred f[a,b,c : Int] {
    a.plus[b] = c 
    a > b
    a > 0
    b > 0
    c > 0 
}

run f for 4 int

The answer can be found in the evaluator or text view. The first answer I got was a=4, b=1, c=5.

Alloy was developed around 2010 and since then there are SMT solvers that work similar to SAT solvers but can handle numeric problems as well. Alloy could be made to use those solvers I think. Would be nice because the language is incredibly nice to work with, the lack of number is a real miss.

Update Added a constraint puzzle at https://github.com/AlloyTools/models/blob/master/puzzle/einstein/einstein-wikipedia.als

Peter Kriens
  • 15,196
  • 1
  • 37
  • 55
0

Alloy is specialized as a relational constraint solver. While it can do very simple linear programming, you might want to look at a specialized tool like MiniZinc instead.

Hovercouch
  • 1,962
  • 12
  • 12