The form of data
hi
what I want to do is create three different types of point with random coordinate so this is what I did
[deleted for better readability]
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
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 PortalThanks,
Matthias0 -
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 gp
from gurobipy import *
from random import randint
import math
coorD=[]
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)]
#dictionary
demand={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
#Demand
coorDx=[]
for i in range(51):
coorDx.append(randint(1,100))
coorDy=[]
for i in range(51):
coorDy.append(randint(1,100))
#Launch station
coorLx=[]
for i in range(51):
coorLx.append(randint(1,100))
coorLy=[]
for i in range(51):
coorLy.append(randint(1,100))
#Recharge station
coorRx=[]
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 station
disDL=[]
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 rechargestation
disDR=[]
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 launchstation
disLR=[]
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')
0
Post is closed for comments.
Comments
3 comments