Home > Community > Forums > Custom IC SKILL > [permutation] how can I make all Instance combinations?

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 [permutation] how can I make all Instance combinations? 

Last post Thu, Nov 29 2012 6:09 AM by Andrew Beckett. 3 replies.
Started by pacowon 22 Nov 2012 04:07 AM. Topic has 3 replies and 796 views
Page 1 of 1 (4 items)
Sort Posts:
  • Thu, Nov 22 2012 4:07 AM

    • pacowon
    • Not Ranked
    • Joined on Thu, Nov 22 2012
    • Seoul, South Korea
    • Posts 2
    • Points 40
    [permutation] how can I make all Instance combinations? Reply

    Hi, I have a question with my skill language.

    I wanna make permutation list with plural cell Instances.

    For example , If I have a,b,c instances

     I wanna return list(a b c) list(a c b) list(b a c) list(b c a) list(c a b) list(c b a) => 3*2*1 lists!!

     I tried all day with

    procedure(permutaion(()

    prog(()

     Inst = list(a b c d)

    foreach(***********)

    )) but may be I'm not smart enogh to deal with this skill .....

     

    somebody help  me out...

    • Post Points: 20
  • Thu, Nov 22 2012 7:03 AM

    Re: [permutation] how can I make all Instance combinations? Reply

    Hopefully this code will help you:

    /* abPermutations.ils
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Mar 28, 2012 
    Modified   
    By         
    
    Generate permutations in lexical order
    
    Almost certainly there's a fancier way to do this...
    
    A few versions of doing this. One based on a perl algorithm (uses arrays), 
    and the second two are more LISPy ways of doing this
    Some of these functions require SKILL++ lexical scoping so please
    ensure file keeps the ".ils" suffix *************************************************** SCCS Info: @(#) abPermutations.ils 03/28/12.09:50:21 1.1 */
    (defun abPermutations (listOfObjects) (let (arrayOfObjects size indexArray) ;-------------------------------------------------------------------- ; Convert everything to arrays to allow faster manipulation ;-------------------------------------------------------------------- (setq arrayOfObjects (listToVector listOfObjects)) (setq size (sub1 (length arrayOfObjects))) (setq indexArray (makeVector (add1 size))) (for i 0 size (setarray indexArray i i)) ;-------------------------------------------------------------------- ; Local function to swap two array entries ;-------------------------------------------------------------------- (defun swap (a b) (let (tmp) (setq tmp (arrayref indexArray a)) (setarray indexArray a (arrayref indexArray b)) (setarray indexArray b tmp) ) ) ;-------------------------------------------------------------------- ; Local function that can be called recursively to generate permutations ;-------------------------------------------------------------------- (defun genPerm () (let ((k (sub1 size)) (j size) retVal) (setq retVal (foreach mapcar ind (vectorToList indexArray) (arrayref arrayOfObjects ind))) (while (and (geqp k 0) (greaterp (arrayref indexArray k) (arrayref indexArray (add1 k)))) (postdecrement k)) (if (minusp k) (list retVal) (progn (while (greaterp (arrayref indexArray k) (arrayref indexArray j)) (postdecrement j)) (swap j (postincrement k)) (setq j size) (while (greaterp j k) (swap (postdecrement j) (postincrement k)) ) (cons retVal (genPerm)) ) ) ) ) (genPerm) ) ) (defun abPerms (l) ;---------------------------------------------------------------------- ; Local function to remove only the first match in a list ; which means that it copes with repeated values in the list ;---------------------------------------------------------------------- (defun removeFirst (val l) (let (found) (setof elem l (cond (found t) ((equal val elem) (setq found t) nil) (t t) )))) (if (null l) '(nil) (mapcan (lambda (x) (mapcar (lambda (y) (cons x y)) (abPerms (removeFirst x l )))) l))) (defun abPermsUniqueList (l) (if (null l) '(nil) (mapcan (lambda (x) (mapcar (lambda (y) (cons x y)) (abPermsUniqueList (remove x l )))) l)))

     

    • Post Points: 20
  • Wed, Nov 28 2012 11:38 PM

    • pacowon
    • Not Ranked
    • Joined on Thu, Nov 22 2012
    • Seoul, South Korea
    • Posts 2
    • Points 40
    Re: [permutation] how can I make all Instance combinations? Reply

    Wow!!! Thanks!!

     

    This is exactily what I wanted!!

    • Post Points: 20
  • Thu, Nov 29 2012 6:09 AM

    Re: [permutation] how can I make all Instance combinations? Reply

    I just noticed that there's a typo in the comments of the file - it should really have a ".ils" suffix because some of the functions use SKILL++ lexical scoping - so my advice is that if you use this, please ensure that it has a .ils suffix.

    I'll edit the post with the code to make this clearer.

    Andrew.

    • Post Points: 5
Page 1 of 1 (4 items)
Sort Posts:
Started by pacowon at 22 Nov 2012 04:07 AM. Topic has 3 replies.