You are on page 1of 2

MCP261 Exercise 2: due 11:59 PM on Sunday, January 23, on Moo-

dle
Total marks: 10

Submission Instructions
Submit the code on Moodle in a zip file. A submission link on Moodle will be
created shortly. The zip file must contain a single Python script (no Jupyter
notebooks). Your script must provide the answer to the question upon execu-
tion; therefore, ensure that output is presented in a readable format.

The script must be easy to read: all variables and key quantities of interest
must be clearly named, all computations must be commented, all assumptions
must be very clearly stated, and finally, you may even add a short (commented)
explanation of your approach to the problem at the beginning of the script.
File naming conventions: EntryNum Name Ex2.zip (with the script inside
named as EntryNum Name Ex2.py. Submissions that do not follow the
above convention will not under any circumstances be entertained.

1. (10 marks) Write Python code to implement the simplex method. You may
choose to implement the ”revised simplex” method (preferably as described in
the textbook Linear and Nonlinear Optimization by Griva, Nash and Sofer) or
the ”tableau method”. Either way, your code should take as input a linear
programming problem in standard form (min cT x s.t. Ax = b, x ≥ 0), and
provide as output the optimal solution. Your code should take as input (supplied
by the user) c, A and b. You can assume that all LP problems your code will
solve have m (assuming A is an mxn matrix) slack variables so that you have
an easy choice for the initial bf s. Your code should solve problems of size up to
n ≤ 6.

You do not have to check for unboundedness or degeneracy, but you will have to
check for multiple solutions (you do not have to identify all vertices associated
with the set of optimal solutions, just the first one you encounter will do, but
you will have to print a statement saying this LP has multiple solutions). If the
problem has multiple solutions, print ”This LP has multiple optimal solutions”;
else, print ”This LP has a unique optimal solution”.

Write the code such that the user can input c, A and b in Python list format (i.e.,
don’t prompt the user to enter these matrices elementwise). For example, c can
be input as a list of the form [c1 , c2 , ..., cn ] and A can be entered as a list of lists,
with each list representing a row (e.g., A = [[a11 , a12 , ..., a1n ], .., [am1 , .., amn ]]).
Note that we will evaluate each submission with a test problem entered in this
format - we will not modify our input format to suit your program, so ensure
that it follows this input format.

Important. Print the output in the following format.

1
Line 1: ”The optimal objective function value is <print value>”
Line 2: ”The optimal solution is <print list with n variable values>”
Example output for Line 2:
”The optimal solution is [1, 2, 3, 4, 5]”
Line 3: Statement as described above reg. multiple solutions.

We will penalize your submission heavily if the input and output formats are
not easily understandable.

You might also like