I'm learning how to use intlinprog to solve a minimization problem. I have a series of paths that each connect two waypoints with distance values that need to be combined to minimize the overall distance of a route. 2 paths share a waypoint to make up a route. For example:
%distance for each path
p1 = 10;p2 = 5;p3 = 12;p4 = 8;%possible route combinations
routes = [p1 p2 0 0; p1 0 p3 0; p1 0 0 p4; 0 p2 p3 0; 0 p2 0 p4; 0 0 p3 p4];%distance for each route
distance = sum(routes,2);
From the above, it can be seen that p2 & p4 would result in the minimum distance combination (5 + 8 is the smallest distance). I could use a brute force for loop to find the minimum distance, but it's not scalable for larger numbers of paths per route. In an attempt to use intlinprog to find the best combination of paths, I'm not understanding what inputs I should use. Referring to the guidlines here, https://www.mathworks.com/help/optim/ug/intlinprog.html, I infer that:
f = ones(1,4);intcon = 4;A = [];b = [];Aeq = routes;Beq = distance;intlinprog(f, intcon, A, b, Aeq, Beq)
I expect this:
ans = [0; 1; 0; 1];
But get this:
ans = [1; 1; 1; 1];
I'm sure I'm missing something key here, but I don't know what. How do I get the first ans above?
Thanks in advance!
Best Answer