0

TSP (JobSolveStatus.INFEASIBLE_SOLUTION: 3)

Well I'm trying to code de travelling salesman prolem but when a get to the solution part my code prints "JobSolveStatus.INFEASIBLE_SOLUTION: 3" I don't know what's happening, but I leave my code below My df are 20 cities and I'm using cities from Mexico import pandas as pd df = pd.read_excel(open('Mydataframe.xlx','rb'),sheet_name='Hoja1', converters={'n°':int}, index_col=[0]) df df["Coordenadas"]="" df import googlemaps gmaps_key=googlemaps.Client(key="My Api Key") for n in range(len(df)): geocode_resultado=gmaps_key.geocode(df.iloc[n][0]) try: lat=geocode_resultado[0]["geometry"]["location"]["lat"] lon=geocode_resultado[0]["geometry"]["location"]["lng"] df.set_value(n,"Coordenadas",(lat,lon)) except: lat=None lon=None from pandas import ExcelWriter from pandas import ExcelFile write=ExcelWriter('/Users/chico/Desktop/Ahora si lo resuelvo/F.xlsx') df.to_excel(write,'Hoja1', index=False) write.save() df from geopy import distance import numpy as np distancia=[] for n in range(len(df)): for i in range(len(df)): if n!=i: distancia.append(np.round(distance.distance(df.iloc[n][1],df.iloc[i][1]).km, decimals=1)) print(distancia) ciudades=[i for i in range(len(df))] ciudades arcos=[(i,j) for i in ciudades for j in ciudades if i!=j] print(arcos) distancia_arcos={(i,j):distance.distance(df.iloc[i][1],df.iloc[j][1]).km for i,j in arcos} distancia_arcos from docplex.mp.model import Model mdl=Model('TSP-2') x=mdl.binary_var_dict(arcos,name='x') d=mdl.continuous_var_dict(ciudades,name='d') mdl.minimize(mdl.sum(distancia_arcos[i]*x[i] for i in arcos)) for c in ciudades: mdl.add_constraint(mdl.sum(x[(i,j)] for i,j in arcos if i==c)==i,ctname='out_%d'%c) for c in ciudades: mdl.add_constraint(mdl.sum(x[(i,j)] for i,j in arcos if i==c)==i,ctname='in%d'%c) #The rest of the code will be in the comments

28th Oct 2019, 8:47 PM
Héctor Eliú Caballero Dimas
Héctor Eliú Caballero Dimas - avatar
2 Réponses
+ 2
Rather than pasting the code in Description section (it's a big code) and end up getting the text truncated from character limits - save your code in your profile, edit your question and share the link in Description section of the original question above. Having the code link available in the Description section, you can then safely remove the code text from Description section (keep problem description intact), also remove the rest of code in answers section. People prefer to open your code for a review rather than copying some text - paste into code for testing (more hustle). Here's how to share links and tips for posting a question. For future reference 👍 P.S. Please don't reply, I will remove this note if you update your original question. https://www.sololearn.com/post/74857/?ref=app https://www.sololearn.com/Discuss/333866/?ref=app
29th Oct 2019, 3:35 AM
Ipang
0
#This is the rest of the code for i,j in arcos: if j!=0: mdl.add_indicator(x[(i,j)],d[i]+1==d[j],name='order_(%d,_%d)'%(i,j)) print(mdl.export_to_string()) mdl.parameters.timelimit=60 mdl.parameters.mip.strategy.branch=1 solucion=mdl.solve(log_output=True) mdl.get_solve_status() #in this part mi code prints <JobSolveStatus.INFEASIBLE_SOLUTION: 3> #An then when i want my optimal solucion a code this: solucion.display() #And just prints "AttributeError: 'NoneType' object has no attribute 'display'"
28th Oct 2019, 8:49 PM
Héctor Eliú Caballero Dimas
Héctor Eliú Caballero Dimas - avatar