Question

Write a program in prolog to perform the critical path scheduling algorithm given the durations and...

Write a program in prolog to perform the critical path scheduling algorithm given the durations and prerequiests for each task.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Lists in Prolog or Lisp are quite different from arrays in other languages, because all the elements of an array have locations known in advance, and any element of an array can be reached as quickly as any other.

Prolog has no arrays, but it has two reasonable substitutes. Instead of using an array as a lookup table, you can use a set of facts, as in this table of prime numbers:

nthprime(1,2).

nthprime(2,3).

nthprime(3,5).

nthprime(4,7).

nthprime(5,11).

nthprime(6,13).

These table entries can be looked up very quickly. Of course it isn’t easy to add or change entries in this kind of table, though it’s perfectly possible. Another way to simulate an array is to use a functor with many arguments, and access the arguments individually using arg. For example, given the structure primes(2,3,5,7,9,11,13,17,19,23,29) you can pick out individual elements like this:

?- arg(1,primes(2,3,5,7,9,11,13,17,19,23,29),What). What = 2

?- arg(5,primes(2,3,5,7,9,11,13,17,19,23,29),What). What = 9

In effect, you are using the argument positions of a cons cell as if they were an array of pointers.

Add a comment
Know the answer?
Add Answer to:
Write a program in prolog to perform the critical path scheduling algorithm given the durations and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT