Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this homework, you will implement a Python script that finds the distance between two squares using CPLEX. In analytic geometry, a square is defined

In this homework, you will implement a Python script that finds the distance between two squares using CPLEX. In analytic geometry, a square is defined as the set of points (x,y) of the Cartesian plane that satisfy the following inequalities
a 12 r <= x <= a +12 r b 12 r <= y <= b +12 r
where (a, b) is the center of the square and r is the side length. The Euclidean distance between two squares is the minimum distance between two points (i.e.,(x1, y1) and (x2, y2)) within these two squares (i.e.,(a1, b1, r1) and (a2, b2, r2)), respectively.
The quadratic programming formulation of this problem becomes
z =(x1x2)2+(y1y2)2 x 1>= a 121 r 1
x 1<= a 1+12 r 1 y 1>= b 112 r 1 y 1<= b 1+12 r 1 x 2>= a 212 r 2 x 2<= a 2+12 r 2 y 2>= b 212 r 2 y 2<= b 2+12 r 2.
After solving the optimization problem, z will give the Euclidean distance between the two squares.
This problem will be represented using a .txt file, namely, squares.txt. This file contains the parameters of two squares in two rows (i.e., a1, b1 and r1 in the first row and a2, b2 and r2 in the second row), and it is composed of the following two lines for an example problem:
squares.txt
-------------
4.06.04.0
11.012.02.0
minimize subject to:
1
The quadratic programming model for the example problem can be written as minimize z=x21x1x2x2x1+x2+y12y1y2y2y1+y2
subject to:
+ x1+x1
+y1+y1
+x2+x2
+ y2+y2
>=2<=6>=4<=8>=10<=12>=11<=13.
The optimum solution of the example problem is as follows:
x1=5.999999995573339, y1=7.999999994097785, x2=10.0,
y2=11.0,
distance=5.000000007082659.
Implement your algorithm to find the distance between two squares in a single interactive Python notebook using Azure Lab Services. Your notebook should include at least the following function definition that takes the file path of the input file as parameter and returns the solution found.
def distance_between_squares(squares_file):
# your implementation starts below
# your implementation ends above
return(x1_star, y1_star, x2_star, y2_star, distance_star)
What to submit: You are provided with a template file named as 0099999 hw04.ipynb, where 99999 should be replaced with your 5-digit student number. You are allowed to change the template file between the following lines.
# your implementation starts below
# your implementation ends above
You need to submit your source code in a single file (0099999 hw04.py file that you will download from Azure Lab Services by following File/Save and Export Notebook As.../Executable Script menu items).
How to submit: Submit the file you edited to Blackboard by following the exact style mentioned. Submissions that do not follow these guidelines will not be graded.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Explain the importance of intersectionality in sampling.

Answered: 1 week ago