您好!我正在尝试编写一个模型来解决 AMPL 中的最小成本问题,但是我不断收到关于 exeprion on origin 和 dest

问题描述 投票:0回答:0

我是 AMPL 的新手,正在尝试制作一个简单的 MC 问题模型,但我有很多错误,我无法理解如何解决它们。 我在我的模型下面附上了一个数据。 也许有人可以帮助理解什么是错的?

set NODES;  #diefine set of nodes
set ARCS within {NODES, NODES};
set COMMODITIES {NODES};
param quantity{COMMODITIES};
param origin{COMMODITIES};
param dest{COMMODITIES};
param cap{ARCS} >= 0;
param cost{ARCS} >= 0;


# Decision Variables
var x{(u,v,k) in ARCS cross COMMODITIES} binary;  #flow assos with commodity k on the acrs

# Objective Function
minimize Total_Cost:
   sum {(u,v) in ARCS, k in COMMODITIES}
      cost [u,v] *x[u,v,k];
      
# Capacity constraints
subject to c1 {(u,v) in ARCS}:
    sum{(u,v,k) in ARCS cross COMMODITIES} 
    x[u,v,k] <= cap[u,v];
    
#Flow conservation constraints
subject to c2 {u in NODES exept {orgin, dest}, k in COMMODITIES}:
    sum{(v,u) in ARCS} x[v,u,k] - sum{(u,v) in ARCS} x[u,v,k] = 0;
    
    
# Source and sink constraints
subject to c5{k in COMMODITIES, v in NODES exept {orgin,dest}}:
    sum{(u,v) in ARCS} x[u,v,k] - sum{(v,u) in ARCS} x[v,u,k] =
        if v = orgin then +quantity[k] else if v = dest then -quantity[k] else 0;  
        
# Non-negativity constraints
subject to c3 {(u,v,k) in ARCS cross COMMODITIES}:
    x[u,v,k] >= 0;
 
      
data;

set NODES := 1 2 3 4 5 6;

param: ARCS: cap cost :=
        1,2   15    3
        2,3   1     6
        3,4   6     3
        4,1   6     8
        2,4   10    4
        2,5   10    4
        5,6   10    4
        5,3   4     12
        3,6   7     8
        4,6   8     10;

param COMMODITIES: orgin dest quantity :=
        1           3    5      6
        2           1    6      4

我试过单独定义约束,但没有用。

ampl
© www.soinside.com 2019 - 2024. All rights reserved.