如何处理Minizinc中图中的边缘重量?

发布于 2025-01-26 21:35:58 字数 2004 浏览 2 评论 0 原文

我的任务如下图:

”在此处输入图像说明“

我需要代码在leinizinc中使用solver放置问题的优化模型,也就是说,求解给出了a 放置策略以指示哪个主机应该 a,b,c 放置。

我面对的chanllenge之一是限制资源要求不超过资源。

我这样做了:

int: numHosts = 5;
set of int: hosts = 1..numHosts;

int: numRel = 2;
set of int: relindx = 1..numRel;
array[relindx] of int: preNode = [1, 1];    % edge (1, 2), (2, 3) a=1, b=2, c=3
array[relindx] of int: postNode = [2, 3];

int: sliceLen = 3;
set of int: sSlice = 1..sliceLen;
array[sSlice] of int: slice = [1, 2, 3];  % a, b, c

int: numVnfs = 5;  % types of rectangle(a, b, c, d, e)
set of int: vnfs = 1..numVnfs;
array[vnfs, vnfs] of int: bandwidth_resource = array2d(1..numHosts, 1..numHosts, [0,0,30,0,0, 0,0,35,0,30, 30,35,0,0,40, 0,0,0,0,35, 0,30,40,35,0]); % array2d save the edge resources
array[vnfs, vnfs] of int: vnf_bandwidth = array2d(1..numVnfs, 1..numVnfs, [0,2,2,4,4, 2,0,3,4,2, 2,3,0,4,3, 4,4,4,0,2, 4,2,3,2,0]); % array2d save the source requirement of rectangle

% DECISION VARIABLES
array[sSlice] of var hosts: placement;
array[vnfs, vnfs] of var int: bandwidth_used;

% CONSTRAINTS
constraint forall(host1 in hosts, host2 in hosts)
(
  bandwidth_used[host1, host2] = sum(c1 in preNode, c2 in postNode where placement[c1] = host1 /\ placement[c2] = host2) (vnf_bandwidth[c1, c2])
);

constraint forall(vnf in vnfs)
(
    bandwidth_used[vnf, vnf] <= bandwidth_resource[vnf, vnf]
);

现在,首先问题是求解器可以给出一个零件,但是 bandwidth_used_used connot可以协调地计算。

第二问题是如何 sum 使用主机未直接收集的资源

,例如在图矩形 a 放置在 host1 和矩形 b host2 上Edge (host1,host3) 和edge (host2,host3)

你能帮我吗?

I have a task like the follow figure:

enter image description here

I need code a optimization model in Minizinc to solver placement problem, that is, solve give a placement strategy to indicate which Host should a, b, c to place.

One of the chanllenge that I faced is the constraint that the resource requirement do not exceed the resource.

I did it like:

int: numHosts = 5;
set of int: hosts = 1..numHosts;

int: numRel = 2;
set of int: relindx = 1..numRel;
array[relindx] of int: preNode = [1, 1];    % edge (1, 2), (2, 3) a=1, b=2, c=3
array[relindx] of int: postNode = [2, 3];

int: sliceLen = 3;
set of int: sSlice = 1..sliceLen;
array[sSlice] of int: slice = [1, 2, 3];  % a, b, c

int: numVnfs = 5;  % types of rectangle(a, b, c, d, e)
set of int: vnfs = 1..numVnfs;
array[vnfs, vnfs] of int: bandwidth_resource = array2d(1..numHosts, 1..numHosts, [0,0,30,0,0, 0,0,35,0,30, 30,35,0,0,40, 0,0,0,0,35, 0,30,40,35,0]); % array2d save the edge resources
array[vnfs, vnfs] of int: vnf_bandwidth = array2d(1..numVnfs, 1..numVnfs, [0,2,2,4,4, 2,0,3,4,2, 2,3,0,4,3, 4,4,4,0,2, 4,2,3,2,0]); % array2d save the source requirement of rectangle

% DECISION VARIABLES
array[sSlice] of var hosts: placement;
array[vnfs, vnfs] of var int: bandwidth_used;

% CONSTRAINTS
constraint forall(host1 in hosts, host2 in hosts)
(
  bandwidth_used[host1, host2] = sum(c1 in preNode, c2 in postNode where placement[c1] = host1 /\ placement[c2] = host2) (vnf_bandwidth[c1, c2])
);

constraint forall(vnf in vnfs)
(
    bandwidth_used[vnf, vnf] <= bandwidth_resource[vnf, vnf]
);

Now, the First question is solver can give a plecement but bandwidth_used connot calculate coorectly.

the second question is how to sum the resource used that host do not conected directly

For example, in the figure rectangle a placed on Host1 and rectangle b placed on Host2, so the bandwidth_used should calculate the resource used in both edge (Host1, Host3) and edge (Host2, Host3).

Could you help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相思碎 2025-02-02 21:35:58

看来您的问题是带宽的通信约束的映射问题。实际上,映射到两个主机的两个任务之间的通信可以以不同的方式进行路由。您建议(host1,host3)和(host3,host2),但也可以将其路由(host1,host3),(host3,host5)和(host5,host2)。这可以通过网络流约束(每次通信的约束)来建模。有关更多详细信息,您可以在
希望它有帮助。

It seems that your problem is a mapping problem with communication constraints on bandwidth. Communication between two tasks mapped into two hosts can, in fact, be routed in different ways. You propose (Host1, Host3) and (Host3, Host2) but it can also be routed (Host1, Host3), (Host3, Host5) and (Host5, Host2). This can be modelled by network flow constraints (one constraint for each communication). For more details you can check our minizinc model in https://github.com/MiniZinc/minizinc-benchmarks/tree/master/mapping.
Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文