confuse to determine the domain of variables
- From: "rinda" <akbarhome@xxxxxxxxx>
- Date: 23 Dec 2006 06:19:37 -0800
Hi,
I try to make simple constraint solver using ruby programming language.
I use backtracking technique and optionally forward checking technique.
I can solve the 4 queen problem. Then I try to solve the complicate
problem, like this one:
http://www.mozart-oz.org/documentation/fdt/node47.html#section.scheduling.house
Task Description Duration Predecessor Company
a Erecting.. 7 none Construction Inc.
.......
I know how to specify the constraint, just like in my ruby code,
job1.rb:
# precedence constraint
cons1 = Constraint.new(Proc.new{|var1,var2| var1 + 7 <= var2}, [a,b])
cons2 = Constraint.new(Proc.new{|var1,var2| var1 + 3 <= var2}, [b,c])
cons3 = Constraint.new(Proc.new{|var1,var2| var1 + 7 <= var2}, [a,d])
cons4 = Constraint.new(Proc.new{|var1,var2| var1 + 1 <= var2}, [c,e])
cons5 = Constraint.new(Proc.new{|var1,var2| var1 + 8 <= var2}, [d,e])
cons6 = Constraint.new(Proc.new{|var1,var2| var1 + 1 <= var2}, [c,f])
.......
# resource constraint
cons14 = Constraint.new(Proc.new{|var1,var2| (var1 + 2 <= var2) or
(var2 + 1 <= var1)}, [i,j])
cons15 = Constraint.new(Proc.new{|var1,var2| (var1 + 7 <= var2) or
(var2 + 8 <= var1)}, [a,d])
cons16 = Constraint.new(Proc.new{|var1,var2| (var1 + 7 <= var2) or
(var2 + 2 <= var1)}, [a,e])
cons17 = Constraint.new(Proc.new{|var1,var2| (var1 + 7 <= var2) or
(var2 + 3 <= var1)}, [a,h])
cons18 = Constraint.new(Proc.new{|var1,var2| (var1 + 8 <= var2) or
(var2 + 2 <= var1)}, [d,e])
cons19 = Constraint.new(Proc.new{|var1,var2| (var1 + 8 <= var2) or
(var2 + 3 <= var1)}, [d,h])
cons20 = Constraint.new(Proc.new{|var1,var2| (var1 + 2 <= var2) or
(var2 + 3 <= var1)}, [e,h])
But I don't know how to specify the domain. So I just sum the 10 jobs
duration and subtract it with the job duration to find the job
duration, like this:
a = Variable.new('a', (0..22).to_a)
b = Variable.new('b', (0..26).to_a)
c = Variable.new('c', (0..28).to_a)
d = Variable.new('d', (0..21).to_a)
e = Variable.new('e', (0..27).to_a)
.......
Yeah, my program solve it but with many many many solution, like this:
d => 7, g => 16, j => 22, b => 7, e => 15, h => 17, c => 10, f => 15, i
=> 20, a => 0,
d => 7, g => 16, j => 23, b => 7, e => 15, h => 17, c => 10, f => 15, i
=> 20, a => 0,
d => 7, g => 16, j => 24, b => 7, e => 15, h => 17, c => 10, f => 15, i
=> 20, a => 0,
d => 7, g => 16, j => 25, b => 7, e => 15, h => 17, c => 10, f => 15, i
=> 20, a => 0,
....... (almost unlimited)
I need to find the most optimal solution. Facing this condition (many
many solution), I can't find the most optimal solution by finding all
solution then find the smallest number in j (j is the last job) because
it takes forever. So I think I can take the first solution as the most
optimal solution because my code extract value from domain from the
smallest number. But with certain ordering of variables, I can find the
more optimal solution than the first one (d => 7, g => 16, j => 22, b
=> 7, e => 15, h => 17, c => 10, f => 15, i => 20, a => 0,):
solver.set_ordering([a,d,h,e,b,c,f,g,i,j]) find this solution:
a => 0, d => 7, g => 16, j => 20, b => 7, e => 18, h => 15, c => 10, f
=> 15, i => 18,
Okay, how do I find the most optimal solution from this csp problem? If
I have to find all solution first, how do I restrict the domain so it
does not take forever?
Thank you. This is the ruby code if any one of you interested:
http://personal.akbarhome.com/france/cons.tar.bz2
.
- Follow-Ups:
- Re: confuse to determine the domain of variables
- From: Libra
- Re: confuse to determine the domain of variables
- Prev by Date: Second Call For Papers - CPAIOR'07
- Next by Date: Re: confuse to determine the domain of variables
- Previous by thread: Second Call For Papers - CPAIOR'07
- Next by thread: Re: confuse to determine the domain of variables
- Index(es):