1

In an assignment for uni , I've been asked to create a schedule for hypothetical backup represented by the predicate backup/5

  • The first argument is the server type with values : db , web
  • The second argument is the server name
  • the third argument represents the time the backup can start at
  • the fourth argument represents the duration of the backup
  • The fifth argument represents the bandwidth required for the backup

Constraints:

  • 2 instances of db or web back ups cannot be runniong at the same time(1 of each at the same time could be done).
  • Total bandwidth cannot be more than 25

What needs to be done is to write a predicate schedule_backups(Db_Starts,Web_Starts,ToalTime). libraries that can be used ic,ic_global,branch_and_bound,ic_edge_finder.

examples for backups :

backup(db,srv_d1,0,5,10).
backup(db,srv_d2,2,8,18).
backup(db,srv_d3,0,4,11).
backup(web,srv_w1,0,7,8).
backup(web,srv_w2,3,11,10).

The question is ... How do I get the bandwidth constraint on all the backups while having to constraint them seperatly for the start time constraint? I figured it out and have a working piece of code , but I do not think that it is the best way to do it. I will post it as the solution.

If anybody has something better as a suggestion feel free to post.

  • 1
    And your code is ? – CapelliC Jun 07 '20 at 18:14
  • Hello, your question does not contain any actual question. Where are you stuck? What have you tried? Try to formulate a concrete question you would like answered ("would you write my homework for me?" doesn't count :) ). See also some questions on [homework assignments](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions). – lambda.xy.x Jun 07 '20 at 18:46
  • Thanks for pointing that out , my brain was fried from prolog at the time I posted. I have actually completed the task I'll update question and post what I did. – DIMITRIOS LEONIDIS Jun 07 '20 at 19:04

1 Answers1

0
schedule_backups(DStarts,WStarts,Total):-
    findall(Server,backup(Server,_,_,_,_),Types),
    findall(PossibleStart,backup(db,_,PossilbleStart,_,_),Posiible_DB_Starts),
    findall(PossibleStart,backup(web,_,PossilbleStart,_,_),Possible_WEB_Starts),
    findall(Duration,backup(db,_,_,Duration,_),DB_Durations),
    findall(Duration,backup(web,_,_,Duration,_),WEB_Durations),
    findall(Bandwidth,backup(_,_,_,_,Bandwidth),Bandwidths),

    constraint_Starts_Ends(DBStarts,DbEnds,Possilble_DB_Starts,DB_Durations,-1),
    constraint_Starts_Ends(WEBStarts,WebEnds,Possilble_WEB_Starts,WEB_Durations,-1),
    append(DBStarts,WEBStarts,Starts),
    append(DbEnds,WebEnds,Ends),
    append(DB_Durations,WEB_Durations,Durations),

    cumulative(Starts, Durations,Bandwidths, 25),
    ic_global:maxlist(Ends,Total),
    bb_min(labeling(Starts),Total,bb_options{strategy:restart}),
    link(Types,Starts,WStarts,DStarts).



constraint_Starts_Ends([],[],[],[],_).
constraint_Starts_Ends([S|RestS],[E|RestE],[P|RestP],[Dur|RestDur],Prev):-
    S #:: 0..inf,
    S #>= P,
    S #>= Prev,
    E #:: 0..inf,
    E #= Dur + S,
    constraint_Starts_Ends(RestS,RestE,RestP,RestDur,E).

link([],[],[],[]).
link([T|TRest],[St|StRest],[WStarts|WRest],Db):-
    T == web,
    WStarts = St,
    link(TRest,StRest,WRest,Db).
link([T|TRest],[St|StRest],Wb,[D|DRest]):-
    T == db,
    D = St,
    link(TRest,StRest,Wb,DRest).