File: testpplpy2.pyx

package info (click to toggle)
pplpy 0.8.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 532 kB
  • sloc: python: 306; makefile: 39; cpp: 21; sh: 2
file content (47 lines) | stat: -rw-r--r-- 1,278 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
The goal of this file is to test cython can use pplpy package properly
In order to do this we do some test with objects from each packages and extension :
ppl
ppl.linear_algebra
ppl.linear_algebra
ppl.constraint
ppl.mip_problem
"""

from ppl.linear_algebra cimport Variable
from ppl.constraint cimport Constraint_System
from ppl.mip_problem cimport MIP_Problem
from ppl.polyhedron cimport C_Polyhedron

def test():
    x = Variable(0)
    y = Variable(1)
    cs = Constraint_System()
    cs.insert( x >= 0)
    cs.insert( y >= 0 )
    cs.insert( 3 * x + 5 * y <= 10 )
    m = MIP_Problem(2, cs, x + y)
    m.objective_function()

    from ppl import C_Polyhedron
    C_Polyhedron( 5*x-2*y >=  x+y-1 )

    print("-"*80)
    print("Cython test 2 OK")
    print("-"*80)

def example():
    "Cython version of the example from the README"
    cdef Variable x = Variable(0)
    cdef Variable y = Variable(1)
    cdef Variable z = Variable(2)
    cdef Constraint_System cs = Constraint_System()
    cs.insert(x >= 0)
    cs.insert(y >= 0)
    cs.insert(x + y + z == 1)
    cdef C_Polyhedron poly = C_Polyhedron(cs)
    print(poly.minimized_generators())
    print('dim = %lu' % poly.thisptr.space_dimension())
    print("-"*80)
    print("Cython example 2 OK")
    print("-"*80)