PROLOG- Predicate that prevents doctor from having more than 8 appointments per day

Viewed 45

I'm writing a code in which I wanted to add a invariable that prevents doctors from having too many appointments.

appointement(IdAct, date(D,M,Y), IdPatient, Idinstitution, Iddoctor, Description, Cost).

So I would like something that can count how many appointments a doctor has per day and avoid insertion if it's more than 8.

I did something like

appointment(IdAct, date(D,M,Y), _, _, IdDoctor, _, _) ::
    soluctions( (IDdoctor),
                ( appointment(IdAct,date(D,M,Y), _, _, IdDoctor, _, _),
                  doctor(IdDoctor, _, _) ),
                X ),
    lenght (X, T),
    T =< 8.

I already have solutions and length described in the code above.

Running the code prevents me from adding any appointments at all.

Any solutions please?

0 Answers
Related