, ,

[SOLVED] Jupyter notebook & use of libraries

$25

File Name: Jupyter_notebook_&_use_of_libraries.zip
File Size: 329.7 KB

5/5 - (1 vote)

Coursework: The Multi-Knapsack Problem

The assignment is worth 50 marks.

It has 3 parts, worth 10, 25 and 15 marks, respectively

The Multi-dimensional Knapsack problem

image The multi-dimensional knapsack problem is an optimisation problem where the goal is to maximise the total value or profit of a set of items.

image It can be seen as an extension of the single knapsack problem, but instead of having a single constraint (a single sack), we can have two or more constraints.

image It is better to think in terms of constraints or resources (rather than sacks) to understand this problem.

image The following data provides an instance of the multi-dimensional knapsack problem.

image n = number of possible items

image m = number of constraints

image A list of length n with the profits or values of each item

image A list of length m with the amounts of each constraint or resource image An n x m matrix with the “weight” or “use” of item i in constraint j

image In mathematical terms, the problem can be formulated as follows

Maximise sum of p(j)s(j) for j = 1,…,n

Subject to sum of r(i,j)s(j) <= b(i) for i=1,…,m and j = 1,…,n Where, s is a binary vector s(j)=0 or 1

p is the vector of profits

r is the matrix of resource coefficients (weights) b is the vector with resource capacities

Let us make this more concrete with an example.

Let us assume we have a pizza shop.

We have the recipes of n different pizzas that we can produce.

Each of the n pizzas has a value or profit, we can think of it as its selling price.

image But we have limited resources! In this case ingredients, so we cannot produce all the n pizza recipes.

image This means that we need to select a subset of the n pizza recipes that maximises our profit.

image Let us assume that for producing the pizzas we have m required ingredients (eg. flour, cheese, olives, ham, mushrooms, pineapple, etc), for each of them we have a fixed amount.

image Each of the n pizza recipes uses a certain amount of the m ingredients (note: it can be zero for some of them).

Our task is to select the subset of the n pizza recipes subject to the constraints imposed by the amounts of the m ingredients we have.

Datasets

You are given 2 datasets to support your work. A small instance to facilitate your work and debugging and a harder instance to challenge your algorithm. The naming convention indicates the number of items n and the number of constraints m:

image multi_knap_n28_m2.txt (https://canvas.stir.ac.uk/courses/13859/files/3303402?wrap =1) image (https://canvas.stir.ac.uk/courses/13859/files/3303402/download?download_frd=1)

image multi_knap_n200_m25.txt (https://canvas.stir.ac.uk/courses/13859/files/3303434?wrap =1) image (https://canvas.stir.ac.uk/courses/13859/files/3303434/download?download_frd=1)

The format of each file is as follows:

number of variables (n), number of constraints (m) the coefficients p(j); j=1,…,n

for each constraint i (i=1,…,m): the coefficients r(i,j); j=1,…,n the constraint right-hand sides, capacities or bounds b(i); i=1,…,m

Jupyter Notebook & Use of Libraries

To facilitate your work, you are given a Jupyter notebook: multi_knapsack.ipynb ( https://canvas.stir.ac.uk/courses/13859/files/3303401?wrap =1) image (https://canvas.stir.ac.uk/courses/13859/files/3303401/download?download_frd=1)

This notebook contains the code to read the data files. To read the files easily, place the notebook and the data files in the same folder.

You can use standard Python libraries such as matplotlib, math, random, and numpy.

You are not allowed to use libraries that implement metaheuristics, evolutionary or swarm- intelligence algorithms. You need to implement your method from scratch.

Part 1: Simple Hill-Climbing

Total: 10 marks

image Implement a fitness (evaluation) function. That is a function, that measures the quality of a solution.

image Implement a function that checks the validity of a solution.

image Using the functions above, implement a simple hill-climbing search method to solve this problem.

image Using the instance with n = 28 and m = 2, run experiments and report the results obtained using both numerical metrics and plots.

Part 2: Algorithm of Your Choice

Total: 25 marks

image Here you’re given the opportunity to design your own algorithm.

image The goal is to try to improve the performance of the simple hill-climbing method in Part 1.

image Can you design an algorithm that improves the performance (finds better solutions) than hill- climbing?

image To do so, you can either use some of the algorithm ideas discussed in the lectures and/or try your own ideas.

The marking on this part will be based on the following criteria

Design Effort and Algorithm Performance: A good algorithm requires design effort and produces good performance (finding good solutions in a reasonably short time).

Implementation Quality: The clarity, modularity and conciseness of your code.

Documentation: It is essential to document your design choices.

image You should provide in text form (using markdown cells in your notebook) brief descriptions of

image The type of algorithm

image The choice of search operator (s) or components you used, and their parameter values image Justify your choices when possible

Part 3: Performance Comparison

Total: 15 marks

Here you’re given the opportunity to perform a sound comparison of two versions of your algorithm.

By two versions, I do not mean two completely different algorithms!

For example, you can contrast two values of your algorithm hyper-parameters, or two different search operators.

Please note that

image The optimisation methods we have studied are stochastic, meaning that any performance comparison needs to consider several runs, at least 10 runs.

image In order to have a fair comparison between the two algorithm variants, we need to give them approximately the same computational effort (running time) to solve the problem.

image Base your comparison on the hardest instance. image To complete this part you should

image Report in text form (using markdown cells in your notebook).

image Briefly describe the two selected algorithm versions. image Justify your design of the two selected versions.

image What did you do to try to make the comparison fair?

image Report numerical values such as average and standard deviation. image Report plots with your comparative results.

Submission Guidelines

image Submit a single Jupyter document (.ipynb), clearly identifying each part using markdown cells. image Submit also an HTML version of your notebook to facilitate reading and initial inspection.

image Use code cells for your code and plots, and markdown cells for your text descriptions and justification of design choices.

Programming Assignment (https://canvas.stir.ac.uk/courses/13859/assignments/110645)

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] Jupyter notebook & use of libraries
$25