首页 > 解决方案 > 在 eplex 库中是否对模运算有任何明确的支持

问题描述

我正在使用eplexic图书馆并试图解决一个问题。我看到and 为eplexandic提供了明确的支持addition,multiplicationsubtraction但不支持moduloor division

更准确地说,我有这个代码:

    FirstResult #=  (Result[I] mod Val), % Here it gives error because Result[I] is not instantiated.
    NewVal is Val+1,
    SecondResult #= (Result[I] mod NewVal)

并且mod要求它的两个参数是接地的,但Result[I]没有实例化,而是具有值范围。所以我的问题是如何延迟这种涉及mod操作的约束。

标签: prologconstraintseclipse-clp

解决方案


您通常可以重新制定

R #= X mod Y

作为

0 #=< R, R #=< Y-1,      %  R is between 0 and Y-1
X #= _*Y + R,            %  X is some multiple of Y, plus a remainder R

这假设您正在使用library(ic)并且您对带有否定参数的行为没有任何特殊要求。

对于library(eplex)使用 MILP 求解器的 ,您几乎可以执行相同的操作(只要 Y 是整数参数),但您必须更加明确地了解完整性:

0 $=< R, R $=< Y-1,
integers([K,R]),
X $= K*Y + R,

推荐阅读