Here is another proposal. You'll find that this extends the system
dynamically, depending on new asset categories and, also, depending on the
kind of queries that are put to the system. (I'm assuming that combinations
of assets have to be queried, too.) To reduce the number of resulting
deftemplates and queries, the user interface should implement some way of
producing a canonical odering of the asser categories of a query (e.g.
Equipment < Software < Tool).
;; Keep track of existing rules.
;;
(deftemplate Rule (slot rulename))
;; Fact for triggering either a rule addition or the rule activation
;;
(deftemplate AddRule (slot rulename)(slot ruletext)(slot facttext))
;; We don't have this rule yet. Add it, and assert the fact that
;; might fire it.
;;
(defrule NoSuchRule
?ar <- (AddRule (rulename ?rulename)(ruletext ?ruletext))
(not (Rule (rulename ?rulename)))
=>
(retract ?ar)
(eval ?ruletext)
(assert (Rule (rulename ?rulename)))
(assert-string ?facttext)
)
;; We have the rule. Just assert the fact that might fire it.
;;
(defrule HaveRule
?ar <- (AddRule (rulename ?rulename)(facttext ?facttext))
(Rule (rulename ?rulename))
=>
(retract ?ar)
(assert-string ?facttext)
)
;; Template for System and the generic Asset.
;;
(deftemplate System (slot sysid) (slot cpu) (slot mem))
(deftemplate Asset (slot sysid) (slot value))
;; Some assets.
;;
(deftemplate Software extends Asset)
(deftemplate Equipment extends Asset)
;; some systems and assets
;;
(deffacts Systems
(System (sysid A)(cpu 300)(mem 1024))
(System (sysid B)(cpu 500)(mem 4096))
(System (sysid C)(cpu 600)(mem 512))
)
(deffacts Assets
(Software (sysid A)(value Jess))
(Software (sysid A)(value Java))
(Software (sysid A)(value Python))
(Software (sysid B)(value Perl))
(Software (sysid C)(value Java))
(Software (sysid C)(value Perl))
(Equipment (sysid A)(value Scanner))
(Equipment (sysid B)(value Plotter))
(Equipment (sysid C)(value Beamer))
)
;;
;; The dynamic extension capability
;;
;; suffix constructor
;;
(deffunction newMap ()
(return (new java.util.HashMap))
)
(deffunction getSuffix (?map ?str)
(bind ?count (?map get ?str))
(if (eq nil ?count)
then (?map put ?str 0) (return "")
else (++ ?count) (?map put ?str ?count) (return ?count))
)
;; add another asset
;;
(deffunction addAsset (?name)
(eval (str-cat "(deftemplate " ?name " extends Asset)"))
)
;; add an asset value for a system
;:
(deffunction addSysAsset (?asset ?sysid ?value)
(eval (str-cat "(assert (" ?asset " (sysid " ?sysid ")(value " ?value
")))"))
)
;; locate a suitable system
;:
(deffunction findSystem ($?args)
(bind ?map (newMap))
(bind ?rulename "Assets")
(bind ?bindlist "")
(bind ?textlist "")
(bind ?ces " ")
(bind ?facttext "")
(while (> (length$ ?args) 0)
(bind ?attr (nth$ 1 ?args))
(bind ?value (nth$ 2 ?args))
(bind ?args (subseq$ ?args 3 (length$ ?args)))
(bind ?attr1 (str-cat ?attr (getSuffix ?map ?attr)))
(bind ?rulename (str-cat ?rulename ?attr))
(bind ?bindlist (str-cat ?bindlist " ?" ?attr1))
(bind ?textlist (str-cat ?textlist "?" ?attr1 " \" \" " ))
(bind ?facttext (str-cat ?facttext " " ?value))
(bind ?ces (str-cat ?ces " (" ?attr "(sysid ?sysid)(value ?" ?attr "))"
))
)
(bind ?facttext (str-cat "(" ?rulename ?facttext ")"))
(bind ?ruletext
(str-cat "(defrule " ?rulename
" ?fx <- (" ?rulename ?bindlist ")"
?ces
" => (retract ?fx)"
"(printout t " ?textlist "\"on system \" ?sysid crlf))"))
;; assert the action trigger
(assert (AddRule (rulename ?rulename)
(ruletext ?ruletext)
(facttext ?facttext)))
(run)
)
(reset)
;; dynamic addition of an asset category and associations with systems
;;
(addAsset Tool)
(addSysAsset Tool A Unicorn)
(addSysAsset Tool B Gryphon)
(addSysAsset Tool C Snark)
;; queries for asset combinations
;;
(findSystem Software Python)
(findSystem Software Jess Tool Unicorn)
(findSystem Software Perl Software Java)
(findSystem Equipment Beamer Software Java Tool Snark)
On Nov 16, 2007 5:46 PM, Mohd. Noor <[EMAIL PROTECTED]> wrote:
> Thanks
>
> >Jess lets you define new rules, and remove old ones, while a system
> >is running, and facts (like the "property" facts) can come and go all
> >the time, as well.
>
> How about the template - can we redefine the template as well as update
> the existing one?
> Do we need install jess-engine in each broker? or it can be embedded with
> Java?
>
> cheers
>
>
>
>
> On Nov 16, 2007 3:40 PM, Ernest Friedman-Hill < [EMAIL PROTECTED]> wrote:
>
> > Hi,
> >
> > I'm not sure how this conversation drifted into a discussion of
> > *alternatives* to Jess; I don't see any problem with doing this
> > application in Jess itself.
> >
> > If you need to have properties like "service" come and go in a
> > running system, then the way to do that is the same way you'd do it
> > in any database-like system: make the property names into data. So,
> > for example
> >
> > (deftemplate computer (slot name))
> > (deftemplate property (slot computer) (slot name) (slot value))
> > (deftemplate user-wants (slot name) (slot value))
> >
> > (assert (computer (name A))
> > (property (computer A) (name RAM) (value 1GB))
> > (property (computer A) (name service) (value BLAST)))
> >
> > The rules look a little different, but not much
> >
> > (defrule find-something
> > (computer (name ?c))
> > (property (computer ?c) (name ?p) (value ?v))
> > (user-wants (name ?p) (value ?v))
> > =>
> > (printout t "Computer " ?c " fits the user criteria " ?p " = " ?
> > v crlf))
> >
> > Jess lets you define new rules, and remove old ones, while a system
> > is running, and facts (like the "property" facts) can come and go all
> > the time, as well.
> >
> > In a real system, you'd probably use multiple user-wants facts at a
> > time, and you could use the "forall" conditional element to match
> > computers which meet all of them.
> >
> >
> >
> > On Nov 16, 2007, at 2:54 AM, Mohd. Noor wrote:
> >
> > > let me extend my example
> > >
> > > say
> > >
> > > > Computer A:
> > > > CPu =100
> > > > RAM = 1GB
> > > > s/w = c++
> > > > Computer B:
> > > > CPU =20
> > > > RAM = 512M
> > > > S/w =spps
> > > > Computer C
> > > > CPU =12
> > > > RAM = 2GB
> > > > s/w = mathlab
> > > >>> service = bioInformatic service(BLAST) - this is a new
> > > service
> > >
> > > with refers to Computer C, it just introduced/published in the
> > > broker a new attribute/property namely service. I wonder how this
> > > infrormation being made available in Jess/JHCR/any other
> > > techniques on the fly- with that, the "user-wants" could be easily
> > > satisfied.
> > > in this case - user-wants might be "run my application with mathlab
> > > and use the BLAST tools" - which not priory available on the
> > > origional rules/facts declaration. My requirement is - my new
> > > rules/facts must be able be updated and evaluated of there is any
> > > request related at particular time.
> > >
> > > Any ideas/comments are very much welcome.
> > >
> > > mnoor
> > >
> > >
> > >
> > >
> > > On Nov 15, 2007 11:15 PM, Hal Hildebrand <[EMAIL PROTECTED]
> > > > wrote:
> > > The rules are compiled into classes, so yes, they are hard coded in
> > > that sense. But you can compile on the fly and create new systems
> > > of rules.
> > >
> > > However, the question comes down to what are the constraints you
> > > are trying to solve? Is it true that the constraints are changing
> > > and therefore you need to create a new system of constraints? Or
> > > is the data changing and the system remains unchanged. If you do
> > > have to change the constraint system/rules, then under what
> > > conditions? Are you changing the constraint system when you could
> > > be modeling this as data that the constraint system uses (thus
> > > eliminating the need to change the constraints)? If not, then how
> > > often does the constraint system change? For example, is it a time
> > > based policy, like 8am - 4pm, these constraint rules are used, but
> > > 5pm - 7am, we use a different set? If so, then the life cycle
> > > doesn't change - merely the equations/rules. You can therefore
> > > create a model where you can switch in the constraint system to
> > > satisfy.
> > >
> > > You can also use object oriented techniques with constraints
> > > ( http://tinyurl.com/2rfdck ). This would allow you to subclass,
> > > use polymorphism, etc, which may allow you to have an extensible
> > > system which doesn't require changing the constraints.
> > >
> > > There's a lot of modeling choices out there...
> > >
> > > On Nov 15, 2007, at 2:46 PM, Mohd. Noor wrote:
> > >
> > >> Yes, - I noticed that we have to consider the state of resource at
> > >> certain point of time.
> > >> I go through the examples of JCHR, it look like that we have to
> > >> hardcoded the rules. Am I right/wrong?.
> > >>
> > >> Cheers
> > >>
> > >>
> > >>
> > >> On Nov 15, 2007 7:35 PM, Hal Hildebrand
> > >> <[EMAIL PROTECTED]> wrote:
> > >> There's a life cycle involved, so you're never going to get a
> > >> system with continuously varying state (nor would you really want
> > >> to), thus it has to be sampled discretely. The result is a system
> > >> which triggers when the sampled values change. Some values, like
> > >> hardware configuration, will change slowly. Others, like CPU
> > >> load, I/O utilization, etc, will change faster. But regardless,
> > >> the essential life cycle remains the same:
> > >>
> > >> sample the data - event driven, perhaps
> > >> set up your equations - canned, template or rule driven
> > >> get your solutions - multiple solutions are possible
> > >> choose your solution - rule driven, perhaps
> > >> effect the system change based on the solution
> > >>
> > >> Rinse and repeat.
> > >>
> > >> On Nov 15, 2007, at 10:38 AM, Mohd. Noor wrote:
> > >>
> > >>> Dear All
> > >>>
> > >>> Thanks for the kind replies
> > >>> What I am concerned is, my rules is always dynamically changes
> > >>> over time(e.g. CPU availability/utilisation) -with that, I cannot
> > >>> hard coded on the programming coding.
> > >>> Even their template/"deftemplate" might be changes( e.g. new
> > >>> software properties/a totally new hardware-such as any new
> > >>> instrument attached to the computer system)
> > >>>
> > >>> Is that possible with JCHR?
> > >>>
> > >>> Any suggestions are welcome
> > >>>
> > >>> Cheers
> > >>> mnoor
> > >>>
> > >>>
> > >>> On Nov 15, 2007 5:09 PM, Hal Hildebrand
> > >>> <[EMAIL PROTECTED]> wrote:
> > >>> What you are describing is constraint programming. You can do
> > >>> this with Jess, but it's not exactly the best (imho) tool for the
> > >>> job due to what is involved. The combinatorics are nasty in all
> > >>> but the simplest examples.
> > >>>
> > >>> For a constraint solver that runs (with minor tweaks) in Jess,
> > >>> see http://tinyurl.com/yvz98m
> > >>>
> > >>> This technique might do what you want, but you might want to look
> > >>> into constraint systems in Java like JCHR or even Genetic
> > >>> Algorithms, which are particularly good at searching large sparse
> > >>> spaces for solutions to constraints.
> > >>>
> > >>> On Nov 15, 2007, at 8:45 AM, Mohd. Noor wrote:
> > >>>
> > >>>> let say the user want to select the computer (resources) in
> > >>>> which suite their requirement- in this case user wants to run
> > >>>> mathlab simulation in computer(clusters) that have more than 20
> > >>>> CPUs available. Let consider the attributes such as CPU and
> > >>>> software are treated differently(whereby we can migrate the
> > >>>> software and licenses to the node that most appropriate with
> > >>>> users' resources requirements- in this case;). This rules
> > >>>> (contains the node A, B and C's properties/attributes) suppose
> > >>>> made available in the brokerage level.
> > >>>>
> > >>>> In this case the user may select the mathlab from node C and run
> > >>>> on node B.
> > >>>>
> > >>>> How do we transform the resources properties into the rules?
> > >>>> How we are going to infer the rules?
> > >>>> How we can apply a forward chaining and backward chaining?
> > >>>>
> > >>>> Cheers,
> > >>>> mnoor
> > >>>>
> > >>>>
> > >>>>
> > >>>> On Nov 15, 2007 2:42 PM, Motaz K. Saad <[EMAIL PROTECTED]>
> > >>>> wrote:
> > >>>> Could you explain more!.
> > >>>> Do you want to make a rule to determine computer specifications
> > >>>> for a given software.?
> > >>>>
> > >>>>
> > >>>> On Nov 15, 2007 1:48 PM, Mohd. Noor < [EMAIL PROTECTED] > wrote:
> > >>>> dear jess
> > >>>> how to make a rule from this scenario
> > >>>>
> > >>>> Computer A:
> > >>>> CPu =100
> > >>>> RAM = 1GB
> > >>>> s/w = c++
> > >>>> Computer B:
> > >>>> CPU =20
> > >>>> RAM = 512M
> > >>>> S/w =spps
> > >>>> Computer C
> > >>>> CPU =12
> > >>>> RAM = 2GB
> > >>>> s/w = mathlab
> > >>>>
> > >>>> The user will request to run a software mathlab - how do the
> > >>>> rules look like
> > >>>>
> > >>>> cHEERS
> > >>>>
> > >>>> On Nov 15, 2007 11:44 AM, Mohd. Noor < [EMAIL PROTECTED]> wrote:
> > >>>> dear jess
> > >>>> how to make a rule from this scenario
> > >>>>
> > >>>> Computer A:
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>> --
> > >>>> Motaz K. Saad
> > >>>> Computer Science Dept.
> > >>>> College of IT
> > >>>> http://motaz.saad.googlepages.com
> > >>>>
> > >>>
> > >>>
> > >>
> > >>
> > >
> > >
> >
> > ---------------------------------------------------------
> > Ernest Friedman-Hill
> > Informatics & Decision Sciences Phone: (925) 294-2154
> > Sandia National Labs FAX: (925) 294-2234
> > PO Box 969, MS 9012 [EMAIL PROTECTED]
> > Livermore, CA 94550 http://www.jessrules.com
> >
> > --------------------------------------------------------------------
> > To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> > in the BODY of a message to [EMAIL PROTECTED], NOT to the list
> > (use your own address!) List problems? Notify
> > [EMAIL PROTECTED]
> > --------------------------------------------------------------------
> >
> >
>