A ternary relation question

I have this model

 sig Factor {}
 sig Rule { rule : some Factor }
 sig RuleSet { rules : some Rule }
 sig EventRuleProperty {}
 
 sig Event {
       rulesets : some RuleSet,
       rule_properties :  rulesets -> Rule -> EventRuleProperty
}

How do I write a fact to restrict the rules in Event.rule_properties have to belong to Event.ruleset?
i tried to declare as

rule_properties :  rulesets -> rulesets.rules -> EventRuleProperty

got a syntax error

“Complex” constraints on fields cannot appear in type declarations, you must add a supplemental fact:

fact { all e: Event | e.rule_properties in e.rulesets -> e.rulesets.rules -> EventRuleProperty }
1 Like

this doesn’t quite do it. see below, RuleSet_1 has only 1 rule, but Event_0.rule_properties maps it to two rules. but your tip is helpful, i will play with it for a bit to fix the model. thanks!

RuleSet_0 { Rule_0, Rule_1 }
RuleSet_1 { Rule_1 }

Event_0 {
   rule_properties : { 
        RuleSet_1 -> Rule_0 -> EventRuleProperty, 
        RuleSet_1 -> Rule_1 -> EventRuleProperty, 
}

Well I addressed your syntax error issue. What do you want to specify exactly?

I got one instance, which isn’t correct, please see the screenshot.

sig Factor {}
 sig Rule { rule : some Factor }
 sig RuleSet { rules : some Rule }
 sig EventRuleProperty {}
 
 sig Event {
       rulesets : some RuleSet,
       rule_properties :  rulesets -> Rule -> one EventRuleProperty
}

fact {
    all e: Event | 
        e.rule_properties in e.rulesets -> e.rulesets.rules -> one EventRuleProperty 
}

I changed the fact, seems it fixed the issue

fact {
    all e : Event, rs : RuleSet, r : Rule {
        e.rule_properties in e.rulesets -> e.rulesets.rules -> one EventRuleProperty
        r !in rs.rules implies r !in e.rule_properties[rs].EventRuleProperty
   }
}