lingo旅行商问题代码

本文展示了如何用LINGO模型解决经典的旅行商问题。通过定义城市、距离矩阵和二进制变量,来最小化旅行路径总距离。模型中包含了进入、离开每个城市的约束条件,并确保城市间的级别关系。此外,还设置了变量的0/1约束,以确保解决方案的可行性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

旅行商问题:
MODEL:
sets:
cities/1..10/:level; !level(i)= the level of city;
link(cities, cities):
distance, !The distance matrix;
x; ! x(i,j)=1 if we use link i,j;
endsets
data: !Distance matrix, it need not be symmetirc;
distance = 0 8 5 9 12 14 12 16 17 22
8 0 9 15 16 8 11 18 14 22
5 9 0 7 9 11 7 12 12 17
9 15 7 0 3 17 10 7 15 15
12 16 9 3 0 8 10 6 15 15
14 8 11 17 8 0 9 14 8 16
12 11 7 10 10 9 0 8 6 11
16 18 12 7 6 14 8 0 11 11
17 14 12 15 15 8 6 11 0 10
22 22 17 15 15 16 11 11 10 0;
enddata
n=@size(cities); !The model size;
! Minimize total distance of the links;
min=@sum(link(i,j)|i #ne# j: distance(i,j)*x(i,j));
!For city i;
@for(cities(i) :
! It must be entered;
@sum(cities(j)| j #ne# i: x(j,i))=1;
! It must be departed;
@sum(cities(j)| j #ne# i: x(i,j))=1;
! level(j)=levle(i)+1, if we link j and i;
@for(cities(

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值