Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Branch and Bound
#5
(Jul-26-2018, 05:18 PM)ichabod801 Wrote: Permutations can be done with recursion:

def permutations(sequence, start = []):
    if not sequence:
        return [start]
    else:
        perms = []
        for item in sequence:
            new_sequence = sequence[:]
            new_sequence.remove(item)
            perms.extend(permutations(new_sequence, start + [item]))
        return perms
You just need to add code blocking certain combinations when you recurse.

Just got done looking up search tree's but they are Binary and what I am doing is not. It also requires understanding of linked lists which I did not, so I looked those up. That required understanding of classes which I do not have a super strong grasp on but I have been working on that this afternoon. It seems like a lot of stuff to learn just to do something simple. This answer above, about using recursion and limiting it, that sounds much more like what I want to do. I don't really know how to write it. Could you make me a short example to study? Say to generate a list of permutations of 'ABC' but anything with BC (in that order) is not allowed and not added to the list?
If that takes too long, can you point me to a article that talks about how to write something like this?
Reply


Messages In This Thread
Branch and Bound - by jarrod0987 - Jul-26-2018, 03:15 PM
RE: Branch and Bound - by ichabod801 - Jul-26-2018, 04:43 PM
RE: Branch and Bound - by jarrod0987 - Jul-26-2018, 04:57 PM
RE: Branch and Bound - by ichabod801 - Jul-26-2018, 05:18 PM
RE: Branch and Bound - by jarrod0987 - Jul-26-2018, 05:38 PM
RE: Branch and Bound - by ichabod801 - Jul-26-2018, 06:00 PM
RE: Branch and Bound - by jarrod0987 - Jul-26-2018, 06:38 PM
RE: Branch and Bound - by ichabod801 - Jul-26-2018, 06:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Confusion over an Except branch Mark17 1 484 Oct-13-2023, 07:45 PM
Last Post: deanhystad
  Program running on RPi 3b+ Very Strange Behavior - Out of Bound Index MadMacks 26 3,638 Mar-07-2023, 09:50 PM
Last Post: MadMacks
  Upper-Bound Exclusive Meaning Johnny1998 1 3,458 Aug-02-2019, 08:32 PM
Last Post: ichabod801
  Bound method Uchikago 1 2,209 Jul-26-2019, 04:43 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020