6.00 Pset 11 - Help with constraints? Hi all, I've been stuck for days on PS11. I have been building off the code presented in the lectures but am totally stuck when it comes to adding constraints. Can anyone help? I'm posting my code in a comment below.

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

6.00 Pset 11 - Help with constraints? Hi all, I've been stuck for days on PS11. I have been building off the code presented in the lectures but am totally stuck when it comes to adding constraints. Can anyone help? I'm posting my code in a comment below.

MIT 6.00 Intro Computer Science (OCW)
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

The code that I'm specifically referring to is a function I've named called "shortestPathWeightedConstraintsGabi". The previous three functions were iterations to get to this point.
Constraints: If you are doing a brute-force search, all you need to do is to check that a particular path satisfies \(both\) given constraints of total distance and outdoor distance. If you find one (feasible solution), then put it aside. If you find another feasible solution, compare with the previous and keep only the one with a lesser total distance. At the end of the search, the retained feasible solution will be the feasible path with minimum total distance as required.
Thanks - I think conceptually I understand it, I'm just having trouble with the implementation. Here's the code that (I thought) goes through that process: def shortestPathWeightedConstraintsGabi(graph, start, end, maxTotalDist, maxDistOutdoors, visited = []): start = Node(start) end = Node(end) if not (graph.hasNode(start) and graph.hasNode(end)): raise ValueError('Start or end not in graph.') path = [str(start)] if start == end: return path shortest = None for node in graph.childrenOf(start): if (str(node) not in visited): visited = visited + [str(node)] #new list newPath = shortestPathWeightedConstraintsGabi(graph, node, end, maxTotalDist, maxDistOutdoors, visited) if newPath == None: continue if (shortest == None or calcTotalDist(newPath, graph) < calcTotalDist(shortest, graph)): if calcTotalDist(newPath, graph) < maxTotalDist and calcDistOutdoors(newPath, graph) < maxDistOutdoors: shortest = newPath if shortest != None: path = path + shortest else: path = None return path I've tested my custom functions (calcTotalDist and calcDistOutdoors) and I know they return the correct integers. Is there something I'm missing/not seeing here?

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Here's a different implementation I've also been testing that breaks when I put in the constraints: def shortestPathWeightedConstraints2(graph, start, end, path, shortest, maxTotalDist, maxDistOutdoors): start = Node(start) end = Node(end) if not (graph.hasNode(start) and graph.hasNode(end)): raise ValueError('Start or end not in graph.') path = path + [str(start)] #print 'Current DFS path:', path #print 'Total Dist Outdoors:', calcDistOutdoors(path, graph) if start == end: return path #shortest = None for node in graph.childrenOf(start): if (str(node) not in path): newPath = shortestPathWeightedConstraints2(graph, node, end, path, shortest, maxTotalDist, maxDistOutdoors) if shortest == None or calcTotalDist(newPath, graph) < calcTotalDist(shortest,graph): if newPath != None: if calcTotalDist(newPath, graph) < maxTotalDist and calcDistOutdoors(newPath, graph) < maxDistOutdoors: print 'FOUND BETTER PATH' shortest = newPath return shortest

Not the answer you are looking for?

Search for more explanations.

Ask your own question