Click here to Skip to main content
15,886,258 members
Home / Discussions / Python
   

Python

 
GeneralRe: Python Code Related Pin
Dave Kreskowiak19-Nov-22 4:07
mveDave Kreskowiak19-Nov-22 4:07 
AnswerRe: Python Code Related Pin
Richard MacCutchan18-Nov-22 22:35
mveRichard MacCutchan18-Nov-22 22:35 
QuestionPython vs. PHP - Web Application Development Pin
vitaassure15-Nov-22 10:30
professionalvitaassure15-Nov-22 10:30 
AnswerRe: Python vs. PHP - Web Application Development Pin
Gerry Schmitz15-Nov-22 12:11
mveGerry Schmitz15-Nov-22 12:11 
AnswerRe: Python vs. PHP - Web Application Development Pin
Richard MacCutchan15-Nov-22 21:34
mveRichard MacCutchan15-Nov-22 21:34 
QuestionPython code Pin
Masande Nogemane3-Nov-22 6:34
Masande Nogemane3-Nov-22 6:34 
AnswerRe: Python code Pin
Richard MacCutchan3-Nov-22 7:47
mveRichard MacCutchan3-Nov-22 7:47 
QuestionPython Code Heuristic Algorithm Pin
Member 1581467330-Oct-22 19:31
Member 1581467330-Oct-22 19:31 
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

Python
# 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:
        return True
    else:
        return False 

if __name__ == "__main__":
            i=0
            j=0
            estado_inicial=[]
            tamaño =int(input("Por Favor, Introduzca el tamaño del array"))
            while i < tamaño:
                inicio =int(input("Por Favor, Introduzca un numero"))
                estado_inicial.append(inicio)
                i=i+1
            
            solucion=[]
            while j < tamaño:
                final =int(input("Por Favor, Introduzca el solucion"))
                solucion.append(final)
                j=j+1   
            nodo_solucion = None
            visitados=[]
            nodo_inicial = Nodo(estado_inicial)
            nodo = buscar_solucion_heuristica(nodo_inicial, solucion, \
                                          visitados)
            # mostrar resultado
            resultado=[]
            while nodo.get_padre() != None:
                resultado.append(nodo.get_datos())
                nodo = nodo.get_padre()
            resultado.append(estado_inicial)
            resultado.reverse()
            print(resultado)

AnswerRe: Python Code Heuristic Algorithm Pin
OriginalGriff30-Oct-22 19:34
mveOriginalGriff30-Oct-22 19:34 
QuestionHow to secure Python application using license key? Pin
Alex Dunlop26-Oct-22 5:39
Alex Dunlop26-Oct-22 5:39 
AnswerRe: How to secure Python application using license key? Pin
Gerry Schmitz15-Nov-22 12:04
mveGerry Schmitz15-Nov-22 12:04 
QuestionHow to set activation system to ready python project? Pin
MR-XAN77715-Oct-22 22:38
MR-XAN77715-Oct-22 22:38 
AnswerRe: How to set activation system to ready python project? Pin
Richard MacCutchan16-Oct-22 0:48
mveRichard MacCutchan16-Oct-22 0:48 
Question[Help]H.W issues Pin
אנטון מוטרוק 202115-Oct-22 7:10
אנטון מוטרוק 202115-Oct-22 7:10 
AnswerRe: [Help]H.W issues Pin
Richard MacCutchan15-Oct-22 9:05
mveRichard MacCutchan15-Oct-22 9:05 
QuestionError - 'module' object has no attribute 'askopenfilename' Pin
s yu13-Oct-22 2:59
s yu13-Oct-22 2:59 
AnswerRe: Error - 'module' object has no attribute 'askopenfilename' Pin
Richard MacCutchan13-Oct-22 3:12
mveRichard MacCutchan13-Oct-22 3:12 
QuestionUnexpected token 'root' Pin
s yu12-Oct-22 5:45
s yu12-Oct-22 5:45 
AnswerRe: Unexpected token 'root' Pin
Richard MacCutchan12-Oct-22 6:39
mveRichard MacCutchan12-Oct-22 6:39 
GeneralRe: Unexpected token 'root' Pin
s yu12-Oct-22 7:28
s yu12-Oct-22 7:28 
GeneralRe: Unexpected token 'root' Pin
Richard MacCutchan12-Oct-22 7:57
mveRichard MacCutchan12-Oct-22 7:57 
GeneralRe: Unexpected token 'root' Pin
Dave Kreskowiak12-Oct-22 12:08
mveDave Kreskowiak12-Oct-22 12:08 
GeneralRe: Unexpected token 'root' Pin
s yu13-Oct-22 2:28
s yu13-Oct-22 2:28 
Questionhello, good day, does anyone know how to solve this problem? It would help me a lot if you could explain how to do it Pin
Member 157924299-Oct-22 18:35
Member 157924299-Oct-22 18:35 
AnswerRe: hello, good day, does anyone know how to solve this problem? It would help me a lot if you could explain how to do it Pin
Richard MacCutchan9-Oct-22 22:16
mveRichard MacCutchan9-Oct-22 22:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.