mathematical-optimization

What's the most efficient way to detect triangle-triangle intersections?

∥☆過路亽.° 提交于 2019-12-18 12:32:18
问题 How can I tell whether two triangles intersect in 2D Euclidean space? (i.e. classic 2D geometry) given the (X,Y) coordinates of each vertex in each triangle. 回答1: One way is to check if two sides of triangle A intersect with any side of triangle B, and then check all six possibilities of a point of A inside B or a point of B inside A. For a point inside a triangle see for example: Point in triangle test. When we test collisions on polygons we also have a surrounding rectangle for our polygons

What's the most efficient way to detect triangle-triangle intersections?

纵然是瞬间 提交于 2019-12-18 12:32:06
问题 How can I tell whether two triangles intersect in 2D Euclidean space? (i.e. classic 2D geometry) given the (X,Y) coordinates of each vertex in each triangle. 回答1: One way is to check if two sides of triangle A intersect with any side of triangle B, and then check all six possibilities of a point of A inside B or a point of B inside A. For a point inside a triangle see for example: Point in triangle test. When we test collisions on polygons we also have a surrounding rectangle for our polygons

Get constraints in matrix format from gurobipy

冷暖自知 提交于 2019-12-18 11:44:34
问题 I coded my model in gurobipy and I want to get the matrix of constraints and vector of cost. Is there any way to access those? 回答1: From the python API, there's no single function to get the matrix coefficients from a Gurobi model, but it's not to hard to write one yourself. It is convenient to have lists of your variables and constraints. If you have a gurobi model in variable m dvars = m.getVars() constrs = m.getConstrs() will give you the list of variables and constraints. You can then use

OpenCV, C++: Distance between two points

丶灬走出姿态 提交于 2019-12-18 10:29:17
问题 For a group project, we are attempting to make a game, where functions are executed whenever a player forms a set of specific hand gestures in front of a camera. To process the images, we are using Open-CV 2.3. During the image-processing we are trying to find the length between two points. We already know this can be done very easily with Pythagoras law, though it is known that Pythagoras law requires much computer power, and we wish to do this as low-resource as possible. We wish to know if

How to create an optimizer in Tensorflow

帅比萌擦擦* 提交于 2019-12-18 10:09:27
问题 I want to write a new optimization algorithm for my network on Tensorflow. I hope to implement the Levenberg Marquardt optimization algorithm, which now is excluded from TF API. I found poor documentation on how to write a custom optimizer, so i ask if someone can give my any advice. Thanks. 回答1: The simplest example of an optimizer is probably the gradient descent optimizer. It shows how one creates an instance of the basic optimizer class. The optimizer base class documentation explains

How to convert quadratic to linear program?

醉酒当歌 提交于 2019-12-18 02:46:40
问题 I have an optimization problem that has in the objective function 2 multiplied variables, making the model quadratic. I am currently using zimpl, to parse the model, and glpk to solve it. As they don't support quadratic programming, I would need to convert this to an MILP. . The first variable is real, in range [0, 1], the second one is real, from range 0 to inf. This one could without a problem be integer. The critical part in the objective function looks like this: max ... + var1 * var2 + .

Why can't I rig SciPy's constrained optimization for integer programming?

别说谁变了你拦得住时间么 提交于 2019-12-17 20:12:13
问题 I've read that integer programming is either very tricky or not possible with SciPy and that I probably need to use something like zibopt to do it in Python . But I really thought I could do it by creating one "is binary" constraint for each element in a vector being optimized by SciPy. To do that, I utilized the closure trick from http://docs.python-guide.org/en/latest/writing/gotchas/#late-binding-closures and created one constraint function for each element, like so: def get_binary

fastest way to determine if a bit is set in a integer data type

…衆ロ難τιáo~ 提交于 2019-12-17 19:58:02
问题 I have a method that computes a hash value as per some specific algorithm. uint8_t cal_hash(uint64_t _in_data) { uint8_t hash; // algorithm // bit at hash[0] = XOR of some specific bits in _in_data // repeat above statement for other indexed bits of hash return hash; } I want to know what could be the most efficient way to access and set corresponding bits in an integer datatype. I have already tried things like (((x) & (1<<(n)))?1:0) to determine if a bit is 1 or 0 at any index. Anything

Fit plane to a set of points in 3D: scipy.optimize.minimize vs scipy.linalg.lstsq

百般思念 提交于 2019-12-17 19:36:06
问题 Given a set of points in 3D, the general problem is to find the a, b, c coefficients of a plane equation in the form: z = a*x + b*y + c such that the resulting plane is the best fit possible to that set of points. In this SO answer, the function scipy.optimize.minimize is used to solve this problem. It relies on initial guesses for the coefficients, and minimizes an error function that sums the distances of each point to the surface of the plane. In this code (based on this other SO answer)

how to find global minimum in python optimization with bounds?

梦想的初衷 提交于 2019-12-17 15:37:52
问题 I have a Python function with 64 variables, and I tried to optimise it using L-BFGS-B method in the minimise function, however this method have quite a strong dependence on the initial guess, and failed to find the global minimum. But I liked its ability to set bounds for the variables. Is there a way/function to find the global minimum while having boundaries for the variables ? 回答1: This can be done with scipy.optimize.basinhopping . Basinhopping is a function designed to find the global