# Compute profile and wavefront
rinfo = _mc60.mc60fd(n, irn, icptr[:nsup + 1], vars[:nsup], permsv)

# Obtain variable permutation from supervariable permutation
perm, possv = _mc60.mc60dd(svar, vars[:nsup], permsv)

np.set_printoptions(precision=3, linewidth=80, threshold=10, edgeitems=3)
print 'The variable permutation is ', perm
print 'The profile is ', rinfo[0]
print 'The maximum wavefront is ', rinfo[1]
print 'The semibandwidth is ', rinfo[2]
print 'The root-mean-square wavefront is ', rinfo[3]

try:
    import pylab
    from pyorder.tools.spy import fast_spy
    # Plot original matrix
    (_, irow, jcol) = M.find()
    left = pylab.subplot(121)
    right = pylab.subplot(122)
    fast_spy(M.nrow, M.ncol, irow, jcol, sym=M.issym,
             ax=left.get_axes(), title='Original')

    # Apply permutation and plot reordered matrix
    perm -= 1   # Convert to 0-based indexing
    fast_spy(M.nrow, M.ncol, perm[irow], perm[jcol], sym=M.issym,
             ax=right.get_axes(), title='Reordered')
    pylab.show()
except:
    pass
Esempio n. 2
0
import matplotlib.pyplot as plt
import os

this_path = os.path.dirname(os.path.realpath(__file__))

model = AmplModel(os.path.join(this_path, 'truss18bars.nl'))
x = np.random.random(model.n)
y = np.random.random(model.m)
(val, irow, jcol) = model.hess(x, y)
(rowind, colptr, values) = coord2csc(model.n, irow, jcol, val)  # Convert to CSC

perm1, rinfo1 = rcmk(model.n, rowind, colptr)   # Reverse Cuthill-McKee
perm2, rinfo2 = sloan(model.n, rowind, colptr)  # Sloan's method

left = plt.subplot(131)
fast_spy(model.n, model.n, irow, jcol, sym=True,
         ax=left.get_axes(), title='Original')

# Apply permutation 1 and plot reordered matrix
middle = plt.subplot(132)
fast_spy(model.n, model.n, perm1[irow], perm1[jcol], sym=True,
         ax=middle.get_axes(), title='Rev. Cuthill-McKee (semibandwidth=%d)' % rinfo1[2])

# Apply permutation 2 and plot reordered matrix
right = plt.subplot(133)
fast_spy(model.n, model.n, perm2[irow], perm2[jcol], sym=True,
         ax=right.get_axes(), title='Sloan (semibandwidth=%d)' % rinfo2[2])

# plt.savefig('mpvc.pdf',bbox_inches='tight')
plt.show()