[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[SOLUTION] Constraint Processing (#70

email55555 email55555

3/16/2006 12:01:00 AM

Just finish my solution, I run out of time to provide an example ...
define the domain as instance variable.
define the rule by using block & instance variable.
define the solution block by using instance variable.
( all block will exec on "Engine"'s instance_eval )


class Engine

def go(&solution)
solve(instance_variables, &solution)
end

private
def method_missing(name, *args, &block)
if name.to_s =~ /=$/ && block.nil?
vars(name, *args)
elsif args.size == 0 && !block.nil?
rules(name, &block)
else
super
end
end

def rules(name, &block)
self.class.send(:define_method, name, &block)
self.class.send(:protected, name)
end

def vars(name, *args)
name = name.to_s.sub(/=$/, '')
self.class.class_eval("attr_accessor :#{name}")
args = args[0] if args.size == 1 && args[0].respond_to?(:each)
instance_variable_set("@#{name}", args)
end

def solve(vars, &solution)
if (vars.size != 0)
name = vars.shift
value = instance_variable_get(name)
value.each { |e|
instance_variable_set(name, e)
solve(vars.dup, &solution)
}
instance_variable_set(name, value)
else
protected_methods.each { |method|
return if !send(method)
}
instance_eval(&solution)
end
end

end

if __FILE__ == $0
e = Engine.new
e.a = 0..4
e.b = 0..4
e.c = 0..4
e.rule1 { @a < @b }
e.rule2 { @a + @b == @c }
e.go { puts "a => #@a, b => #@b, c => #@c" }
end


__END__

--
www.doublegifts.com


1 Answer

Ratu Adil , native Freedom Fighter against Dutch Baron de Kock of East Indies Army

9/4/2010 10:22:00 AM

0

jesus christ ,you have made a mistake

it was not 230 earth years


it is 230 million earth years for the Sun to circulate once
around the Galatic Centre





n Sep 3, 6:59 pm, "Jesus Christ , a long - term fucker of the
Prostitute St . Mary 's cunt hole , is an Unique Son of GOD"
<veak...@gmail.com> wrote:
> I  think  the earth ' s    Sun  takes  230  earth years  to
> circulate
>  one  whole  circle  around
> the  Galatic  Centre  of  this  Carbonit   Universe   Galaxy   .
>
> n Sep 2, 5:34 pm, charlie vietcong <vietcong.charlie...@gmail.com>
> wrote:
>
> > how  long  does  the  sun  take  to
> >   circulate  once  around    the  Galatic  Centre  , our  Galaxy  ?
>
> > On Sep 2, 10:12 pm, The Cynic <i.thecy...@gmail.com> wrote:
>
> > > So the myth of creation has once again been demolished!! LOL
>
> > >http://www.bbc.co.uk/news/u...
>
> > > 2 September 2010 Last updated at 08:18 GMT
>
> > > Stephen Hawking: God did not create Universe
> > > Stephen Hawking The Universe can create itself from nothing, says Prof
> > > Hawking
>
> > > There is no place for God in theories on the creation of the Universe,
> > > Professor Stephen Hawking has said.
>
> > > He had previously argued belief in a creator was not incompatible with
> > > science but in a new book, he concludes the Big Bang was an inevitable
> > > consequence of the laws of physics.
>
> > > The Grand Design, part serialised in the Times, says there is no need
> > > to invoke God to set the Universe going.
>
> > > "Spontaneous creation is the reason there is something," he concluded.
>
> > > 'Planetary conditions'
>
> > > In his new book, an extract of which appears in the Times, Britain's
> > > most famous physicist sets out to contest Sir Isaac Newton's belief
> > > that the universe must have been designed by God as it could not have
> > > sprung out of chaos.
>
> > > Citing the 1992 discovery of a planet orbiting a star other than our
> > > Sun, he said: "That makes the coincidences of our planetary conditions
> > > - the single Sun, the lucky combination of Earth-Sun distance and
> > > solar mass - far less remarkable, and far less compelling as evidence
> > > that the Earth was carefully designed just to please us human beings."
>
> > > He adds: "Because there is a law such as gravity, the universe can and
> > > will create itself from nothing.
>
> > > "Spontaneous creation is the reason there is something rather than
> > > nothing, why the universe exists, why we exist.
>
> > > "It is not necessary to invoke God to light the blue touch paper and
> > > set the universe going."
>
> > > The book was co-written by US physicist Leonard Mlodinow and is
> > > published on 9 September.
>
> > > In his 1988 bestseller, A Brief History of Time, Prof Hawking appeared
> > > to accept the role of God in the creation of the Universe.
>
> > > "If we discover a complete theory, it would be the ultimate triumph of
> > > human reason - for then we should know the mind of God," he said.