Fix.
This commit is contained in:
parent
08c4b1f790
commit
bb2797a8c2
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import collections
|
import collections
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
Point = collections.namedtuple("Point", "x y")
|
Point = collections.namedtuple("Point", ("x", "y"))
|
||||||
|
|
||||||
|
|
||||||
class Side(Enum):
|
class Side(Enum):
|
||||||
ON = auto()
|
ON = auto()
|
||||||
|
@ -14,13 +14,14 @@ class Side(Enum):
|
||||||
|
|
||||||
def sidedness(slope, intersection, p3, eps=0.0000001):
|
def sidedness(slope, intersection, p3, eps=0.0000001):
|
||||||
print(slope * p3[0] + intersection )
|
print(slope * p3[0] + intersection )
|
||||||
""" finds where a point is in regards to a line """
|
# finds where a point is in regards to a line
|
||||||
if p3[1] - eps <= slope * p3[0] + intersection <= p3[1] + eps or p3[0] - eps <= (p3[1] - intersection)/slope <= p3[0] + eps:
|
if p3[1] - eps <= slope * p3[0] + intersection <= p3[1] + eps or p3[0] - eps <= (p3[1] - intersection)/slope <= p3[0] + eps:
|
||||||
return Side.ON
|
return Side.ON
|
||||||
elif p3[1] > slope * p3[0] + intersection:
|
elif p3[1] > slope * p3[0] + intersection:
|
||||||
return Side.ABOVE
|
return Side.ABOVE
|
||||||
return Side.BELOW
|
return Side.BELOW
|
||||||
|
|
||||||
|
|
||||||
def diplay_prune_points(points, p1, p2):
|
def diplay_prune_points(points, p1, p2):
|
||||||
xs = [p[0] for p in points]
|
xs = [p[0] for p in points]
|
||||||
ys = [p[1] for p in points]
|
ys = [p[1] for p in points]
|
||||||
|
@ -90,7 +91,6 @@ def solve1D(points, xm, iteration_num):
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def findBridge(points, xm):
|
def findBridge(points, xm):
|
||||||
if xm > 0:
|
if xm > 0:
|
||||||
v = (-float('Inf'), -float('Inf'))
|
v = (-float('Inf'), -float('Inf'))
|
||||||
|
@ -190,5 +190,3 @@ res_ys = [p[1] for p in result]
|
||||||
plt.plot(res_xs, res_ys)
|
plt.plot(res_xs, res_ys)
|
||||||
plt.plot(xs, ys, 'ro')
|
plt.plot(xs, ys, 'ro')
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
56
h2/howto
Normal file
56
h2/howto
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
---- MbC ---
|
||||||
|
MbC(P: l, r): (finds UH of P from x-coordinates l to r)
|
||||||
|
Find median x-coordinate x_m
|
||||||
|
Partition points on x_m into Pl and Pr
|
||||||
|
Find bridge uv over x_m
|
||||||
|
Remove points below bridge
|
||||||
|
Recurse MbC(Pl: l, u.x) and MbC(Pr: v.x, r)
|
||||||
|
|
||||||
|
Find bridge is finding the line (y=ax+b) such that:
|
||||||
|
1) passes above all the points
|
||||||
|
2) has the lowest intersection point with the median line
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---- 1D ----
|
||||||
|
Unknown x1
|
||||||
|
Minimize c1*x1
|
||||||
|
such that
|
||||||
|
a1*x1 \leq b1
|
||||||
|
a2*x1 \leq b2
|
||||||
|
...
|
||||||
|
an*x1 \leq bn
|
||||||
|
|
||||||
|
for each of the constraints:
|
||||||
|
ai*x1 \leq bi
|
||||||
|
=>
|
||||||
|
if ai > 0: x1 <= bi/ai
|
||||||
|
if ai < 0: x1 >= bi/ai
|
||||||
|
if ai = 0:
|
||||||
|
if bi < 0: impossible
|
||||||
|
if bi \geq 0: always satisfied
|
||||||
|
|
||||||
|
this means that each constraint half of the real line
|
||||||
|
therefore run for-loop on bi/ai and check the ifs
|
||||||
|
|
||||||
|
|
||||||
|
when we have feasible region/interval:
|
||||||
|
if c1 > 0: choose minimum of interval
|
||||||
|
if c1 < 0: choose maximum of interval
|
||||||
|
if c1 = 0: degenerate
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---- 2D ----
|
||||||
|
a and b are unknowns
|
||||||
|
minimize ax_m + b
|
||||||
|
such that y_i \leq ax_i + b, for every input point (x_i, y_i)
|
||||||
|
where x_m is given (median)
|
||||||
|
|
||||||
|
Algorithm:
|
||||||
|
Initialise v
|
||||||
|
Randomly shuffle constraints
|
||||||
|
for i=1 to n:
|
||||||
|
if constraint i does not violate v, do nothing
|
||||||
|
else solve 1d LP on boundary of constraint i
|
||||||
|
|
Loading…
Reference in New Issue
Block a user