cost

select * from wip_entities where wip_entity_name='60593'
select * from wip_discrete_jobs where wip_entity_id='1140724'
select * from WIP_OPERATIONS where wip_entity_id='1140724'
select * from WIP_OPERATION_RESOURCES where wip_entity_id='1140724'
SELECT * FROM WIP_REQUIREMENT_OPERATIONS WHERE WIP_ENTITY_ID='1140724' AND ORGANIZATION_ID=255

select * from mtl_system_items where inventory_item_id=341210 and organization_id=255   2KD0-0000000
select * from BOM_OPERATIONAL_ROUTINGS where assembly_item_id=341210
select * from BOM_OPERATION_SEQUENCES  where routing_sequence_id=279801
select * from bom_operation_resources  where operation_sequence_id=643727
select * from bom_resources where resource_id in (937,941,935,939,942,943,936,938,940)
select * from bom_standard_operations where standard_operation_id=643727

select * from cst_resource_costs where resource_id in (937,941,935,939,942,943,936,938,940) and cost_type_id=1203
select * from cst_cost_types where cost_type_id in (1181,1203)
select * from cst_department_overheads_v

-----------
inv會計期間無法關閉
a) The number of erred rows in MTL_MATERIAL_TRANSACTIONS:
select count (*)
from MTL_MATERIAL_TRANSACTIONS
where COSTED_FLAG = 'E';

b) The number of unprocessed rows in MTL_MATERIAL_TRANSACTIONS:
select count (*)
from MTL_MATERIAL_TRANSACTIONS
where COSTED_FLAG = 'N';
c) The number of processed rows in MTL_MATERIAL_TRANSACTIONS:
select count (*)
from MTL_MATERIAL_TRANSACTIONS
where COSTED_FLAG like NULL;

To resubmit the erred records in the MTL_MATERIAL_TRANSACTIONS table, it must be done via a SQL statement by updating the costed_flag = ‘N’ and the transaction_group_id = NULL.

Update MTL_MATERIAL_TRANSACTIONS
set COSTED_FLAG = 'N',
set TRANSACTION_GROUP_ID = NULL
where COSTED_FLAG ='E' or COSTED_FLAG ='N';
----------------------------------------------
查询未计成本:
select
m.transaction_id ,
m.transfer_organization_id,
m.organization_id,
msib.segment1 item,
mtt.transaction_type_name,
to_char(m.transaction_date,'yyyy-mm-dd') 事务日期,
m.transaction_reference,
m.transaction_id ,
m.subinventory_code,
m.costed_flag,
m.cost_group_id,
m.cost_category_id,
m.cost_update_id,
m.error_code,
m.error_explanation,
m.transaction_group_id
from
MTL_MATERIAL_TRANSACTIONS M,
MTL_TRANSACTION_TYPES MTT,
mtl_system_items_b msib
where
   to_char(m.transaction_date,'yyyymm')='200611'
and m.costed_flag='N'
and M.TRANSACTION_TYPE_ID = MTT.TRANSACTION_TYPE_ID
and msib.inventory_item_id=m.inventory_item_id
and msib.organization_id=m.organization_id
order by
mtt.transaction_type_name,
to_char(m.transaction_date,'yyyy-mm-dd'),
m.subinventory_code

-----------------------
查询错误计成本:
select
m.transaction_id ,
m.transfer_organization_id,
m.organization_id,
msib.segment1 item,
mtt.transaction_type_name,
to_char(m.transaction_date,'yyyy-mm-dd') 事务日期,
m.transaction_reference,
m.transaction_id ,
m.subinventory_code,
m.costed_flag,
m.cost_group_id,
m.cost_category_id,
m.cost_update_id,
m.error_code,
m.error_explanation,
m.transaction_group_id
from
MTL_MATERIAL_TRANSACTIONS M,
MTL_TRANSACTION_TYPES MTT,
mtl_system_items_b msib
where
to_char(m.transaction_date,'yyyymm')='200611'
and m.costed_flag='E'
and M.TRANSACTION_TYPE_ID = MTT.TRANSACTION_TYPE_ID
and msib.inventory_item_id=m.inventory_item_id
and msib.organization_id=m.organization_id
order by
mtt.transaction_type_name,
to_char(m.transaction_date,'yyyy-mm-dd'),
m.subinventory_code
----------------------------
还原到未计成本原始状态:
update  MTL_MATERIAL_TRANSACTIONS M1
set m1.costed_flag = 'N',
m1.error_code = NULL,
m1.error_explanation = NULL,
m1.transaction_group_id = NULL
where
m1.transaction_id in
(
select
m.transaction_id
from
MTL_MATERIAL_TRANSACTIONS M,
MTL_TRANSACTION_TYPES MTT,
mtl_system_items_b msib
where
    to_char(m.transaction_date,'yyyymm')='200611'
and m.costed_flag='N'
and M.TRANSACTION_TYPE_ID = MTT.TRANSACTION_TYPE_ID
and msib.inventory_item_id=m.inventory_item_id
and msib.organization_id=m.organization_id
)
----------
最后,重新运行一下成本管理器即可!

-------------------------------------
未计成本物料导致库存会计期不可进行关闭的查询

由于俺们这里系统报表没有提供相应报表来查详细是哪些东西出错了,经过一个下午的研究终于找到了解决办法:
运行如下脚本语句

select mmt.*
from
apps.MTL_MATERIAL_TRANSACTIONS mmt
where mmt.organization_id= 您所设定的库存组织代码
and mmt.costed_flag='E'
and and mmt.transaction_date between 您所要查找的起始日期 and 您所要查找的结束日期

凡是costed_flag 标记为E的都是未计成本项目,在mmt这个表中错误代码及错误解释项目里有相应注释。

我不是系统管理员,暂时只研究到这一步,大家各位有什么宝贵经验请不吝赐教。俺们公司的库存会计期关闭经常出现异常问题,但是相应解决的方法却不明显,还望高手指教。


未处理物料事务处理的查询

运行如下脚本查询:

select mmtt.* ,
MSI.SEGMENT1 物料编码,
fu.user_name

from inv.MTL_MATERIAL_TRANSACTIONS_TEMP mmtt ,
INV.MTL_SYSTEM_ITEMS_B MSI,
apps.fnd_user fu

where mmtt.organization_id= 您所设定的库存组织代码
and msi.organization_id= mmtt.organization_id
AND msi.INVENTORY_ITEM_ID = mmtt.INVENTORY_ITEM_ID
and mmtt.created_by= fu.user_id


--此消息表示 MTL_MATERIAL_TRANSACTIONS_TEMP 表中存在未被处理的物料事务处理。
--在这种情况下,您不能关闭期间。请与系统管理员联系。
--库存管理系统会将此表内的这些事务处理视为移动数量的一部分。
--这种情况下系统将不允许您关闭期间,因为结果生成的会计分录事务处理日期将处于已关闭的期间内,
--该分录不会被关闭期间或总帐传送流程接受

 

等待接收事务处理的查询

select *
from po.RCV_TRANSACTIONS_INTERFACE

--如果使用的是采购管理系统,此消息表示 RCV_TRANSACTIONS_INTERFACE 表中有未被处理的采购事务处理,
--其中包括采购订单接收和库存退货。
--如果存在这种情况,您会收到一则警告消息,但仍可以关闭会计期。
--接收值中不会包括这些事务处理,但在关闭期间后,
--由于这些事务处理的日期处于已关闭的期间内,因此无法对其进行处理。


待定物料事务处理的查询

select *
from inv.MTL_TRANSACTIONS_INTERFACE


--此消息表示 MTL_TRANSACTIONS_INTERFACE 表中存在未被处理的物料事务处理。
--如果存在这种情况,您会收到一则警告消息,但仍可以关闭会计期。
--库存值中不会包括这些事务处理。
--但在关闭期间后,由于这些事务处理的日期处于已关闭的期间内,因此无法对其进行处理。

等待移动事务处理的查询

select *
from wip.WIP_MOVE_TXN_INTERFACE

--此消息表示 WIP_MOVE_TXN_INTERFACE 表中存在未被处理的车间移动事务处理。
--如果存在这种情况,您会收到一则警告消息,但仍可以关闭会计期。
--在制品值中不包括这些事务处理。但在关闭期间后,
--由于这些事务处理的日期处于已关闭的期间内,因此无法对其进行处理。

待定 WIP 成本核算事务处理的查询

select *
from wip.WIP_COST_TXN_INTERFACE

--此消息表示 WIP_COST_TXN_INTERFACE 表中存在未被处理的资源和制造费用会计事务处理。
--在这种情况下,您不能关闭期间。这些事务处理包括在在制品值中,正等待进一步处理。
--这种情况下系统将不允许您关闭期间,因为结果生成的会计分录事务处理日期将处于已关闭的期间内,
--该分录不会被关闭期间或总帐传送流程接受。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12122734/viewspace-329656/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/12122734/viewspace-329656/

下载方式:https://pan.quark.cn/s/a4b39357ea24 布线问题(分支限界算法)是计算机科学和电子工程领域中一个广为人知的议题,它主要探讨如何在印刷电路板上定位两个节点间最短的连接路径。 在这一议题中,电路板被构建为一个包含 n×m 个方格的矩阵,每个方格能够被界定为可通行或不可通行,其核心任务是定位从初始点到最终点的最短路径。 分支限界算法是处理布线问题的一种常用策略。 该算法与回溯法有相似之处,但存在差异,分支限界法仅需获取满足约束条件的一个最优路径,并按照广度优先或最小成本优先的原则来探索解空间树。 树 T 被构建为子集树或排列树,在探索过程中,每个节点仅被赋予一次成为扩展节点的机会,且会一次性生成其全部子节点。 针对布线问题的解决,队列式分支限界法可以被采用。 从起始位置 a 出发,将其设定为首个扩展节点,并将与该扩展节点相邻且可通行的方格加入至活跃节点队列中,将这些方格标记为 1,即从起始方格 a 到这些方格的距离为 1。 随后,从活跃节点队列中提取队首节点作为下一个扩展节点,并将与当前扩展节点相邻且未标记的方格标记为 2,随后将这些方格存入活跃节点队列。 这一过程将持续进行,直至算法探测到目标方格 b 或活跃节点队列为空。 在实现上述算法时,必须定义一个类 Position 来表征电路板上方格的位置,其成员 row 和 col 分别指示方格所在的行和列。 在方格位置上,布线能够沿右、下、左、上四个方向展开。 这四个方向的移动分别被记为 0、1、2、3。 下述表格中,offset[i].row 和 offset[i].col(i=0,1,2,3)分别提供了沿这四个方向前进 1 步相对于当前方格的相对位移。 在 Java 编程语言中,可以使用二维数组...
源码来自:https://pan.quark.cn/s/a4b39357ea24 在VC++开发过程中,对话框(CDialog)作为典型的用户界面组件,承担着与用户进行信息交互的重要角色。 在VS2008SP1的开发环境中,常常需要满足为对话框配置个性化背景图片的需求,以此来优化用户的操作体验。 本案例将系统性地阐述在CDialog框架下如何达成这一功能。 首先,需要在资源设计工具中构建一个新的对话框资源。 具体操作是在Visual Studio平台中,进入资源视图(Resource View)界面,定位到对话框(Dialog)分支,通过右键选择“插入对话框”(Insert Dialog)选项。 完成对话框内控件的布局设计后,对对话框资源进行保存。 随后,将着手进行背景图片的载入工作。 通常有两种主要的技术路径:1. **运用位图控件(CStatic)**:在对话框界面中嵌入一个CStatic控件,并将其属性设置为BST_OWNERDRAW,从而具备自主控制绘制过程的权限。 在对话框的类定义中,需要重写OnPaint()函数,负责调用图片资源并借助CDC对象将其渲染到对话框表面。 此外,必须合理处理WM_CTLCOLORSTATIC消息,确保背景图片的展示不会受到其他界面元素的干扰。 ```cppvoid CMyDialog::OnPaint(){ CPaintDC dc(this); // 生成设备上下文对象 CBitmap bitmap; bitmap.LoadBitmap(IDC_BITMAP_BACKGROUND); // 获取背景图片资源 CDC memDC; memDC.CreateCompatibleDC(&dc); CBitmap* pOldBitmap = m...
%% 0. 环境清理及随机种子设置 clear; clc; close all; % ========== 随机性控制开关 ========== set_seed = true; % true: 固定结果;false: 每次随机 if set_seed seed = 42; rng(seed); fprintf('【随机控制】已启用固定种子,seed = %d\n', seed); else rng('shuffle'); fprintf('【随机控制】已禁用种子,启用完全随机模式'); end %% 1. 定义问题规模和生成合成数据 num_candidate_centers = 50; num_demand_points = 200; fprintf('正在生成一个带容量约束的 %d 个候选配送中心, %d 个需求点的大规模问题...\n', ... num_candidate_centers, num_demand_points); % 生成带容量限制的问题数据 problem = generate_capacitated_problem_data(num_candidate_centers, num_demand_points); fprintf('解空间大小: 2^%d ≈ %.2e\n\n', num_candidate_centers, 2^num_candidate_centers); % 将详细的随机数据保存到 CSV 文件 save_problem_data_to_csv(problem); % 保存每个中心 - 需求点对的完整中心 - 需求点成本矩阵 % 生成的 CSV 文件将包含以下列:CenterID(配送中心 ID)、DemandID(需求点 ID)、Distance_Center_Demand(配送中心 - 需求点距离) % Transport_Cost_Internal_A(内部运输成本_A)和 Transport_Cost_External_B(外部运输成本_B) save_center_demand_cost_matrix(problem); %% 2. 算法参数定义 nPop = 50; % 蝙蝠群规模 MaxIt = 3000; % 最大迭代次数 fmin = 0; % 最小频率 fmax = 2; % 最大频率 A_init = 1.5; % 初始响度 r_init = 0.5; % 初始脉冲率 alpha = 0.95; % 响度衰减系数 gamma = 0.1; % 脉冲率增长系数 D = num_candidate_centers; % 解向量维度等于候选中心数量 %% 3. 数据生成函数 function problem_data = generate_synthetic_problem_data(num_centers, num_demands) % 随机生成配送中心和需求点坐标 city_size = 100; center_coords = rand(num_centers, 2) * city_size; demand_coords = rand(num_demands, 2) * city_size; main_hub_coord = [city_size/2, city_size/2]; % 计算配送中心到需求点的距离矩阵 dist_matrix_cd = pdist2(center_coords, demand_coords); % 计算配送中心到物流中心的距离 dist_to_hub = pdist2(center_coords, main_hub_coord); % 内部需求运输成本 (成本 = 固定 + 单位距离成本 * 距离 * 随机扰动) base_cost_a = 20; km_cost_a = 1.5; problem_data.cost_transport_internal_a = base_cost_a + km_cost_a * dist_matrix_cd ... .* (1 + 0.2*(rand(num_centers, num_demands) - 0.5)); % 外部需求运输成本 base_cost_b = 30; km_cost_b = 2.0; problem_data.cost_transport_external_b = base_cost_b + km_cost_b * dist_matrix_cd ... .* (1 + 0.2*(rand(num_centers, num_demands) - 0.5)); % 各需求点的内部和外部需求量 problem_data.demand_internal_x = rand(1, num_demands) * 0.2 + 0.05; problem_data.demand_external_w = rand(1, num_demands) * 0.8 + 0.2; % 每个中心的单位仓储成本 problem_data.unit_storage_cost_C = rand(num_centers, 1) * 0.5 + 1.5; % 固定建设成本 (随机整数) problem_data.annual_fixed_cost_F = randi([30, 60], num_centers, 1); % 轨道建设成本 (按距离 hub 并摊销到年) track_cost_per_km = 30000; num_years = 40; problem_data.annual_track_cost_P = (dist_to_hub * track_cost_per_km * 2) / num_years; % 保存坐标信息 problem_data.center_coords = center_coords; problem_data.demand_coords = demand_coords; problem_data.main_hub_coord = main_hub_coord; % 保存维度信息 problem_data.num_dist_centers = num_centers; problem_data.num_demand_points = num_demands; end CostFunction = @(x) calculate_capacitated_cost(x, problem); function problem_data = generate_capacitated_problem_data(num_centers, num_demands) % 调用 generate_synthetic_problem_data 生成基本数据 problem_data = generate_synthetic_problem_data(num_centers, num_demands); % 计算所有需求点的总需求量 total_demand = sum(problem_data.demand_internal_x) + sum(problem_data.demand_external_w); % 定义容量区间 min_capacity_per_center = total_demand / num_centers * 1.5; % 下界 max_capacity_per_center = total_demand / num_centers * 3.0; % 上界 % 随机生成各中心的最大容量 problem_data.max_capacity = rand(num_centers, 1) * ... (max_capacity_per_center - min_capacity_per_center) + min_capacity_per_center; % 确保总体容量充足:若总容量不足总需求 1.2 倍,则扩大容量 while sum(problem_data.max_capacity) < total_demand * 1.2 problem_data.max_capacity = problem_data.max_capacity * 1.1; end end %% 4. 运行两种算法 disp('----------------------------------------------------'); disp('正在运行【优化前】的基础蝙蝠算法 (BA)...'); [BestSol_BA, BestCost_BA, CostCurve_BA] = bat_algorithm(nPop, MaxIt, fmin, fmax, A_init, r_init, alpha, gamma, D, CostFunction); fprintf('BA 找到的最优成本: %.2f (万元)\n', BestCost_BA); disp('----------------------------------------------------'); disp('正在运行【文献】的改进蝙蝠算法 (IBA)...'); [BestSol_IBA, BestCost_IBA, CostCurve_IBA] = iba_algorithm(nPop, MaxIt, fmin, fmax, A_init, r_init, alpha, gamma, D, CostFunction); fprintf('IBA 找到的最优成本: %.2f (万元)\n', BestCost_IBA); %% 5. 绘制收敛曲线 % 统一所有图的 Y 轴范围 all_costs = [CostCurve_BA(CostCurve_BA < inf); CostCurve_IBA(CostCurve_IBA < inf)]; y_min_limit = min(all_costs) * 0.98; y_max_limit = max(all_costs) * 1.02; figure('Name', '算法收敛曲线对比'); hold on; plot(CostCurve_BA, 'r-', 'LineWidth', 3); plot(CostCurve_IBA, 'g-', 'LineWidth', 3); hold off; legend({'BA','IBA'}, 'Location', 'best'); title('两种算法收敛曲线比较'); xlabel('迭代次数'); ylabel('总成本 (万元)'); grid on; ax = gca; ax.YAxis.Exponent = 0; ytickformat('%,.0f'); ylim([y_min_limit, y_max_limit]); drawnow; %% 6. 最终结果输出 disp('====================== 最终结果输出 ======================'); [BestCost, best_alg_idx] = min([BestCost_BA, BestCost_IBA]); alg_names = {'【优化前】的BA算法', '【文献】的IBA算法'}; fprintf('在两个算法中,%s 找到了最优的解。\n', alg_names{best_alg_idx}); if best_alg_idx == 1 BestSol = BestSol_BA; else BestSol = BestSol_IBA; end if BestCost == inf disp('警告:所有算法均未能找到任何可行解!'); else fprintf('最优总成本: %.2f (万元)\n', BestCost); fprintf('选择的配送中心数量: %d\n', sum(BestSol)); fprintf('选择的配送中心编号: %s\n\n', mat2str(find(BestSol))); try generate_allocation_summary(BestSol, problem, CostFunction); catch ME if strcmp(ME.identifier, 'MATLAB:TooManyOutputs') disp(' '); disp('提示:generate_allocation_summary 需要成本函数返回额外信息。'); disp('请确保 calculate_capacitated_cost 函数的返回形式为:'); disp('[total_cost, allocation_map, goods_per_active_center] = ...'); else rethrow(ME); end end % 导出最佳解决方案中的需求中心分配表 try [~, allocation_map] = calculate_capacitated_cost(BestSol, problem); demand_ids = (1:problem.num_demand_points)'; mapping_table = table(demand_ids, allocation_map', ... 'VariableNames', {'需求点编号','配送中心编号'}); writetable(mapping_table, 'best_allocation_map.csv'); fprintf('已将最优方案的需求点与配送中心对应关系保存至 best_allocation_map.csv\n'); catch ME disp('无法导出最优方案的需求–中心对应表:'); disp(ME.message); end end %% 7. 辅助函数 function [total_cost, allocation_map, goods_per_active_center] = calculate_capacitated_cost(solution, problem) % 计算二进制解向量的总成本,并返回分配信息 allocation_map = []; goods_per_active_center = []; active_centers_idx = find(solution == 1); % 若没有选择任何中心,则返回无穷成本以表示不可行 if isempty(active_centers_idx) total_cost = inf; return; end num_active_centers = length(active_centers_idx); capacity_remaining = problem.max_capacity(active_centers_idx); % 每个需求点总需求量(内部 + 外部) total_goods_per_demand = problem.demand_internal_x + problem.demand_external_w; % 1. 计算每个中心向每个需求点的单位运输成本 unit_transport_cost = (problem.cost_transport_internal_a(active_centers_idx, :) ... .* problem.demand_internal_x + ... problem.cost_transport_external_b(active_centers_idx, :) ... .* problem.demand_external_w) ./ total_goods_per_demand; % 2. 创建并排序所有可能的分配 (配送中心编号, 需求编号, 单位成本) [center_indices, demand_indices] = meshgrid(1:num_active_centers, 1:problem.num_demand_points); allocation_list = [center_indices(:), demand_indices(:)]; costs_flat = unit_transport_cost'; allocation_list(:, 3) = costs_flat(:); % 按成本升序排列 [~, sorted_idx] = sort(allocation_list(:, 3)); sorted_allocations = allocation_list(sorted_idx, :); % 3. 逐一进行分配,检查容量约束 demand_assigned = false(1, problem.num_demand_points); goods_per_active_center = zeros(num_active_centers, 1); total_transport_cost = 0; allocation_map = zeros(1, problem.num_demand_points); for k = 1:size(sorted_allocations, 1) local_center_idx = sorted_allocations(k, 1); demand_idx = sorted_allocations(k, 2); if ~demand_assigned(demand_idx) demand_volume = total_goods_per_demand(demand_idx); if capacity_remaining(local_center_idx) >= demand_volume % 执行分配 demand_assigned(demand_idx) = true; capacity_remaining(local_center_idx) = capacity_remaining(local_center_idx) - demand_volume; goods_per_active_center(local_center_idx) = goods_per_active_center(local_center_idx) + demand_volume; allocation_map(demand_idx) = active_centers_idx(local_center_idx); % 累加该次分配的运输成本 transport_cost_this_alloc = ... (problem.cost_transport_internal_a(active_centers_idx(local_center_idx), demand_idx) ... * problem.demand_internal_x(demand_idx) + ... problem.cost_transport_external_b(active_centers_idx(local_center_idx), demand_idx) ... * problem.demand_external_w(demand_idx)); total_transport_cost = total_transport_cost + transport_cost_this_alloc; end end end % 4. 检查可行性:若仍有未分配的需求,则解不可行 if ~all(demand_assigned) total_cost = inf; allocation_map = []; goods_per_active_center = []; return; end % 5. 计算仓储成本与建设成本 active_storage_costs = problem.unit_storage_cost_C(active_centers_idx); total_storage_cost = sum(goods_per_active_center .* active_storage_costs); active_fixed_costs = problem.annual_fixed_cost_F(active_centers_idx); active_track_costs = problem.annual_track_cost_P(active_centers_idx); total_construction_cost = sum(active_fixed_costs) + sum(active_track_costs); % 6. 总成本(万元) total_cost = total_transport_cost + total_storage_cost + total_construction_cost; end function generate_allocation_summary(solution, problem, CostFunction) % 根据成本函数计算分配结果,输出每个选中配送中心的服务情况 [~, allocation_map, goods_per_active_center] = CostFunction(solution); active_centers_idx = find(solution == 1); if isempty(active_centers_idx) disp('没有选择任何配送中心。'); return; end disp('各选定配送中心的分配情况 (带容量利用率):'); disp(repmat('-', 1, 80)); fprintf('%-10s | %-15s | %-15s | %-15s | %-15s\n', '配送中心ID', '服务的需求点数', '总处理货量', '最大容量', '容量利用率'); disp(repmat('-', 1, 80)); for i = 1:length(active_centers_idx) center_id = active_centers_idx(i); num_served = sum(allocation_map == center_id); total_volume = goods_per_active_center(i); max_cap = problem.max_capacity(center_id); utilization = total_volume / max_cap * 100; fprintf('%-10d | %-15d | %-15.2f | %-15.2f | %-15.2f%%\n', center_id, num_served, total_volume, max_cap, utilization); end disp(repmat('-', 1, 80)); end %% 8. 基础的蝙蝠算法(BA) function [BestSol, BestCost, CostCurve] = bat_algorithm(nPop, MaxIt, fmin, fmax, A_init, r_init, alpha, gamma, D, CostFunction) % 基础蝙蝠算法(BA)的实现 vel = zeros(nPop, D); pos = rand(nPop, D) > 0.5; cost = zeros(nPop, 1); for i = 1:nPop cost(i) = CostFunction(pos(i, :)); end [BestCost, BestIdx] = min(cost); BestSol = pos(BestIdx, :); A = ones(nPop, 1) * A_init; r = ones(nPop, 1) * r_init; CostCurve = zeros(MaxIt, 1); for it = 1:MaxIt for i = 1:nPop beta = rand; freq = fmin + (fmax - fmin) * beta; vel(i, :) = vel(i, :) + (pos(i, :) - BestSol) * freq; new_pos_continuous = pos(i, :) + vel(i, :); % 采用 Sigmoid 变换将连续值转换为二进制值 new_pos = (1 ./ (1 + exp(-new_pos_continuous))) > rand(1, D); % 在全局最优值周围进行局部随机移动 if rand < r(i) k = randperm(D, max(1, round(0.1*D))); new_pos_local = BestSol; new_pos_local(k) = 1 - new_pos_local(k); new_pos = new_pos_local; end new_cost = CostFunction(new_pos); if new_cost < cost(i) && rand < A(i) pos(i, :) = new_pos; cost(i) = new_cost; A(i) = alpha * A(i); r(i) = r_init * (1 - exp(-gamma * it)); end if cost(i) < BestCost BestCost = cost(i); BestSol = pos(i, :); end end CostCurve(it) = BestCost; if BestCost ~= inf fprintf('BA Iteration %d/%d, Best Cost = %.2f\n', it, MaxIt, BestCost); end end end %% 9. 莱维飞行函数 function s = levy(d) % 生成莱维飞行步长 beta = 1.5; sigma_u = (gamma(1 + beta) * sin(pi * beta / 2) ... / (gamma((1 + beta) / 2) * beta * 2^((beta - 1) / 2)))^(1 / beta); sigma_v = 1; u = random('Normal', 0, sigma_u, 1, d); v = random('Normal', 0, sigma_v, 1, d); s = u ./ (abs(v).^(1 / beta)); end %% 10. 基于莱维飞行改进的蝙蝠算法(IBA) function [BestSol, BestCost, CostCurve] = iba_algorithm(nPop, MaxIt, fmin, fmax, A_init, r_init, alpha, gamma, D, CostFunction) % 改进蝙蝠算法(IBA),引入莱维飞行策略 pos = rand(nPop, D) > 0.5; cost = zeros(nPop, 1); for i = 1:nPop cost(i) = CostFunction(pos(i, :)); end [BestCost, BestIdx] = min(cost); BestSol = pos(BestIdx, :); A = ones(nPop, 1) * A_init; r = ones(nPop, 1) * r_init; CostCurve = zeros(MaxIt, 1); scale_factor = 0.01; for it = 1:MaxIt for i = 1:nPop levy_step = levy(D); new_pos_continuous = pos(i,:) + scale_factor * levy_step .* (BestSol - pos(i,:)); new_pos = (1 ./ (1 + exp(-new_pos_continuous))) > rand(1, D); if rand < r(i) k = randperm(D, max(1, round(0.1*D))); new_pos_local = BestSol; new_pos_local(k) = 1 - new_pos_local(k); new_pos = new_pos_local; end new_cost = CostFunction(new_pos); if new_cost < cost(i) && rand < A(i) pos(i, :) = new_pos; cost(i) = new_cost; A(i) = alpha * A(i); r(i) = r_init * (1 - exp(-gamma * it)); end if cost(i) < BestCost BestCost = cost(i); BestSol = pos(i, :); end end CostCurve(it) = BestCost; if BestCost ~= inf fprintf('IBA Iteration %d/%d, Best Cost = %.2f\n', it, MaxIt, BestCost); end end end %% 11. 将合成数据导出为csv function save_problem_data_to_csv(problem) % 配送中心信息 num_centers = problem.num_dist_centers; center_id = (1:num_centers)'; center_x = problem.center_coords(:,1); center_y = problem.center_coords(:,2); max_capacity = problem.max_capacity; unit_storage_cost = problem.unit_storage_cost_C; annual_fixed_cost = problem.annual_fixed_cost_F; annual_track_cost = problem.annual_track_cost_P; centers_table = table(center_id, center_x, center_y, max_capacity, unit_storage_cost, annual_fixed_cost, annual_track_cost, ... 'VariableNames', {'配送中心编号','X轴','Y轴','最大容量','单位储存费用','年度固定成本','年度运营成本'}); writetable(centers_table, 'centers_data.csv'); % 需求点信息 num_demands = problem.num_demand_points; demand_id = (1:num_demands)'; demand_x = problem.demand_coords(:,1); demand_y = problem.demand_coords(:,2); internal_demand = problem.demand_internal_x'; external_demand = problem.demand_external_w'; total_demand = internal_demand + external_demand; demand_table = table(demand_id, demand_x, demand_y, internal_demand, external_demand, total_demand, ... 'VariableNames', {'需求点编号','X轴','Y轴','内部需求量','外部需求量','总需求量'}); writetable(demand_table, 'demands_data.csv'); fprintf('已将随机生成的配送中心和需求点数据分别保存至 centers_data.csv 和 demands_data.csv\n'); end %% 12. 导出配送中心 - 需求成本矩阵 function save_center_demand_cost_matrix(problem) num_centers = problem.num_dist_centers; num_demands = problem.num_demand_points; rows = num_centers * num_demands; data = zeros(rows, 5); idx = 1; for c = 1:num_centers for d = 1:num_demands dist_cd = pdist2(problem.center_coords(c, :), problem.demand_coords(d, :)); internal_cost = problem.cost_transport_internal_a(c, d); external_cost = problem.cost_transport_external_b(c, d); data(idx, :) = [c, d, dist_cd, internal_cost, external_cost]; idx = idx + 1; end end % Convert to table with descriptive headers tbl = array2table(data, 'VariableNames', ... {'配送中心编号','需求点编号','配送中心与需求点之间的距离', ... '内部运输成本','外部运输成本'}); writetable(tbl, 'center_demand_cost_data.csv'); fprintf('已将配送中心–需求点成本矩阵保存为 center_demand_cost_data.csv\n'); end 转化为python代码
11-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值