24小时热门版块排行榜    

查看: 1438  |  回复: 0

ysp24

铁杆木虫 (小有名气)

[求助] C# 调用CPlex 关于冲突检测RefineConflict的问题?急死了!

如题,在网上查到的代码如下(用户手册中内容与此差不多):
if (cplex.RefineConflict(constraints,prefs))
  {
      Cplex.ConflictStatus[] conflicts = cplex.GetConflict(constraints);
      for (int i = 0; i < conflicts.Length;i++ )
      {
          if (conflicts==Cplex.ConflictStatus.Member)
          System.Console.WriteLine(" Proved : " + constraints);
          else if (conflicts==Cplex.ConflictStatus.PossibleMember)
          System.Console.WriteLine(" Possible : " + constraints);
     }
}

上述代码中的constraints,prefs怎么定义,以及其值是什么,我没弄明白。参考上述代码,我自己写的冲突检测代码一直有误,输出结果全部是Possible的类型。具体代码如下,请大家帮忙:

INumVar[][] var = new INumVar[1][];//用于求解后调用或查看结果
IRange[][] rng = new IRange[1][];//用于求解后调用或查看松弛程度
private string[] xt;
INumVar[] x;

建立优化目标:
xt = new string[i_Dvar];
var[0] = new INumVar[i_Dvar];
for (int i = 0; i < xt.Length; i++)
     {
          xt = NumVarType.Float.ToString();
      }

x = cplex.NumVarArray(i_Dvar, intArr_Object_Lower, intArr_Object_Upper, xt);//添加决策变量

var[0] = x;//加引用(指针变化),两个可以等同
cplex.AddMinimize(cplex.ScalProd(x, intArr_Object));//添加优化目标

建立约束:
rng[0] = new IRange[i_Num_le_eq];//i_Num_le_eq为约束总数
for (int j = 0; j < A1_le.Length; j++)//不等式约束
   {
           rng[0][j] = (cplex.AddLe(cplex.ScalProd(x, A1_le[j]), b1_le[j]));
    }
......

冲突检测:
IConstraint[] constraints = new IConstraint[rng[0].Length];
double[] prefs = new double[constraints.Length]; //一直不清楚prefs 做什么用的
constraints = rng[0];
            
if (cplex.RefineConflict(constraints,prefs))
      {
                 Cplex.ConflictStatus[] conflicts = cplex.GetConflict(constraints);
                 for (int i = 0; i < conflicts.Length; i++)
                {
                    if (conflicts == Cplex.ConflictStatus.Member)
                    {
                        System.Console.WriteLine(" Proved : " + constraints);
                    }
                    else if (conflicts == Cplex.ConflictStatus.PossibleMember)
                    {
                        System.Console.WriteLine(" Possible : " + constraints);
                    }
                }
     }

检测输出的结果是所有的约束全部输出,且都属于Possible 。肯定是不对了。但自己调好久一直没成功,很着急,请大家帮忙呀!!!!!谢谢!!
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 ysp24 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 科研孤儿太难了 +14 我4大白菜 2026-08-20 15/750 2026-08-20 22:33 by 袁向阳007
[基金申请] 让我中一个面上吧! +8 大萍1987 2026-08-20 10/500 2026-08-20 21:48 by 大萍1987
[基金申请] 言之凿凿,明天官网会通知放榜? +15 医学老男孩 2026-08-20 17/850 2026-08-20 20:35 by CaoLG
[基金申请] 时间戳又变了 +12 wuchongjun 2026-08-20 17/850 2026-08-20 20:05 by spzhao
[基金申请] 今天系统多次维护,明天很可能放榜! +10 zju2000 2026-08-16 11/550 2026-08-20 20:02 by cl479861084
[基金申请] 时间戳变了,能看出什么问题? +18 基诺咪客 2026-08-17 23/1150 2026-08-20 17:19 by Godzela
[基金申请] 只有每年这种时候来逛逛小木虫 +21 yaoyewhu2008 2026-08-20 22/1100 2026-08-20 17:03 by yaoyewhu2008
[基金申请] 放榜前的不淡定 40+3 snowwithsea 2026-08-19 12/600 2026-08-20 15:56 by lfy8008
[基金申请] 重要消息,中午系统在维护 +11 yuleib84 2026-08-18 12/600 2026-08-20 11:09 by xskun
[基金申请] 今天基金会出结果吗?20260819 +14 kkkl_v 2026-08-19 15/750 2026-08-20 08:21 by sunzitan
[教师之家] 为什么余额宝的年化利率越来越低?主要原因有哪些? +5 瞬息宇宙 2026-08-15 5/250 2026-08-19 20:23 by super2002521
[基金申请] 今天放榜吗? +14 布布和一二 2026-08-19 15/750 2026-08-19 18:07 by gltch
[基金申请] filecode=后面第一个是大写字母 +10 wangze12014 2026-08-14 12/600 2026-08-19 16:56 by 苦难博士
[基金申请] 什么时候开奖? +6 CrisMessi 2026-08-18 6/300 2026-08-19 08:06 by Equinoxhua
[论文投稿] 投稿咨询 +4 wwm09 2026-08-17 6/300 2026-08-18 15:36 by wwm09
[基金申请] 时间戳又变了8-15 +14 archvillain 2026-08-15 26/1300 2026-08-18 13:37 by phantomgost
[基金申请] 今天维护系统维护 祝所有人 高中 +8 gjjjzhong 2026-08-18 9/450 2026-08-18 13:01 by 家与远方
[基金申请] 93BebMhtakh前后11位开头都是大写 +4 且听虎啸 2026-08-17 5/250 2026-08-18 00:49 by 蔡棒棒菂
[精细化工] 招聘 金属平磨液,抛光液研发工程师 +3 小天0311 2026-08-14 3/150 2026-08-16 07:31 by H9PLUS
[基金申请] 各位道友,我要去昆明玩几天,回来见。 +7 Tide man 2026-08-14 8/400 2026-08-15 01:11 by arzu_hma
信息提示
请填处理意见