Генерация списка фиксированных значений в сплаве

Я пытаюсь создать список монет, обозначающих значение. Предположим, что 9 рупий будут содержать последовательность 5->2->2 . 8rs будет иметь 5rs->2rs->1rs. 7rs будет иметь 5->2 . Монеты могут быть типа 10 рупий, 5 рупий, 2 рупии, 1 рупия. Здесь в этом коде тенр подразумевает список монет номиналом десять, а тенр подразумевает монету достоинством в десять рупий. Как я могу создать такой список? Я пытался, но все напрасно. Также, когда я выполняю и нажимаю «Показать», он показывает несколько монет, назначенных одному узлу монеты. Любая помощь будет оценена. На самом деле я пытаюсь использовать его в торговом автомате. Я проверил ваш код и сейчас пытаюсь его реализовать. Я также предоставляю свой код для торгового автомата.

sig coin{}

sig oners,twors,fivers,tenrs,null1 in coin {}

sig list
{

next :  coin lone -> lone coin
}


sig oner,twor,threer,fourr,sixr,sevenr,eightr,niner,fiver,tenr,nullr in list {}

fact {
    //  all c:choco | all c1:choco -c | c1.choice != c.choice
    //  all m: machine| some n:m.null1 | some ors: m.oners| ors->n in (m.oner).next
    all  l:list| all c:coin| c->c not  in l.next
    all  l:list|no c : coin | (c in c.^(l.next ))
    //all m: machine| all o:m.oner | oners->null1 in o
   all o:oner| all n: null1|all l:list|oners->null1 in o.next and #n.(l.next)=0
            all n:nullr| all n1:null1| #n1.(n.next)= 1  and #(n.next).n1=0 and n1->null1 in n.next
    all t:tenr| all tr:tenrs | #tr.(t.next)= 1 and #(t.next).tr=0 and tr->null1 in t.next
all t:twor| all tr:twors | #tr.(t.next)= 1 and #(t.next).tr=0 and tr->null1 in t.next
}

Торговый автомат

sig button {}

sig coin{}

sig choco{
    value:one coin,
    choice :one button
            }
fact {
        all c:choco | all c1:choco -c | c1.choice != c.choice
        }
sig machine{
    a,b,c,d : one button,
    oners,twors,fivers ,tenrs,null1: set coin,
    cadbury, kitkat, eclairs , gum,null: lone choco
    }

{
  #(fivers+tenrs+null+twors+oners) = 5 
  #(a+b+c+d) = 4
    #   (cadbury+kitkat+ eclairs +gum) =4
    cadbury=choice.a
    cadbury= value.tenrs
        kitkat=choice.b
        kitkat=value.fivers
        eclairs=choice.c
        eclairs=value.oners
        gum=choice.d
            gum=value.twors
}

pred show{}

pred chocolate [before,after:machine , x: coin, op:choco, opc: coin, ip:button]
    {
    before.a=after.a
    before.b=after.b
    before.c=after.c
    before.d=after.d
    before.cadbury=after.cadbury
    before.kitkat=after.kitkat
    before.eclairs=after.eclairs
    before.gum=after.gum
    before.null1=after.null1
    before.oners=after.oners
    before.twors=after.twors
    before.fivers=after.fivers
    before.tenrs=after.tenrs
        before.null=after.null
    x = before.oners or x= before.twors or x= before.fivers or x= before.tenrs
    ip = before.a or ip = before.b or ip=before.c or ip = before.d 
    ip=before.a =>op=before.cadbury or op=none

        ip=before.b =>op=before.kitkat or op=none

    ip=before.c =>op=before.eclairs or op=none

    ip=before.d =>op=before.gum or op=none
    op=before.gum=>x=before.twors
    op=before.cadbury=>x=before.tenrs
    op=before.eclairs=>x=before.oners
    op=before.kitkat=>x=before.fivers
    (ip=before.c and x=before.oners =>op=after.eclairs and opc=after.null1)
    or   
    (ip=before.c and x=before.twors =>op=after.eclairs and opc=after.oners)
    or
        (ip=before.c and x=before.fivers =>op=after.eclairs and opc=after.twors)
    or
        (ip=before.c and x=before.tenrs =>op=after.eclairs and opc=after.fivers)
    or
    (ip=before.c and x=before.null1 =>op=after.null and opc=after.null1)
or
(ip=before.d and x=before.twors =>op=after.gum and opc=after.null1)
    or
(ip=before.d and x=before.oners =>op=after.null and opc=after.oners)
or
(ip=before.d and x=before.fivers =>op=after.gum and opc=after.twors)
or
(ip=before.d and x=before.tenrs =>op=after.gum and opc=after.fivers)
or
    (ip=before.d and x=before.null1 =>op=after.null and opc=after.null1)
or
(ip=before.b and x=before.fivers =>op=after.kitkat and opc=after.null1)   
    or
(ip=before.b and x=before.tenrs =>op=after.kitkat and opc=after.fivers)
or 
(ip=before.b and x=before.oners =>op=after.null and opc=after.oners)
or
(ip=before.b and x=before.twors =>op=after.null and opc=after.twors)
or
    (ip=before.b and x=before.null1 =>op=after.null and opc=after.null1)
or
    (ip=before.a and x=before.tenrs =>op=after.cadbury and opc=after.null1)
or
    (ip=before.a and x=before.fivers =>op=after.null and opc=after.fivers)
or
    (ip=before.a and x=before.twors =>op=after.null and opc=after.twors)
or
    (ip=before.a and x=before.null1 =>op=after.null and opc=after.null1)
}

run chocolate for exactly 2 machine, 8 button, 8 choco, 10 coin

person Akshay Hazari    schedule 24.04.2013    source источник


Ответы (1)


person    schedule
comment
Я создал машину, которой я хочу предоставить список монет в качестве входных данных. В настоящее время я пытаюсь проверить, могу ли я использовать это как вход. - person Akshay Hazari; 24.04.2013
comment
Спасибо . Я воспользовался вашим предложением использовать целые числа при реализации моего кода. - person Akshay Hazari; 26.04.2013