|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On December 31 2013 18:43 Blisse wrote: Also, I saw a place in my code where a function had 8 lines of code and I remembered the argument a couple pages back here. Haha. 8 lines being more or less than normal? I think the stricter lines per function rules really only apply to very high level languages.
|
On December 31 2013 18:13 darkness wrote:Show nested quote +On December 31 2013 08:38 Tobberoth wrote:On December 31 2013 08:06 Blisse wrote: No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns. The classic "You'll never use it" anti-pattern. Focusing so hard to programming paradigms and design patterns that you spend more time planning code than writing it and therefor never getting any benefit. Write code, refactor it later. Why lazy initialize something unless you know there's a definite benefit to doing so? I'm not sure how files are handled by OS especially when they're big. But if they take more memory because of their larger size, then I can see a benefit if lazy initialization is used in this case. That might very well be true. However, the point is that unless you know this ahead of time, it's wasted effort to implement it ahead of time. Better to not overthink it, and then profile it. If it turns out the initialization of files makes an impact you feel it worth getting rid of, there should be no problem implementing the lazy initialization later.
Optimization and refactoring is awesome, the problem is when you do it too early and it turns out you just wasted your time.
|
Make it work, then if and only if, it is needed, make it faster and the code prettier where needed.
|
Well the thing is lazy initialization is an optimisation. Writing lazy initialization before you know if you need it is pre-opimisation, its not really an issue of design patterns.
Part of learning a paradigm is to actually learn when they're actually useful, and part of learning paradigms in general is understanding when to use them and when not to, and being wary of overusing them, which is what he originally asked about.
Sorry I'm a bit confused, I don't think you can "over-use" a paradigm.
You must always use the paradigm if a language requires that you use that paradigm. For example if you are using Java, you should always use the Object Oriented Programming paradigm. In SQL you use declarative programming.
Maybe you are referring to edge cases where you can do declarative programming in say Javascript, but the over-arching paradigm you are using is functional programming. Overall "overusing" a paradigm is a good thing, if you decide to use a paradigm you should stick with it all the way, if you interchange between paradigms that is a very bad thing.
I'm not sure if saying "over-using a design pattern" is the right phrase here. I think you should always use design patterns, they are well tested and they are beneficial to the long-term maintenance of code.
Sometimes though you can over-engineer or use an incorrect design pattern to solve a problem.
For example in the last example, using lazy initialization is pointless because it doesn't actually solve any problems or speed up the program. 99.999% of the overhead is from the input stream, it is the payload that should be lazily loaded if performance was an issue.
|
On December 31 2013 18:43 Blisse wrote: On a side note, it is really weird to work coincidentally on 3 separate, dependant projects.
Project C (and in the future, D), are dependent on a common base B, which is dependent on another library, A, all of which I'm writing. Very strange. But it's entertaining being able to engineer all parts of the project and applying crazy design patterns all over the place because I'm bored. Seems rather normal to me. I have a solution that uses one project for the database layer, one for the views and viewmodels (likely going to further split that one), one for utility classes that are clarly independant of the solution, one for special data types (and no logic!) that I treat as "primitive types", accessible to the database, model and viewmodel layers, and currently two projects in the model layer.
Imo splitting layers into different projects makes it much easier to avoid unwanted dependencies. I would have to add a reference to another project/dll to access it, and at that point I would realize that something is not quite right.
|
On December 31 2013 21:23 Rollin wrote:Show nested quote +On December 31 2013 18:43 Blisse wrote: Also, I saw a place in my code where a function had 8 lines of code and I remembered the argument a couple pages back here. Haha. 8 lines being more or less than normal? I think the stricter lines per function rules really only apply to very high level languages.
I think people are still confused about this.
Basically if you follow the basic principles of functional decomposition, you will naturally end up with an average of 3-5 lines per method in lower level languages, and 1-3 lines in higher level languages. Although that was a ballpark figure that I originally came up with because I didn't think people would take it so seriously. Its basically what I end up with.
I never really look at a big method and go, oh hey that's a lot of lines better crunch it down. Its that big methods really never happen in the first place, because in my mind I'm only writing methods that are atomic.
So a good guideline would be certain amounts of lines per method would make sure you are doing things correctly, and if not, you are probably doing something wrong, or need improvement.
For example the TicTacToe project my first thought was.
Ok TicTacToe needs a Board, it needs Cells for the Board, so that's 2 classes. You have Games, which have 2 Players, so I also need a Game class and a Player class.
There's your object decomposition.
The next think I think about is the relationships. A Game has 2 players and a Board, each Board has X Cells. Which should be in your declarations and setup.
The next thing I think about is the states that each class have, and meaningful ways of setting them. I decide that because the players have markings, there's no need to set the Cell marking, setting the Player on the Cell would be better and makes it easier to check later down the track.
After that the implementation, its a turn based game. There should be a method to iterate through the players to give each player a turn, so make a method that just does that. Each player should then handle their own turn, like they do in real life, so each Player has an onTurn event where they can create their own abstractions for decision making such as for an AIPlayer.
So you have two methods, Game.turnSequence and Player.doTurn.
The Board also has the responsibility as the Umpire, but you could also have a RowSolver or Referee class. In TicTacToe the game ends when there is 3 in a row, doesn't matter which direction. So the RowSolver should just take a list of Rows, and check if any of them have 3 in a row. So what to do? Just create a solveRow method which checks for 3 in a row, you don't need any more than that, you create other methods to work with your solveRow method in order to check the Board state, for example getting every Row. I can't see how each of these functions should be longer than a certain amount of lines, the only reason they would be, is if you have a method performing the actions of what should be multiple methods. In which case you aren't doing functional decomposition properly.
|
I've been racking my brain over this problem for a few days now, and have been unable to come up with an optimal solution. So I'm hoping you guys can help me out.
Suppose I have a random assortment of items I want to produce in x number of production facilities. I want to write a program to find the distribution that best minimizes the total time it takes to produce the items. Here are the constraints:
- A facility can only produce one item at a time. My goal is to backlog all facilities with all the items in a way that takes the least amount of time as possible to produce the items. For example, if I have three facilities and six items to produce, given that everything else is equal, the optimal solution is to split it evenly with two items per facility. - Certain items take longer than others to be produced. So if I have one item that takes fifteen minutes, five items that take three minutes, and two facilities, the best solution is to put the fifteen minute item in one facility and all the other items in the other facility. - A facility must have slots available in order to produce or backlog an item, and certain items take more slots than others. Also, some facilities have more slots than others. - Some facilities can only produce certain items.
I've tried using a dynamic programming solution, but every approach I've made fails because of the circular dependency between large subsets and the smaller subsets they encompass. For example, if I have two items and two facilities, trying to solve a smaller subset (like one item and two facilities) is pointless without knowing where the other item will be.
I could easily brute force the solution, but if I have a few hundred items and several facilities, the number of combinations can grow exponentially too large. My goal is to write an efficient program to solve this as fast as possible.
Any help would be appreciated! I'm doing this in C#.net, but pseudo code I can understand.
|
Sounds very much like a variation of a well studied math problem... I can't quite put my finger on it, but I suppose factory/production/scheduling might be promising keywords when looking for an algorithm. Knapsack problem seems to be similar although not quite the same.
You definitely should try to find a proper algorithm for this kind of problem and adjust it for your needs or transform the problem to fit the algorithm.
|
On December 31 2013 23:17 sluggaslamoo wrote:Well the thing is lazy initialization is an optimisation. Writing lazy initialization before you know if you need it is pre-opimisation, its not really an issue of design patterns. Show nested quote +Part of learning a paradigm is to actually learn when they're actually useful, and part of learning paradigms in general is understanding when to use them and when not to, and being wary of overusing them, which is what he originally asked about. Sorry I'm a bit confused, I don't think you can "over-use" a paradigm. You must always use the paradigm if a language requires that you use that paradigm. For example if you are using Java, you should always use the Object Oriented Programming paradigm. In SQL you use declarative programming. Maybe you are referring to edge cases where you can do declarative programming in say Javascript, but the over-arching paradigm you are using is functional programming. Overall "overusing" a paradigm is a good thing, if you decide to use a paradigm you should stick with it all the way, if you interchange between paradigms that is a very bad thing. I'm not sure if saying "over-using a design pattern" is the right phrase here. I think you should always use design patterns, they are well tested and they are beneficial to the long-term maintenance of code. Sometimes though you can over-engineer or use an incorrect design pattern to solve a problem. For example in the last example, using lazy initialization is pointless because it doesn't actually solve any problems or speed up the program. 99.999% of the overhead is from the input stream, it is the payload that should be lazily loaded if performance was an issue.
I'm sorry, I didn't know there was a standardized definition for Programming Paradigms. In my mind, Programming Paradigm ~ Programming Pattern ~ Design Pattern.
I know the example was useless, I stated that in the example. I'm talking about a context in which you can see its usage, and I couldn't engineer the ideal example at 4am.
Applying lazy optimization is a pre-optimization, and it is also considered applying a design pattern. But in this case, he is specifically asking when he should be using lazy initialization and if there is a case of overuse, which seems much more like a design pattern question to me.
You can definitely overuse design patterns. Are you going to write factory methods to implement fizzbuzz? Over-engineering is nearly the same as over-using. If you overuse a design pattern you implement it more than it is necessary.
On December 31 2013 23:41 spinesheath wrote:Show nested quote +On December 31 2013 18:43 Blisse wrote: On a side note, it is really weird to work coincidentally on 3 separate, dependant projects.
Project C (and in the future, D), are dependent on a common base B, which is dependent on another library, A, all of which I'm writing. Very strange. But it's entertaining being able to engineer all parts of the project and applying crazy design patterns all over the place because I'm bored. Seems rather normal to me. I have a solution that uses one project for the database layer, one for the views and viewmodels (likely going to further split that one), one for utility classes that are clarly independant of the solution, one for special data types (and no logic!) that I treat as "primitive types", accessible to the database, model and viewmodel layers, and currently two projects in the model layer. Imo splitting layers into different projects makes it much easier to avoid unwanted dependencies. I would have to add a reference to another project/dll to access it, and at that point I would realize that something is not quite right.
Yeah, I can see where breaking the project apart helps a lot with dependencies. The first reason I made it into multiple projects is to avoid the dependencies and make the code a lot er.. less coupled I guess? Not sure if I can recall the correct term.
The only issue is that with this method of programming, I seem to be spending a lot a lot more time writing code and figuring out what's the cleanest way of writing the code and making it properly manageable. That's good and all, but it has that feeling where you're not as productive as you could be in terms of things done, even though the things you have done are pretty.
|
On January 01 2014 01:29 enigmaticcam wrote: I've been racking my brain over this problem for a few days now, and have been unable to come up with an optimal solution. So I'm hoping you guys can help me out.
Suppose I have a random assortment of items I want to produce in x number of production facilities. I want to write a program to find the distribution that best minimizes the total time it takes to produce the items. Here are the constraints:
- A facility can only produce one item at a time. My goal is to backlog all facilities with all the items in a way that takes the least amount of time as possible to produce the items. For example, if I have three facilities and six items to produce, given that everything else is equal, the optimal solution is to split it evenly with two items per facility. - Certain items take longer than others to be produced. So if I have one item that takes fifteen minutes, five items that take three minutes, and two facilities, the best solution is to put the fifteen minute item in one facility and all the other items in the other facility. - A facility must have slots available in order to produce or backlog an item, and certain items take more slots than others. Also, some facilities have more slots than others. - Some facilities can only produce certain items.
I've tried using a dynamic programming solution, but every approach I've made fails because of the circular dependency between large subsets and the smaller subsets they encompass. For example, if I have two items and two facilities, trying to solve a smaller subset (like one item and two facilities) is pointless without knowing where the other item will be.
I could easily brute force the solution, but if I have a few hundred items and several facilities, the number of combinations can grow exponentially too large. My goal is to write an efficient program to solve this as fast as possible.
Any help would be appreciated! I'm doing this in C#.net, but pseudo code I can understand. This problem is a perfect match for constraint programming, which is a framework for combination optimization and satisfaction and generally outperforms other techniques for such problems when it comes to scheduling. Constraint programs are also very easy to write, although you might have to read up on some theory if you've never used it before. In C++ I used a library called Gecode to model constraint programs, I dunno what's available in C#.
|
On January 01 2014 01:29 enigmaticcam wrote: I've been racking my brain over this problem for a few days now, and have been unable to come up with an optimal solution. So I'm hoping you guys can help me out.
Suppose I have a random assortment of items I want to produce in x number of production facilities. I want to write a program to find the distribution that best minimizes the total time it takes to produce the items. Here are the constraints:
- A facility can only produce one item at a time. My goal is to backlog all facilities with all the items in a way that takes the least amount of time as possible to produce the items. For example, if I have three facilities and six items to produce, given that everything else is equal, the optimal solution is to split it evenly with two items per facility. - Certain items take longer than others to be produced. So if I have one item that takes fifteen minutes, five items that take three minutes, and two facilities, the best solution is to put the fifteen minute item in one facility and all the other items in the other facility. - A facility must have slots available in order to produce or backlog an item, and certain items take more slots than others. Also, some facilities have more slots than others. - Some facilities can only produce certain items.
I've tried using a dynamic programming solution, but every approach I've made fails because of the circular dependency between large subsets and the smaller subsets they encompass. For example, if I have two items and two facilities, trying to solve a smaller subset (like one item and two facilities) is pointless without knowing where the other item will be.
I could easily brute force the solution, but if I have a few hundred items and several facilities, the number of combinations can grow exponentially too large. My goal is to write an efficient program to solve this as fast as possible.
Any help would be appreciated! I'm doing this in C#.net, but pseudo code I can understand.
Well my math sucks but one way I can think of off the top of my head is,
- Each item has a "difficulty". - Add one item to each facility, starting with highest to lowest. Loop through each item - Find the Facility with the smallest combined difficulty, and add the highest difficulty item to that.
e.g Item(difficulty) IA(1) IB(2) IC(3) ID(4)
2 Facilities
Start FA - ID FB - IC
1 Iteration FB - IC + IB FA - ID + IA
FB = 5 FA = 5
Any math wizzes please tell me if this can't work at all, would be keen to know. I believe there would be a few examples where it won't be perfect and won't find the complete optimal solution, but it should be super fast. For an extremely large collection the accuracy would increase though.
So if I have one item that takes fifteen minutes, five items that take three minutes, and two facilities, the best solution is to put the fifteen minute item in one facility and all the other items in the other facility.
So for the above example it would still work, by adding 5 to the second facility until it reached 15.
The requirements would just be a filter, you would do the same adding items only to where the facility meets the requirements. Same as slots and slots taken up, this can be done easily with OO.
Honestly I've given this about 10 seconds thought so let me know if I'm completely wrong.
|
On January 01 2014 02:05 ZerG~LegenD wrote:Show nested quote +On January 01 2014 01:29 enigmaticcam wrote: I've been racking my brain over this problem for a few days now, and have been unable to come up with an optimal solution. So I'm hoping you guys can help me out.
Suppose I have a random assortment of items I want to produce in x number of production facilities. I want to write a program to find the distribution that best minimizes the total time it takes to produce the items. Here are the constraints:
- A facility can only produce one item at a time. My goal is to backlog all facilities with all the items in a way that takes the least amount of time as possible to produce the items. For example, if I have three facilities and six items to produce, given that everything else is equal, the optimal solution is to split it evenly with two items per facility. - Certain items take longer than others to be produced. So if I have one item that takes fifteen minutes, five items that take three minutes, and two facilities, the best solution is to put the fifteen minute item in one facility and all the other items in the other facility. - A facility must have slots available in order to produce or backlog an item, and certain items take more slots than others. Also, some facilities have more slots than others. - Some facilities can only produce certain items.
I've tried using a dynamic programming solution, but every approach I've made fails because of the circular dependency between large subsets and the smaller subsets they encompass. For example, if I have two items and two facilities, trying to solve a smaller subset (like one item and two facilities) is pointless without knowing where the other item will be.
I could easily brute force the solution, but if I have a few hundred items and several facilities, the number of combinations can grow exponentially too large. My goal is to write an efficient program to solve this as fast as possible.
Any help would be appreciated! I'm doing this in C#.net, but pseudo code I can understand. This problem is a perfect match for constraint programming, which is a framework for combination optimization and satisfaction and generally outperforms other techniques for such problems when it comes to scheduling. Constraint programs are also very easy to write, although you might have to read up on some theory if you've never used it before. In C++ I used a library called Gecode to model constraint programs, I dunno what's available in C#. Taken any courses featuring Gecode?
|
On January 01 2014 02:05 ZerG~LegenD wrote:This problem is a perfect match for constraint programming, which is a framework for combination optimization and satisfaction and generally outperforms other techniques for such problems when it comes to scheduling. Constraint programs are also very easy to write, although you might have to read up on some theory if you've never used it before. In C++ I used a library called Gecode to model constraint programs, I dunno what's available in C#. I've near heard of constraint programming before, but after a little research it sounds like it might be what I'm looking for. I'll look into it more and see if I can work it out. Thanks!
On January 01 2014 02:13 sluggaslamoo wrote:Well my math sucks but one way I can think of off the top of my head is, - Each item has a "difficulty". - Add one item to each facility, starting with highest to lowest. Loop through each item - Find the Facility with the smallest combined difficulty, and add the highest difficulty item to that. e.g Item(difficulty) IA(1) IB(2) IC(3) ID(4) 2 Facilities Start FA - ID FB - IC 1 Iteration FB - IC + IB FA - ID + IA FB = 5 FA = 5 Any math wizzes please tell me if this can't work at all, would be keen to know. I believe there would be a few examples where it won't be perfect and won't find the complete optimal solution, but it should be super fast. For an extremely large collection the accuracy would increase though. Show nested quote +So if I have one item that takes fifteen minutes, five items that take three minutes, and two facilities, the best solution is to put the fifteen minute item in one facility and all the other items in the other facility. So for the above example it would still work, by adding 5 to the second facility until it reached 15. The requirements would just be a filter, you would do the same adding items only to where the facility meets the requirements. Same as slots and slots taken up, this can be done easily with OO. Honestly I've given this about 10 seconds thought so let me know if I'm completely wrong. I tried a similar approach, but with the additional constraint of a limited number of slots in a facility, I don't think this would always find the best solution. As an example, suppose I have two facilities: one with one slot, and the other with 15 slots. Now suppose I have sixteen items: one that uses one slot and takes 15 minutes, and all the rest use one slot and take 1 minute. Before I've made any iterative decisions, if I start off by putting the 15 minute item in the facility that has 15 slots, I've already lost.
I suppose I could build some intelligence on the initial placement at the start, but I'm wondering if I won't come upon the same issue while iterating. The constraints of the facilities (limited slots, limited item types) might change the solution rather than just be a deciding factor on whether I can put an item in it or not. That's why I thought a dynamic programming solution would be the key, but I haven't yet found a workable implementation.
|
On January 01 2014 02:13 sluggaslamoo wrote: The requirements would just be a filter, you would do the same adding items only to where the facility meets the requirements. Same as slots and slots taken up, this can be done easily with OO.
2 facilities (FA, FB). 2 items (1;2) with 10min. 5 items (3-7) with 4min but only facility FB. You would put item 1 on FA. Item 2 on FB. Then you would put 3-7 on FB. Resulting in FA = 10 and FB = 30. Ideal solution would be: 1 and 2 on FA. 3-7 on FB. Both would be 20min. The obvious solution would be to do the items which can only be done in specific facilities first.
But then imagine 3 Facilities (FC) and 2 products. Both identical except, one product can be done in FA and FB, the other in FB and FC. Assume 15 items of each product. You would take one product and end with FA = 8, FB = 7, FC = 0. Now you take the other product would fill up to FC = 7, and then end with FB = 11, FC = 11. The ideal solution though would be FA = 10, FB = 10, FC = 10.
This is even completely ignoring the slots problem.
I would look at constraints as well. Another question is, do you need the best solution or one which is just good enough? If good enough is ok, you might want to look at heuristics; genetic algorithms, (local) beam search, simulated annealing (hill climbing).
|
On January 01 2014 02:57 enigmaticcam wrote:Show nested quote +On January 01 2014 02:05 ZerG~LegenD wrote:This problem is a perfect match for constraint programming, which is a framework for combination optimization and satisfaction and generally outperforms other techniques for such problems when it comes to scheduling. Constraint programs are also very easy to write, although you might have to read up on some theory if you've never used it before. In C++ I used a library called Gecode to model constraint programs, I dunno what's available in C#. I've near heard of constraint programming before, but after a little research it sounds like it might be what I'm looking for. I'll look into it more and see if I can work it out. Thanks! Show nested quote +On January 01 2014 02:13 sluggaslamoo wrote:Well my math sucks but one way I can think of off the top of my head is, - Each item has a "difficulty". - Add one item to each facility, starting with highest to lowest. Loop through each item - Find the Facility with the smallest combined difficulty, and add the highest difficulty item to that. e.g Item(difficulty) IA(1) IB(2) IC(3) ID(4) 2 Facilities Start FA - ID FB - IC 1 Iteration FB - IC + IB FA - ID + IA FB = 5 FA = 5 Any math wizzes please tell me if this can't work at all, would be keen to know. I believe there would be a few examples where it won't be perfect and won't find the complete optimal solution, but it should be super fast. For an extremely large collection the accuracy would increase though. So if I have one item that takes fifteen minutes, five items that take three minutes, and two facilities, the best solution is to put the fifteen minute item in one facility and all the other items in the other facility. So for the above example it would still work, by adding 5 to the second facility until it reached 15. The requirements would just be a filter, you would do the same adding items only to where the facility meets the requirements. Same as slots and slots taken up, this can be done easily with OO. Honestly I've given this about 10 seconds thought so let me know if I'm completely wrong. I tried a similar approach, but with the additional constraint of a limited number of slots in a facility, I don't think this would always find the best solution. As an example, suppose I have two facilities: one with one slot, and the other with 15 slots. Now suppose I have sixteen items: one that uses one slot and takes 15 minutes, and all the rest use one slot and take 1 minute. Before I've made any iterative decisions, if I start off by putting the 15 minute item in the facility that has 15 slots, I've already lost. I suppose I could build some intelligence on the initial placement at the start, but I'm wondering if I won't come upon the same issue while iterating. The constraints of the facilities (limited slots, limited item types) might change the solution rather than just be a deciding factor on whether I can put an item in it or not. That's why I thought a dynamic programming solution would be the key, but I haven't yet found a workable implementation.
Ah I get it, that is a cool problem, keen to find out what the solution would be.
|
On January 01 2014 03:05 Zocat wrote:Show nested quote +On January 01 2014 02:13 sluggaslamoo wrote: The requirements would just be a filter, you would do the same adding items only to where the facility meets the requirements. Same as slots and slots taken up, this can be done easily with OO.
2 facilities (FA, FB). 2 items (1;2) with 10min. 5 items (3-7) with 4min but only facility FB. You would put item 1 on FA. Item 2 on FB. Then you would put 3-7 on FB. Resulting in FA = 10 and FB = 30. Ideal solution would be: 1 and 2 on FA. 3-7 on FB. Both would be 20min. The obvious solution would be to do the items which can only be done in specific facilities first. But then imagine 3 Facilities (FC) and 2 products. Both identical except, one product can be done in FA and FB, the other in FB and FC. Assume 15 items of each product. You would take one product and end with FA = 8, FB = 7, FC = 0. Now you take the other product would fill up to FC = 7, and then end with FB = 11, FC = 11. The ideal solution though would be FA = 10, FB = 10, FC = 10. This is even completely ignoring the slots problem. I would look at constraints as well. Another question is, do you need the best solution or one which is just good enough? If good enough is ok, you might want to look at heuristics; genetic algorithms, (local) beam search, simulated annealing (hill climbing).
Yep, it looks like heuristics might be the way to go. You might be able to convert Slots + Requirements + Difficulty into a heuristic and determine where to place items using that. You're right though in that it depends on whether you need 100% accuracy.
Not sure if genetic/annealing algorithms would help though as performance is an issue, although algorithmic problem solving in general isn't my forte so I wouldn't know .
|
On January 01 2014 03:05 Zocat wrote:Another question is, do you need the best solution or one which is just good enough? If good enough is ok, you might want to look at heuristics; genetic algorithms, (local) beam search, simulated annealing (hill climbing). Ideally, whatever solution would give me the least time as possible. There might be more than one solution, in which case I wouldn't care. I've heard of all those that you mentioned, but never dabbled into them. I'll do a little research on them and see if they might be what I'm looking for. Thanks
|
On January 01 2014 03:14 sluggaslamoo wrote:Not sure if genetic/annealing algorithms would help though as performance is an issue, although algorithmic problem solving in general isn't my forte so I wouldn't know  .
They are used, because they are performing better than brute force algorithms. Either because the search state (all possible solutions) is too large (memory limitation) or because it takes too long to calculate every possible solution (processing limitation). Many also offer a time limitation which basically is a "You have 5minutes - give me the best solution you can find by then". The downside though is that they dont guarantee to find the global optima. Depending on the starting states it`s possible to run into a local optima and never escape from it (though it`s unlikely, since you start from multiple points).
|
Happy New Year 
I've been reading about the Adapter pattern. However, I'm kind of pessimistic about this example:
http://www.tutorialspoint.com/design_pattern/adapter_pattern.htm
In particular, I think those overridden methods that "do nothing" are kind of out of place. Were they designed badly? If yes, how can the example be fixed?
Thanks.
|
I believe the idea of having the // do nothing functions in the AdvancedMediaPlayer were to demonstrate a class that had a completely different interface than the MediaPlayer class. This meant that you could not call the AdvancedMediaPlayer Play function in the same way that you called the MediaPlayer Play function.
With this in mind then, the implementation of the AdvancedMediaPlayer class is irrelevant to learning the adapter pattern. The only thing important would be that, there exists a class that adds functionality, but needs an Adapter class to bridge its broken ass interface to your own clean code.
So really, you can't really "fix" the example, as the poorly designed code is part of the point of the example, and to an extent, of the Adapter pattern.
|
|
|
|
|
|