Fork me on GitHub
#off-topic
<
2019-07-01
>
Drew Verlee03:07:54

does the term "optimality" have a specific meaning in the field of discrete optimization? e.g dynamic programming proved optimality for the knapsack problem.

andy.fingerhut04:07:08

One use of the word optimality for such problems is: is a particular algorithm guaranteed to return an optimal solution to the problem? Or does it sometimes return a best solution, but other times return a feasible solution that might be worse?

andy.fingerhut04:07:14

For some problems, like shortest path through a graph of nodes and edges, there are well-known algorithms that are both provably fast (e.g. run time is order of (# edges) * (log(# of nodes)) in the worst case) and guaranteed to find an optimal solution, i.e. a path that is shortest among all possible.

Drew Verlee17:07:18

so optimal means correct? if the requirement is to find the shortest path, then anything that isn't the shortest past would be incorrect.

andy.fingerhut17:07:14

If the requirement is to find the shortest path, then only a shortest path is correct.

andy.fingerhut17:07:45

If the goal is "find a 'good enough' path, hopefully short" then an algorithm that, say, returns a path guaranteed to be at most twice as long as the shortest path, might be good enough, for your purposes.

andy.fingerhut17:07:33

There are many computationally hard optimization problems where people have figured out how to write a fast algorithm that is guaranteed to return a solution that is "at most A times worse than the best", but no one has figured out a fast algorithm with A=1.

Drew Verlee17:07:22

i think i understand. I was working through a problem on a discrete optimization class and they required you mark if your algorithm proved optimal. I looked at some existing solutions and people just hard coded this flag . in the lectures they talk around it but never specifically define it. At one point they say DP is optimal for knapsack, but then later say it depends on the input. I'm going to hardcode it as well, as it seem to be a bit of a distraction.

andy.fingerhut18:07:15

knapsack is one of those hard computational problems where, for the general problem with arbitrarily large pieces sizes, there is no known "fast" (i.e. guaranteed worst case polynomial run time in the size of the input). If the piece sizes are limited to be small, then there are.

andy.fingerhut18:07:25

You should probably ask the professor/TA to be sure what they mean, but my guess is when they say "mark if your algorithm proved optimal", they mean "tell us if the program you wrote implements an algorithm that is guaranteed to return a best possible solution". There are certainly algorithms for the problem that are guaranteed to return a solution, but not necessarily a best one.

andy.fingerhut18:07:31

There are algorithms that are not guaranteed to return a best solution, but they might still for some inputs return a solution that is a best one. Whether or not it is easy to determine that a particular solution is a best one or not, depends a lot upon the problem.

Drew Verlee18:07:48

Thanks Andy, i did ask on the class forums. I know i'm constant with other solutions so far and maybe specifics are made clear later. 🙂

andy.fingerhut04:07:54

There are a bunch of problems where the best known algorithms fall into a spectrum where you have to choose between fast run times, or guaranteed optimal solutions.

andy.fingerhut04:07:30

Not sure if that addresses your question, exactly.

Drew Verlee18:07:21

----- warning type stuff ------------- Is there a better place for type specific discussions then off-topic? Tim's old gist on "what he wants from a Type System" is currently trending on HN https://news.ycombinator.com/item?id=20322704. Most likely because of the recent attention it got on here and the Future of Coding slack channel (just a guess though). Some quick thoughts about the discussions i see so far. I think the top comment by UFO is informative. It's possible the type error problem of type A != type B could be made more clear by giving that information in realtime to the developer and letting them assign blame. Some reference to a library called Hlist which quickly leads me down a rabbit hole. Yogthos tries to motivate a defence for building a scope in which its ok to not prove things for the sake of conciseness. I find it interesting that a lot of the more advanced uses of Types to augment the developer experience seem to reach all the way to the run time and interact with the user as they build the program. Hazel and Lamdu are two examples i'm aware of. This approach seems to bridge the gap for me and doesn't seem dis similar to how and why i enjoy using clojure.