Answered step by step
Verified Expert Solution
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 xy of the Cartesian plane that satisfy the following inequalities
a r x a r b r y b 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 iex y and x y within these two squares iea b r and a b r respectively.
The quadratic programming formulation of this problem becomes
z xxyy x a r
x a r y b r y b r x a r x a r y b r y b r
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 ie a b and r in the first row and a b and r in the second row and it is composed of the following two lines for an example problem:
squares.txt
minimize subject to:
The quadratic programming model for the example problem can be written as minimize zxxxxxxyyyyyy
subject to:
xx
yy
xx
yy
The optimum solution of the example problem is as follows:
x y x
y
distance
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 distancebetweensquaressquaresfile:
# your implementation starts below
# your implementation ends above
returnxstar, ystar, xstar, ystar, distancestar
What to submit: You are provided with a template file named as hwipynb, where should be replaced with your 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 hwpy file that you will download from Azure Lab Services by following FileSave and Export Notebook AsExecutable 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started