A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

ps8, dpAdvisor, bug Something is wrong with my code, but I can't figure it out. I'm having memo return a list that includes both the achieved value and a list (within the list) of indecies that were used. That's what I'm trying to do, anyway. The code always returns a list of courses that come in under the maximum hours, but the value isn't maximized. code here: http://codepad.org/hVjl1rkR

  • This Question is Closed
  1. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    this seems like a much harder approach rather than following the template from class. here's my approach: -extract a tuple of the keys from the subject_dict (I'm using the tuple as an index so I don't want it mutating) -using the keyTuple, create tuples of work and values. -then I can pass 'work' and 'values' to the fuction dpAdvisor in the same format as the program in class. then you just need to add 'i' as one of the returns from dpAdvisor did you have this working as a regular decision tree w/o the dynamic programming?

  2. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    what is the structure of the list that dpadvisorhelper returns?

  3. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    bwCA: should be [ value , [list of indicies] ] where indicies are the i values, if that makes sense valmont: no, i don't have it working as a regular decision tree. I'm not sure why I decided to do it this way, just seemed like I wouldn't have to make new tuples. If I do it your way, when you say I would just have to add the i values, do you mean a list of i values?

  4. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    bwCA: that's [ totalValue , [list of indicies] ] i hate that we can't edit posts

  5. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    "If I do it your way, when you say I would just have to add the i values, do you mean a list of i values?" yes. a list of the i value. same as what you're thinking with dpadvisorhelper.

  6. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    still not working. I think I'm doing something wrong after the else: with_i block code here: http://codepad.org/HPTXl7ND

  7. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm a lil strapped for time so quick question. did you have this working for small files without the dynamic programming? if not, that might be one way to attack the problem. Get the decision tree working without the dynamic programming first.

  8. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    btw, I forgot to ask. Do you want me to post functioning code?

  9. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    you might be right, try recursing (line 83) after you have taken the current i (lines 84-92) . you want to take it then recurse - at least that is what i did and your code structure looks similar to mine except for that

  10. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    valmont: yeah, shoot me some functioning code bwCA: I'm not sure what you mean. I'm not passing my list of indecies into dpAdvisorHelper and I don't have anything to add the current i to until I get values for with_i back from dpAdvisorHelper. Should I be passing in my list of i's?

  11. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    btw, I don't know if either of you have ran the code, but the problem is, at least in part, that total value just keeps going up and up and does not match the total value for the final list of indicies returned

  12. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    dang, got it to work. there was a problem with list assignment, i.e., I wasn't using [:] where I should have been. working code here: http://codepad.org/EqDMjqpf I kinda went crazy with the [:] -- probably don't need them all, but what can it hurt? valmont: I'd still like to see your code, if you don't mind

  13. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    here it is working without the work and value lists: http://codepad.org/SDl3q22n

  14. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    here http://codepad.org/OrmQVC24

  15. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    here's mine, i only kept track of the indices - http://dpaste.com/699640/ and another that uses a different algorithm = not recursive but apparently considered dp http://dpaste.com/699627/

  16. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @six3 i did some testing and yours is faster than mine. yours is linear with work and mine is more-than-linear (curves up) with work. with work = 200 yours is twice as fast. most of my excess is taken up by having to find the value of each branch with a seperate function because i didn't keep track of it.

  17. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.