使用字符串索引参数进行线性编程??? [英] linear programming with string indexed parameters???

查看:86
本文介绍了使用字符串索引参数进行线性编程???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想使用线性编程模型实现最短路径算法。


我将输入一个包含节点和边缘的图形,它将返回一个短路径,根据


到距离或类似的东西。我已经设法使用
的$默认求解器为
$ MSF,但是如果我输入边缘和节点ID为整数,则可以使用。但我希望将ID作为字符串。


这个问题是,当我尝试创建模型的参数并试图出价


他们使用的词典我得到的边和节点不能将字符串


的索引应用于参数。

Hello, i want to implement a shortesst path algorithm using the linear programming model.
I will input a graph that holds nodes and edges and it will return a short path according
to distance or something similar. I have managed to make it work using te default solver of
MSF but onlly if i input the edges and node ids as ints. But i want to have ids as strings.
The problem with this is that when i try to create the parameters of the model and try to bid
them with the dictionaries that hold the edges and nodes i get cannot apply indexing of string
to parameters.

我想做的是:



参数from = new Parameter(Domain.Integer," from" edge);

from.SetBinding(g.Edges.Values,"Node1"," Name");


Parameter from = new Parameter(Domain.Integer,"from",edge);
from.SetBinding(g.Edges.Values, "Node1", "Name");

参数to = new parameter(Domain.IntegerNonnegative, "to","edge";
$
to.SetBinding(g.Edges.Values,"Node2"," Name");

Parameter to = new Parameter(Domain.IntegerNonnegative, "to", edge);
to.SetBinding(g.Edges.Values,"Node2", "Name");

参数节点名... ...
>> ..... edgename

Parameter nodename ...
>>.....edgename



这样我就可以检查节点是否可以形成与另一个边缘或节点是源或目标的边缘....

Model..Model.ForEach(节点,i =>
$
ForEachWhere(边缘, a =>赋值[a],a => Model.And(来自[a] == nodename [i],来自[a] ==源节点)))


So that i can check if a node can form an edge with another or if the node is the source or target....
Model..Model.ForEach(node, i =>
ForEachWhere(edge, a => assign[a], a => Model.And(to[a] == nodename[i], from[a] == source node)))

这有效,如果我有整数名称。我怎么能用字符串呢?用字典参数?什么?


我不想创建另一个id字段,因为它必须是唯一且令人困惑的。谢谢!!!!!?

This works if i haave integer Names. How can i do it with strings also? with dictionary parameters? anything??
i dont want to have to create another field of ids since it must be unique and confusing. Thanks!!!!!?

推荐答案

您是否尝试过从Domain.Integer更改为Domain.Any?那可能有用。否则,您只需使用标准的.Net Dictionary对象,并用循环替换ForEachWhere。

Have you tried changing from Domain.Integer to Domain.Any? That might work. Otherwise you can simply use a standard .Net Dictionary object and replace ForEachWhere with a loop.

Nate


这篇关于使用字符串索引参数进行线性编程???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆