lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Mar 23, 2009 at 10:02 PM, Geoff Leyland wrote:
> On 24/03/2009, at 2:19 PM, David Manura wrote:
>> Here's a few alternatives:
>>
>>  a_constraint = le(2 * x1 + 3 * x2 + 4 * x3, 6)
>>  a_constraint = (2 * x1 + 3 * x2 + 4 * x3):le(6)
>>  a_constraint = Constraint[[2 * x1 + 3 * x2 + 4 * x3 <= 6]]

Also,

  a_constraint = expr(2 * x1 + 3 * x2 + 4 * x3, '<=', 6)
  a_constraint = (2 * x1 + 3 * x2 + 4 * x3) '<=' (6)
  a_constraint:add(2 * x1 + 3 * x2 + 4 * x3, '<=', 6)
  a_constraint(2 * x1 + 3 * x2 + 4 * x3, '<=', 6)

and, if even worth mentioning,

  local val
  local mt = {}
  function mt.__le(a,b) val = {'<=', a, b} end
  function mt.__tostring(a) return tostring(a.n) end
  local function C(n) return setmetatable({n=n}, mt) end
  local function compare(...) return val end

  local y = compare(C(2) <= C(3))

> Pulp[1] and pyomo[2] manage quite nicely in Python

since Python allows this:

  class A(object):
      def __init__(self, foo):
          self.foo = foo
      def __le__(self, other):
          return 'works!'
  print ( A(1) <= A(2) )  # print 'works!'