Extending the purpose of a Prolog through recursion?

I have implemented (finally) several goals that plan to complete a series of tasks according to startBy startAfter and duration. However, the goal of the schedule accepts only a given number of tasks. I would like to extend the functionality of the schedule goal to accept a single list and iterate over this list during planning.

Unfortunately, I think that this will require completely different goals than those that can be fulfilled, and the conflicts shown below.

UPDATE: now we are getting closer ... can_run / 3 returns true if any of the RT, TT pairs does not conflict ... which is clearly not what I want, but I'm close ... if anyone can tell me how to avoid it (perhaps with the help of the operator!)? That would be nice.

UPDATE: Eet werkz! Now, to clean up excessive imperfect solutions (not planning a task) and permutations of a solution (a, b, c and a, c, b and b, a, c and b, c, a, etc.)

UPDATE: Bah .. okay, so it really doesn't work ... for something for 1 ... mutter mutter. Also ... it looks like it can be quite intensive processing.

UPDATE (final): it worked and implemented the “smallest window first” heuristic to improve processing time ... there are still problems returning false for schedules that cannot be resolved, but finding a solution is pretty fast.

Here is what I still have:

can_run(R,T) :- startAfter(R,TA),startBy(R,TB),between(TA,TB,T). conflicts(R,T,RTs) :- duration(R,D),member([RT,TT],RTs),R=\=RT,duration(RT,DT),T<DT+TT,T+D>TT. schedule :- findall(R,request(R),Rs),predsort(windowCompare,Rs,Rtn),schedule(Rtn,[]). windowCompare(D,R1,R2) :- startAfter(R1,SA1),startBy(R1,SB1),W1=SB1-SA1, startAfter(R2,SA2),startBy(R2,SB2),W2=SB2-SA2, W1>W2->D='>';D='<'. schedule(Rs,RTs) :- Rs==[]; ( member(R,Rs),select(R,Rs,Rst), can_run(R,T),\+conflicts(R,T,RTs), append(RTs,[[R,T]],RTN),schedule(Rst,RTN), writef('%t @ %t\n',[R,T]) ). request(1). request(2). request(3). request(4). request(5). request(6). request(7). request(8). request(9). startAfter(1,0). startAfter(2,0). startAfter(3,0). startAfter(4,0). startAfter(5,0). startAfter(6,0). startAfter(7,0). startAfter(8,0). startAfter(9,0). startBy(1,20). startBy(2,40). startBy(3,15). startBy(4,5). startBy(5,0). startBy(6,35). startBy(7,30). startBy(8,10). startBy(9,25). duration(1,5). duration(2,5). duration(3,5). duration(4,5). duration(5,5). duration(6,5). duration(7,5). duration(8,5). duration(9,5). 

I think I might need to maintain a constant structure that each iteration updates ...

+4
source share
1 answer

If you want can_run (R, T, Rts) to fail, if ANY of the pairs in the list conflict, then the final sentence in your predicate should be

 \+ (member([RT,TT], RTs), conflicts(T, RT,TT)) 

I am not familiar with the predicate between 3, but it is important that the effect of the solution between (TA, TB, T) is to associate T with the main value before calling + (...)

+2
source

Source: https://habr.com/ru/post/1299666/


All Articles