• Gurobi Staff

Hi!

Could you please use a proper code formatting for your Python code? It is very hard to read this without formatting.

Please check our guide on how to write a community post:
Posting to the Community Forum – Gurobi Support Portal

Thanks,
Matthias

I'm sorry for that

what I want to do is create three different types of point with random coordinate so this is what I did

import gurobipy as gpfrom gurobipy import *from random import randintimport mathcoorD=[]for i in range(50):    coorD.append([])    for j in range(2):        s=randint(1,100)        coorD[i].append(s)demandpoint=[i for i in range(1,51)]coorL=[]for i in range(50):    coorL.append([])    for j in range(2):        s=randint(1,100)        coorL[i].append(s)Launchstationpoint=[i for i in range(1,51)]coorR=[]for i in range(50):    coorR.append([])    for j in range(2):        s=randint(1,100)        coorR[i].append(s)Rechargestationpoint=[i for i in range(1,51)]#dictionarydemand={demandpoint[i]:coorD[i] for i in range(50)}Launchstation={Launchstationpoint[i]:coorL[i] for i in range(50)}Rechargestation={Rechargestationpoint[i]:coorR[i] for i in range(50)}

The codes below were my previous distance practice and I want to modify, cause I want to change the form of data, how can I use the direct values from the three dictionaries to compute distances between points and create dictionaries to contain them?

#the form I want{(demand1,Launchstation1):distance,(demand1,Launchstation2):distance,(demand1,Launchstation3):distance...etc}
#below is my previous practice#DemandcoorDx=[]for i in range(51):    coorDx.append(randint(1,100))coorDy=[]for i in range(51):    coorDy.append(randint(1,100))#Launch stationcoorLx=[]for i in range(51):    coorLx.append(randint(1,100))coorLy=[]for i in range(51):    coorLy.append(randint(1,100))#Recharge stationcoorRx=[]for i in range(51):    coorRx.append(randint(1,100))coorRy=[]for i in range(51):    coorRy.append(randint(1,100))#distance#distance between demand and launch stationdisDL=[] for i in range(1,51):    for j in range(1,51):        s1=math.sqrt((Kx[i]-Ix[j])**2+(Ky[i]-Iy[j])**2)        disDL.append(s1)#distance between demand and rechargestationdisDR=[]for i in range(1,51):    for j in range(1,51):        s2=math.sqrt((Kx[i]-Jx[j])**2+(Ky[i]-Jy[j])**2)        disDR.append(s2)#distance between rechargestation and launchstationdisLR=[]for i in range(1,51):    for j in range(1,51):        s3=math.sqrt((Ix[i]-Jx[j])**2+(Iy[i]-Jy[j])**2)        disLR.append(s3)

and one more thing

if I want to create variables with the forms

## Dki={0,1}    k∈K     i∈I          K= the set of demands      I=the set of Launch station

are the codes below the correct way to express?

Di=m.addVars(demandpoint,Launchstationpoint,vtype=GRB.BINARY,name='Di')