Question: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that

Given a set of items, each with a weight and a value, determine the number of each item to include in a
collection so that the total weight is less than or equal to a given limit and the total value is as large as
possible,
maximize X
i in I
cixi
subject to X
i in I
xiwi <= W, xi in {0,1}
1. Create an abstract base class which represents the above problem with solve as the pure
virtual function.
(5)
2. The abstract base class should contain the necessary members such as wi
, ci and xi
forall i in I, with generic type T.
(6)
3. Write functions in the abstract base class to add items to the problem, and set the value W.(2)
4. Write a function in the abstract base class to print the expanded problem in a linear
programming format, e.g.2x1+3x2+4x3<=40.
(3)
5. Write a function in the abstract base class to obtain and print the solution. (3)
Question 2/ Vraag 2
1. Create heuristic solver class that inherits the abstract base class created in Question 1.(3)
2. Override the solve() function and implement a greedy heuristic with priority queues for
the problem described in Question 1.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!