function [ FitnessVal , sol ] =MyCost( x , model)
%UNTITLED6 Summary of this function goes here
% Detailed explanation goes here
% clc,clear , close all
% [ model ] = CreatModel( ) ;
% % % % %
% rand( 'seed' , 11010 );
% % % % % %
% % x= rand( 1, model.nVar );
% load('mydata.mat')
%%
% 小数编码转化为整数编码
[~, x ] = sort( x );
% 确定 分隔符位置
DelPos=find( x > model.NumClient );
From=[0 DelPos]+1;
To=[DelPos model.nVar+1 ]-1;
% 线路分割
t=1;
for j=1: model.K
if ~numel( x(From(j):To(j)) )
continue;
end
L{ t, 1}=x(From(j):To(j));
t=t+1;
end
Num_Route = numel(L ); % 总的线路数目
% if Num_Route == model.M1
% disp('succeed ')
% end
%% 每条线路目标函数值计算
empty_rourte.ClientSequence = [ ]; % 每条线路的 客户序列
empty_rourte.Client_Num = [ ]; % 每条线路的 客户数目
empty_rourte.LoadVal = [ ] ; % 每条线路 总装载量
empty_rourte.LoadValidation =[ ]; %每条线路 总装载量 的超载量
empty_rourte.FixedCost = [ ] ; % 每条线路的 固定成本 (即 TC1)
empty_rourte.TravelingTimeSum = [ ]; % 每条线路的 总的 行驶时间
empty_rourte.CijSum = [ ] ; % 每条线路的 总的 行驶费用 (即 TC2)
empty_rourte.TC3 = [ ] ; % 制冷成本 TC3
empty_rourte.TC4= [ ] ; % 制冷成本 TC4 货损成本
Schedule =repmat(empty_rourte , Num_Route ,1);
ArrivalDeparturetime = zeros( model.NumClient , 2) ; % 两列 : 到达每个客户的时间 和 离开每个客户的时间
for route_index =1 : Num_Route
temp = L{ route_index } ;
% 每条线路的 客户序列 和 客户数目
Schedule( route_index ).ClientSequence = temp ;
Schedule( route_index ).Client_Num = numel( temp ) ;
% 每条线路 总装载量 和 超载量
Schedule( route_index ).LoadVal = sum( model.Demand( temp ) ) ;
Schedule( route_index ).LoadValidation = max( 0, Schedule( route_index ).LoadVal-model.Q ) ;
% 每条线路的 固定成本 TC1
Schedule( route_index ).FixedCost = model.gk ;
% TC2 和 到达每个客户点的时间 计算
% 到达第一个 客户点
Leav_time = model.StartTime ; % 离开时间
D_length = model.D_Center2Client( temp( 1 ) ) ; % 需要跑过的 路段的长度
VelocitySet = [ model.Velocity(1).Center2Client( temp( 1 ) ) ;
model.Velocity( 2 ).Center2Client( temp( 1 ) ) ;
model.Velocity( 3 ).Center2Client( temp( 1 ) ) ; ] ; % 该路段在各个时间对应的 速度取值
[ ArriTime , TravellingTime , Cost ] =ArcProcess( Leav_time , D_length , VelocitySet , model ) ;
Schedule( route_index ).TravelingTimeSum = TravellingTime ;
Schedule( route_index ).CijSum = Cost ;
ArrivalDeparturetime( temp( 1 ) , 1 ) = ArriTime ;
ArrivalDeparturetime( temp( 1 ) , 2 ) = ArrivalDeparturetime( temp( 1 ) , 1 ) + model.ServiceTime( temp( 1 ) ) ;
% 到达后续客户点
for j = 2: numel( temp )
Leav_time = ArrivalDeparturetime( temp( j-1 ) , 2 ) ; % 离开时间
D_length = model.D_Center2Client( temp( j ) ) ; % 需要跑过的 路段的长度
VelocitySet = [ model.Velocity( 1 ).Client2Client( temp( j-1 ) , temp( j ) ) ;
model.Velocity( 2 ).Client2Client( temp( j-1 ) , temp( j ) ) ;
model.Velocity( 3 ).Client2Client( temp( j-1 ) , temp( j ) ) ; ] ; % 该路段在各个时间对应的 速度取值
[ ArriTime , TravellingTime , Cost ] =ArcProcess( Leav_time , D_length , VelocitySet , model ) ;
Schedule( route_index ).TravelingTimeSum = Schedule( route_index ).TravelingTimeSum + TravellingTime ;
Schedule( route_index ).CijSum = Schedule( route_index ).CijSum + Cost ;
ArrivalDeparturetime( temp( j ) , 1 ) = ArriTime ;
ArrivalDeparturetime( temp( j ) , 2 ) = ArrivalDeparturetime( temp( j ) , 1 ) + model.ServiceTime( temp( j ) ) ;
end
% 返回 配送中心
Leav_time = ArrivalDeparturetime( temp(end ) , 2 ) ; % 离开时间
D_length = model.D_Center2Client( temp( end ) ) ; % 需要跑过的 路段的长度
VelocitySet = [ model.Velocity(1).Center2Client( temp( end ) ) ;
model.Velocity( 2 ).Center2Client( temp( end ) ) ;
model.Velocity( 3 ).Center2Client( temp( end ) ) ; ] ; % 该路段在各个时间对应的 速度取值
[ ~ , TravellingTime , Cost ] =ArcProcess( Leav_time , D_length , VelocitySet , model ) ;
Schedule( route_index ).TravelingTimeSum = Schedule( route_index ).TravelingTimeSum + TravellingTime ;
Schedule( route_index ).CijSum = Schedule( route_index ).CijSum + Cost ;
% 制冷成本 TC3
Schedule( route_index ).TC3 = model.PL *( model.EC1 * Schedule( route_index ).TravelingTimeSum + ...
model.EC2 * sum( model.ServiceTime( temp ) ) ) ;
% 制冷成本 TC4 货损成本
timeval = ArrivalDeparturetime( temp , 2 ) - model.StartTime ;
Schedule( route_index ).TC4 = model.P* sum( model.Demand( temp ).*( 1- model.T4_K * exp( - model.epsilon * timeval ) ) ) ;
end
%% 计算每个客户点的满意度
Satisfaction = zeros( model.NumClient , 1 ) ;
for ind = 1 : model.NumClient
timeval = ArrivalDeparturetime( ind , 1 ) ;
if timeval<= model.eei( ind ) | timeval>= model.lli( ind )
continue ;
end
if timeval>= model.ei( ind ) && timeval<= model.li( ind )
Satisfaction( ind ) =1 ;
continue ;
end
if timeval > model.eei( ind ) && timeval< model.ei( ind )
Satisfaction( ind ) = ( ( timeval - model.eei( ind ) ) /( model.ei( ind ) - model.eei( ind ) ) )^model.alpha ;
continue ;
end
if timeval > model.li( ind ) && timeval< model.lli( ind )
Satisfaction( ind ) = ( ( model.lli( ind ) - timeval ) /( model.lli( ind ) - model.li( ind ) ) )^model.beta ;
continue ;
end
end
%% 目标函数值和适应度值 计算
Objective = sum( [Schedule.FixedCost ] ) + ...
sum( [ Schedule.CijSum ] ) + ...
sum( [ Schedule.TC3 ] ) + ...
sum( [ Schedule.TC4 ] ) ;
% TC1 TC2 TC3 TC4
FitnessVal = Objective + ...
model.Penaltycof1 * sum( [Schedule.LoadValidation] ) + ... % 质量超载 惩罚
model.Penaltycof2 * max( 0 , model.Min_Satisfaction-min( Satisfaction ) ) ; % 质量超载惩罚
sol.FitnessVal = FitnessVal ; % 适应度值
sol.Objective = Objective ; % 目标函数值
sol.Schedule = Schedule ; % 调度方案具体情况
sol.IsFeasible = ( FitnessVal == Objective ) ; % 表示解是否为可行解
sol.Min_SatisfactionVal = min( Satisfaction ) ; % 所有客户的满意度水平 中的最小值
sol.Satisfaction = Satisfaction ; % 各个客户的满意度水平
sol.ArrivalDeparturetime =ArrivalDeparturetime ; % 两列 : 到达每个客户的时间 和 离开每个客户的时间

qq_35144224
- 粉丝: 2
最新资源
- 国内移动通信基站防雷保护的分析与参考.doc
- 基于智能化网络机房的绿色数据中心设计.docx
- 播音主持行业中人工智能技术的应用研究.docx
- 小天鹅物联网洗衣机设计初探.docx
- JSP大学设计UT物流仓储管理系统.doc
- 节移动地理信息系统与嵌入式地理信息系统的关键实用技术.doc
- 计算机专业学生需要了解的计算机知识.doc
- 《软件工程》试题和标准答案(第套).doc
- Excel表格模板:应收账款统计表.xlsx
- 液压挖掘机伸缩臂CAD设计与有限元分析.doc
- Java语言程序设计(一)试题答案.doc
- 配网基建工程项目管理模式的精益化策略.docx
- 关于农村乡镇档案实行计算机管理的探讨.docx
- JAVA-面历年真题--社会上常用的历年真题库.doc
- 信息化背景下的计算机教学改革探究.docx
- 《面向对象程序设计》课程教学模式改革方案.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


