Home > other >  Program is not an error, why don't skip calTC execution, strives for the bosses, using python2.
Program is not an error, why don't skip calTC execution, strives for the bosses, using python2.

Time:03-25

# - * - coding: utf-8 - * -

The import sys

Sys. Path. Append ('../../../')
The from nsga2. Individual import individual
The from nsga2. Customer import customer
The from nsga2. Cusset import cusset
The from nsga2. Carset import carset
The from nsga2. Car import car
The from nsga2. The problems the import Problem
The from nsga2. Utils import NSGA2Utils
The from vrp_definitions import VRPDefinitions
Import the random
The import functools
The import numpy as np
The import math
The from sklearn. Cluster import KMeans
The from sklearn. Externals import joblib
The from sklearn import cluster

Mileage_0=# 8 km per Litre
Mileage_m=# 6 km per Litre
Load_truck=5500
Weight=12500
Load_max=load_truck + weight
Data=https://bbs.csdn.net/topics/np.loadtxt (' C: \ \ Users \ \ SMX \ \ Desktop \ \ nsga2 - master \ \ 120 _10. TXT '). The astype (np) int64)
# print (' data: 'data)
Cus_num=21
Dismat=[[0] * (cus_num) for a row in the range (cus_num)]
For I in data:
For j in data:
# print (' I [0] : 'I [0])
# print (' j [0] : 'j [0])
Dismat [I [0]] [[0]]=((I [1] - [1] j) * * 2 + (I [2] - [2] j) * * 2) * * 0.5
# print (' dismat: 'dismat)





# def mileage (load) :
# consumption=mileage_0 + ((mileage_m - mileage_0) * (the load - load_truck)/(load_max - load_truck))
# return consumption

Def mileage (load) :
Consumption=mileage_0 + ((mileage_m - mileage_0) * (the load - load_truck)/(load_max - load_truck))
Return consumption

The class VRP (Problem) :

Def __init__ (self, vrp_definitions) :
Self. Vrp_definitions=vrp_definitions
Self. Max_objectives=[None, None]
Self. Min_objectives=[None, None]
Self. Problem_type=None
Self. N=20


Def __dominates (self, individual2 individual1) :
Worse_than_other=self. Vrp_definitions. F1 (individual1) & lt;=self. Vrp_definitions. F1 (
Individual2) and the self. Vrp_definitions. F2 (individual1) & lt;=self. Vrp_definitions. F2 (individual2)
Better_than_other=self. Vrp_definitions. F1 (individual1) & lt; Self. Vrp_definitions. F1 (
Individual2) or self. Vrp_definitions. F2 (individual1) & lt; Self. Vrp_definitions. F2 (individual2)
Return worse_than_other and better_than_other


Def initSolusion (self, cusset) :
Carset=[]
C=0
Global countcar
Countcar=0
The car=car (countcar)

Cus_list=range (len (cusset cusset))
The random shuffle (cus_list)
For cid in cus_list:
C=c + cusset. Cusset [cid] me
If c & lt;=car. Capacity:
The car. The route. Append (cid)
The else:
# the random shuffle (car. The route)
Carset. Append (car)
# print car. The route
C=cusset. Cusset [cid] me
Countcar=countcar + 1
The car=car (countcar)
The car. The route. Append (cid)
Carset. Append (car)
Return carset

Def CRSM (self, carroute cusset) :
Li=[]
The car=car (1)
Cc=0
Ss=0
Tc=0
Ts=0
I=1
# carroute: a car passed all the path

Individual=individual ()
Cset=self. InitSolusion (cusset)
Individual. Car_route. The extend (cset)


# print (' carroute: 'carroute)

While I & lt;=10:
I=I + 1
# for I in range (10) :
Cur_cw=car. Capacity
Cc=0
Ss=0
SSS=0
CurT=0
Preid=0
Lastid=None

For nc in carroute:
# print (nc:, nc)
If cur_cw==0:
Cur_cw=car. Capacity
CurT=curT + (dismat [0] [preid]/car. The Velocity) * 2

Cc=cc + self. CalTC (dismat [0] [preid], carroute, cusset, car. CarWeight, car. The Velocity) + self. CalTC (
Dismat [0] (nc), carroute cusset, car. CarWeight + car. Capacity, car the Velocity)
# print (' cusset. Dismat, cusset dismat)
# print (' individual. Car_route: ', individual car_route)

Cc=cc + self. CalTC (dismat preid (nc), carroute, cusset, car. CarWeight + cur_cw, car. The Velocity)

# print cusset. Cusset [nc]. Demand
CurT=curT + dismat [preid] [] nc/car. The Velocity
Ss=self. CalSat (curT, cusset cusset [r]. Nc eS, cusset. Cusset [nc]. LS, cusset. Cusset [nc]. EH,
Cusset. Cusset [nc]. LH)
SSS=SSS + ss
# print ss
# dd=np. Random. Normal (cusset. Cusset [nc] me, cusset. Cusset [r]. Nc va, 1)
Dd=cusset. Cusset [nc] me + np. Random. Normal (cusset. Cusset [nc] me, cusset. Cusset [nc] me/9)
Cusset. Cusset [nc]. Demand=dd
Cur_cw=car. Capacity - cusset. Cusset [nc] demand
CurT=curT + cusset. Cusset [nc] st
Preid=nc

If cur_cw & lt; 0:
Cur_cw=car. Capacity + cur_cw
CurT=curT + (dismat [0] (nc)/car. The Velocity) * 2
Cc=cc + self. CalTC (dismat [0] (nc), carroute, cusset, car. CarWeight, car. The Velocity) + self. CalTC (
Dismat [0] (nc), carroute cusset, car. CarWeight + car. Capacity, car the Velocity)
Lastid=nc

# print 'SSS' SSS
Cc=cc + self. CalTC (dismat [0] [lastid], carroute, cusset, car. CarWeight + cur_cw,
Car. Velocity)

Tc=Tc + cc
Ts=Ts + SSS
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related