Implementing Interior Point [closed] - algorithm

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
Besides Boyd's Convex Programming book,
what's the best resource for:
analysis + practical implementation of interior point algorithms?

If you have Boyd's book, you know about CVXOPT. Look inside of it. If you are interested in implementation details, looking at an implementation is invaluable. As with most complex numerical algorithms, you are going to be much better off using previously written code than writing your own, but you probably know that. There are many other interior point implementations available online for linear programing, SOCP, quadratic programming, convex programming, etc. I have also used OOQP, and looked a bit at the insides. It seemed straightforward enough.
I also liked the first edition of Numerical Optimization. I had a good, fairly practical, overview of predictor-corrector methods in the second half. The second edition is no doubt of similar quality.

You can implement it in two ways:
If you have only one point, you'll get the area of the polygon, and then check if the sum of the area of the n triangles with a verticle in the point and the other two in two consecutively points is equal with the area of the polygon. If it's true, the point is inside, otherwise it's outside.
If you have many points (let's say M points) and you have to find if it's inside, you'll find a point inside the polygon, and split the polygon into n triangles, with a verticle in that point and the other two in two consecutively points on the polygon (that form an edge). You will have n lines, with a verticle in the point choosed before and a point in each point of the polygon. You'll sort them by the angle, clockwise. Then, you'll have M lines with a verticle in the point choosed and the other in one of the M points. You'll sort them like the first N. Then, you can find in o(N + M), for each point in the M, the nearest left and right line from the N (let's say the lines are CenterAx and CenterAy. Next, you'll have to find if the point it's in the triangle CenterAxAy. You can do it in o(1) checking if the are a of the triangle CenterAxAy is equal with area(CenterAxP) + area(CenterAyP) + area(AxAyP).
I hope you'll understand what i've written here.

Related

Is there a generalization of Voronoi Diagrams to curves in the plane? [closed]

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 months ago.
Improve this question
I've studied Voronoi Diagrams and Fortune's Algorithm before. What I'm curious about is if there's a generalization of Voronoi diagrams where instead of the input being a set of points, it is instead a set of non-intersecting curves in the plane, where we want to partition the plane into regions based off the Euclidean distance to the nearest curve.
Is this problem well defined and is there any known (hopefully efficient) algorithm to compute this generalization?
I've tried searching for an answer to this, but most resources seem to focus on curved metric spaces or curved regions rather than the input set itself being composed of non-points.
Edit:
If this isn't well defined for non-intersecting curves, will it work for line segments?
Yes, the Voronoi diagram is defined for arbitrary point sets and other distances than Euclidean. A quick web search gives you as many examples as you want. Intersecting curves are also possible.
The construction of the diagram for a set of line segments is well documented. The cells are bounded by line segments and parabolic arcs. If I am right, Fortune's algorithm generalizes to this case.
For general curves, the problem gets harder. In all cases, you need to derive the equation of bisector lines, and intersect them correctly to delimit the proper arcs at triple points.
A digitized version (on a raster grid) is easier and will work with any kind of shape. It is similar to the computation of a distance map, and can be performed in time linear in the number of pixels.

Does this algorithm work? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
The given problem is to find a way to efficiently return all boxes hit by a ray.
So I came up with an idea but I want to know your opinion before I waste time in programming something not working.
Basically, the idea is to have a grid of boxes with height = width, all of these boxes are the same size and they don't have a gap between each other, I also have a function to calculate the box index which belongs to a point.(in which box the point is)
Now I calculate a box around the grid and calculate the hit points of a ray with the edges.
So I know the intersection points and of course the direction of the rays, now I take the direction, normalize it and divide it by 2. ( I'm not really sure if I need /2 but I feel better with it)
The resulting vector is now my "step size". (I call this vector v)
So if I take now my first intersection point add v, calculate the box which belongs to the resulting point and does this again and again until I reach my second intersection point I shouldn't miss any box. (right?)
But I'm not sure about that so I ask for your opinion.
This algorithm does not work completely, because in any given square you can take a path through it (by cutting corners) that was a lower distance than whatever you put your step size as. This means that, no matter what you make your step size is, certain vectors will cause this function to omit blocks. That being said, if you use a smaller step size (say v=.05), this isn't a bad estimation algorithm (supposing the grid isn't too large).
Edit: Here is an algorithm that will work. Do the step size thing you are doing with step size < 1 (I think v = .9 should be fine), but after each step, check the relation of each box to the previous one. If you are in the same box or an adjacent box, do nothing. If you are in a diagonal box, you probably passed through an adjacent box to get there. Figure out if and which one it was, and also add it to your list.

What is the shortest path that touches every tile in a square grid? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Suppose a ant is placed on the position (0,0) of a chess-board. That ant wants to walk through every single tile of the board, while walking the least it can to do so. What path it must follow? Is there a formula F(i) that returns the position of the ith tile on that path?
Edit: as requested, I've tried the following:
I tried googling for keywords such as "shortest path", "shortest path in square grid", but couldn't find anything relevant.
I then downloaded, configured and used a Traveling Salesman Problem solver in a square grid. Obviously, the solution wasn't satisfactory, but I could gain an insight on the problem. There is an illustration of my results:
I then, intuitively, speculated wether the answer could be something like the Hilbert Curve: . I googled about it and asked on a IRC programming channel, but I couldn't find any actual evidence this is better than spirals and similars, nor a proof this is the best possible solution.
EDIT 2: Further clarifications:
The ant can move diagonally. The distance refers to the euclidean length of the line defined by the path.
Walk in straight line, with the edge of the board on your left, until you either hit the edge of the chess board or a tile you have visited before. If you do, then take a right.
Or a thousand other obvious patterns.
Any path that takes 63 steps is the minimum and just as good as any other path.
This is going to depend on if you're taking the width of each square into consideration or is this just a double array question?
If we're talking a double-array question f(x,y), then the answer is that there is no least path because the ant will need to travel to each square f(x,y) = x*y, so f(8,8) = 64.
If we start taking the width of the tiles themselves into consideration, then the answer is somewhat different because we can use some strategies to get the least amount of distance traveled (such as starting in the center, staying by the grid separators and walking in a roughly spiral pattern r=xy^(theta)).

Checking convexity from outside [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there any method or algorithm to determine convex (or non-convexity) property of a region from outside (perimeter) ?
One way is plotting tangent line in each point of perimeter and discuss how many times this line intersect the perimeter points. If no intersect shown (for all points of perimeter ) we can conclude region is convex. In otherwise region is non-convex.
Second way is determine interior angel of each point of perimeter and discuss if it's bigger than 180 or not. The region is non-convex if at least one point in perimeter exist it's interior angel bigger than 180.
Are there another simpler ways?
Any ideas or solution would be appreciated, thanks.
One thing to observe when doing this is that as you traverse the sides of a convex polygon, all the turns will be to the same side. That is, if you are traversing around the vertices in a counter-clockwise direction, all of the turns will be to the left; if you are traversing around the vertices in a clockwise direction, all of the turns will be to the right. If you ever observe a turn to the opposite side of any others observed, then you know you're dealing with a non-convex polygon. If all of the turns are to one side, then it is a convex polygon.
So, all you need to do is take look three vertices at a time, call them vn, vn+1 and vn+2. You can then determine which side of the line segment connecting vn and vn+2 the vertex vn+1 sits on. For CCW, vn+1 should be on the right of the line segment, and for CW it should be on the left. There is an answer to another question which provides a method for determining this.
There are additional implementation details you should work out (like how to deal with n=N, the number of points in your polygon, but this should provide you with a place to start.
An implementation based on this approach will run in O(N) time and space.
UPDATE: In response to the question below, "how about non-polygonal regions"? In general this is much harder. Mathematically, a region can be shown to be non-convex by finding a line segment with endpoints in the interior of the region but which has some portion of the line segment exterior to the region. I suspect you're looking for a way of implementing this using a digital computer, and so the pure mathematical approach is not practical.
So, you're going to have to offer some sort of constraints as to the types regions before the problem becomes intractable. That is, you have to constrain your problem space so that things like Nyquist sampling of the perimeter of the boundary do not incorrectly identify a non-convex region as being convex.
Assuming you can properly constrain the problem, any solution you can come up with, which can be implemented on a digital computer will have to approximate the region. You can either generate a piece-wise linear approximation of the region in question and run the algorithm above, or pick the proper set of points along the boundary of the region and calculate their derivative. Each successive sample should rotate the angle of the tangent line by some increment in the same direction. But again, it gets downs to sampling.
If you have other information about the nature of any nonlinearities which comprise the boundary of your region, you may be able to symbolically demonstrate whether a segment of the boundary is convex. The problem then reduces to showing that it remains convex when joined to the adjacent sections, which again is going to be problem specific.
So, my suggestion is, for digital computer implementation, approximate as needed the boundary of the region by a polygon and run the method defined above on that approximation.
An algorithm I've used (in pseudo code):
function isConvex(vertices[Count] V):
convex = true
if Count <= 3 return convex
for N = 0 to Count while convex:
// line segment between previous and subsequent vertices
LineSegment segment1 = new LineSegment(
V[(N + Count - 1) % Count], V[(N + 1) % Count]);
// line segment between the point and any other point
LineSegment segment2 = new LineSegment((V[N], V[N+2 % Count]);
if not segment1.intersects(segment2) then convex = false;
return convex
I don't know if this is optimal or simpler than the algorithms you've already tried.
The LineSegment.intersects() method already existed making this really easy to write.
The actual code used segment2 from the previous iteration as segment 1 of the current iteration making it faster but more complex to write even in pseudo code.
And also, for what it's worth, the original of this algorithm was written in assembly language on a processor that no longer exists, so I won't be providing actual code ;-).

Weiszfeld algo for "highway" distance? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
The problem is to find the point minimizing the travel distance for around 100 persons in different regions who want to meet in the same place. Travel is by car not by plane.
Assuming that I get access to an API giving me mileage / kilometric distance in terms of highway travel between any two points, how can I find the best place to meet?
On other Stackexchange sites (gis.stackexchange.com/questions/65563/meeting-point-minimizing-travel-distance-for-participants) I got directed to the Weiszfeld algo to solve this problem of geometric median.
I suspect that kilometric distance complexifies the problem, because it becomes possible to get stuck in local minima. I don't know really where to start. Any pointer would be appreciated.
Even though it may suffer from local minima, I would try local search, since road networks aren't adversarially designed. Pick a random starting point and then iterate as follows. Compute directions from the current point to the 100 clients. Evaluate each of the next-to-last stops in the directions and move the point to the best.
If the distances taken into account are Manhattan distances then the optimal meeting point is one of the points which has a x-coordinate equal to the x-coordinate of some input point, and the y-coordinate equal to the y-coordinate of some input point.

Resources