Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Python
  4. Python Code Heuristic Algorithm

Python Code Heuristic Algorithm

Scheduled Pinned Locked Moved Python
pythonalgorithmsdata-structureshelpquestion
2 Posts 2 Posters 33 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_15814673
    wrote on last edited by
    #1

    Me enviaron hacer que el algorimo heruistico que esta de forma lineal sea dinamico, osea que el cambio de posicion lo genere de forma dinamica mediante el ingreso del tamaño del array, pero no me sale me podrian ayudar??? solo he logrado que imprima el array pero no me sale el cambio de posicion

    Google translate:

    They sent me to make the heruistic algorithm that is linearly dynamic, that is, the change of position is generated dynamically by entering the size of the array, but it doesn't work out, could you help me??? I have only managed to print the array but I do not get the change of position

    # Puzle Lineal con heurística
    from re import I
    from ClaseNodo import Nodo
    def buscar_solucion_heuristica(nodo_inicial, solucion, visitados):
    visitados.append(nodo_inicial.get_datos())
    if nodo_inicial.get_datos() == solucion:
    return nodo_inicial
    else:
    # expandir nodos sucesores (hijos)
    dato_nodo = nodo_inicial.get_datos()
    i=0
    while i < tamaño :
    hijo=[]
    hijo.append(dato_nodo)
    i=i+1
    hijo=[dato_nodo[1], dato_nodo[0], dato_nodo[2], dato_nodo[3], dato_nodo[4], dato_nodo[5]]
    hijo_izquierdo = Nodo(hijo)
    hijo=[dato_nodo[1], dato_nodo[0], dato_nodo[3], dato_nodo[2], dato_nodo[4], dato_nodo[5]]
    hijo_central = Nodo(hijo)
    hijo=[dato_nodo[1], dato_nodo[0], dato_nodo[3], dato_nodo[2], dato_nodo[5], dato_nodo[4]]
    hijo_derecho = Nodo(hijo)
    nodo_inicial.set_hijos([hijo_izquierdo, hijo_central, hijo_derecho])
    for nodo_hijo in nodo_inicial.get_hijos():
    if not nodo_hijo.get_datos() in visitados and mejora(nodo_inicial, nodo_hijo):
    # llamada recursiva
    sol= buscar_solucion_heuristica(nodo_hijo, solucion, visitados)
    if sol != None:
    return sol

            return None
    

    def mejora(nodo_padre, nodo_hijo):
    calidad_padre=0
    calidad_hijo=0
    dato_padre = nodo_padre.get_datos()
    dato_hijo = nodo_hijo.get_datos()
    for n in range(1,len(dato_padre)):
    if (dato_padre[n]>dato_padre[n-1]):
    calidad_padre = calidad_padre + 1;
    if (dato_hijo[n]>dato_hijo[n-1]):
    calidad_hijo = calidad_hijo + 1;

    if calidad\_hijo>=calidad\_padre:
    
    OriginalGriffO 1 Reply Last reply
    0
    • M Member_15814673

      Me enviaron hacer que el algorimo heruistico que esta de forma lineal sea dinamico, osea que el cambio de posicion lo genere de forma dinamica mediante el ingreso del tamaño del array, pero no me sale me podrian ayudar??? solo he logrado que imprima el array pero no me sale el cambio de posicion

      Google translate:

      They sent me to make the heruistic algorithm that is linearly dynamic, that is, the change of position is generated dynamically by entering the size of the array, but it doesn't work out, could you help me??? I have only managed to print the array but I do not get the change of position

      # Puzle Lineal con heurística
      from re import I
      from ClaseNodo import Nodo
      def buscar_solucion_heuristica(nodo_inicial, solucion, visitados):
      visitados.append(nodo_inicial.get_datos())
      if nodo_inicial.get_datos() == solucion:
      return nodo_inicial
      else:
      # expandir nodos sucesores (hijos)
      dato_nodo = nodo_inicial.get_datos()
      i=0
      while i < tamaño :
      hijo=[]
      hijo.append(dato_nodo)
      i=i+1
      hijo=[dato_nodo[1], dato_nodo[0], dato_nodo[2], dato_nodo[3], dato_nodo[4], dato_nodo[5]]
      hijo_izquierdo = Nodo(hijo)
      hijo=[dato_nodo[1], dato_nodo[0], dato_nodo[3], dato_nodo[2], dato_nodo[4], dato_nodo[5]]
      hijo_central = Nodo(hijo)
      hijo=[dato_nodo[1], dato_nodo[0], dato_nodo[3], dato_nodo[2], dato_nodo[5], dato_nodo[4]]
      hijo_derecho = Nodo(hijo)
      nodo_inicial.set_hijos([hijo_izquierdo, hijo_central, hijo_derecho])
      for nodo_hijo in nodo_inicial.get_hijos():
      if not nodo_hijo.get_datos() in visitados and mejora(nodo_inicial, nodo_hijo):
      # llamada recursiva
      sol= buscar_solucion_heuristica(nodo_hijo, solucion, visitados)
      if sol != None:
      return sol

              return None
      

      def mejora(nodo_padre, nodo_hijo):
      calidad_padre=0
      calidad_hijo=0
      dato_padre = nodo_padre.get_datos()
      dato_hijo = nodo_hijo.get_datos()
      for n in range(1,len(dato_padre)):
      if (dato_padre[n]>dato_padre[n-1]):
      calidad_padre = calidad_padre + 1;
      if (dato_hijo[n]>dato_hijo[n-1]):
      calidad_hijo = calidad_hijo + 1;

      if calidad\_hijo>=calidad\_padre:
      
      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      This is an English language site, and we can only accept and answer questions in that language. I have run this through Google Translate to produce a probably-good version, but you should check it and make sure it does say what you are actually asking.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups