Program #1 Due March 11 The KNAPSACK problem is defined as follows: You are given a collection of N objects. Each object has a specified weight and a specified value. You are given a capacity, which is the maximum total weight you can carry, and a quota, which is the minimum total value that you want to get. The problem is to find a subset of the objects whose total weight is at most equal to the capacity and whose total value is at least equal to the quota. For example, suppose that you are given three objects: Object Weight Value and you are given a capacity of 110 and a quota of 90. Then a solution to the problem is the set (B C). Note that there is no solution involving object A, because once you have put A in the knapsack, there is no room for the other two. You are not allowed to choose a fraction of an object. Problem #1[20]: For your language of choice, devise data structures and functions for: a state, a node in the search tree, the initial state, a goal test function, and a function that expands the current node. Problem #2 [40]: Implement a program that solves the KNAPSACK problem using iterative deepening, a blind search method. Demonstrate it as described below. Problem #3 [40]: Choose an admissable heuristic and solve the same set of problems using an appropriate informed method. Please compare and briefly discuss the performance of this solution with the previous one (see the output we request below).
Input format The program should take its input from a file. The input file will contain a number of problems in sequence. Each problem has the following format. Each object will parse as a Lisp list, but I've put linefeeds and a comment delimiter in so that it shouldbe easy to parse in other languages.
For example, our example at the top would be:
You may assume that: There are at most 20 objects, a name is a single alphabetical character, and all quotas, capacities, weights, and values are integers. Output format The program should give its output in standard output. It should have the following form:
If no solution exists, then the output for the program should be just "No solution". For example, the output for the first problem above might be
Test file: A test file with 20 sample problems is HERE Program: You may write your program in Lisp, Scheme, C, or Java. If you want to use any other language, you must get the approval of the grader. The program should be well-structured and commented. The grader can take off up to 5 discretionary points for code that works but is not clearly structured. Deliverables: You should email to the grader:
|
|
![]() |
![]() |