【发布时间】:2015-04-02 14:21:20
【问题描述】:
在 Mathematica 中,我定义了以下内容,以尝试解决优化问题:
costVector := {710000, 610000, 650000, 910000, 720000, 570000}
cost[x_] := Total[IntegerDigits[x, 2, 6]*costVector]
coverage[x_] := coveragex @@ IntegerDigits[x, 2, 6]
coveragex[a_ , b_, c_, d_, e_, f_ ] :=
Complement[
Union[a*{4, 5, 6}, b*{1, 5}, c*{5, 6, 7}, d*{1, 3, 4, 7},
e*{2, 3, 5}, f*{2, 6}], {0}]
goal = {1, 2, 3, 4, 5, 6, 7}
总结问题:我想找到一个六位数的二进制值 x 使得 cost[x] 尽可能小,同时满足调用 coverage[x] 给出指定整数列表的标准目标。为了找到这个值,我尝试通过以下方式使用 NMinimize:
NMinimize[{cost[x], {(coverage[x]) == goal,
x <= 63, x >= 0}}, x]|
我的问题是我收到以下错误:
NMinimize::bcons: "The following constraints are not valid: {coveragex[x,2,6]==goal,x>=0,x<=63}. Constraints should be equalities, inequalities, or domain specifications involving the variables"
出于某种原因,Mathematica 似乎认为将 coverage[x] 与目标进行比较的约束不是相等的。我一直在扯头发试图找出原因。我只是犯了某种语法错误,还是我以不正确的方式使用 NMinimize?这是否可行?
【问题讨论】:
标签: math wolfram-mathematica mathematical-optimization