Permutation.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef _Permutation_h_
  2. #define _Permutation_h_
  3. /* Permutation.h
  4. *
  5. * Copyright (C) 2005-2018 David Weenink
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "Collection.h"
  21. #include "Permutation_def.h"
  22. /*
  23. Class invariant: any permutation equals the identity permutation after all its elements are sorted ascendingly.
  24. */
  25. void Permutation_init (Permutation me, integer numberOfElements);
  26. void Permutation_tableJump_inline (Permutation me, integer jumpSize, integer first);
  27. autoPermutation Permutation_create (integer numberOfElements);
  28. /*
  29. Create the Permutation data structure and fill
  30. with the identical permutation (1,2,..n)
  31. */
  32. void Permutation_checkInvariant (Permutation me);
  33. /* Check that the elements, if sorted ascendingly, are exactly equal to the identity (1,2,...). */
  34. void Permutation_sort (Permutation me);
  35. /* Set p[1..n]=1,..n */
  36. void Permutation_permuteRandomly_inplace (Permutation me, integer from, integer to);
  37. autoPermutation Permutation_permuteRandomly (Permutation me, integer from, integer to);
  38. /* Generate a new sequence by permuting the elements from..to */
  39. autoPermutation Permutation_rotate (Permutation me, integer from, integer to, integer step);
  40. void Permutation_swapOneFromRange (Permutation me, integer from, integer to, integer pos, bool forbidsame);
  41. /* Swap item at pos with one randomly chosen in interval [from,to]. If pos in [from,to]
  42. and forbidsame==true then new position may not be equal to pos. */
  43. void Permutation_swapBlocks (Permutation me, integer from, integer to, integer blocksize);
  44. /* Swap two blocks */
  45. void Permutation_swapPositions (Permutation me, integer i1, integer i2);
  46. void Permutation_swapNumbers (Permutation me, integer i1, integer i2);
  47. autoPermutation Permutation_interleave (Permutation me, integer from, integer to, integer blocksize, integer offset);
  48. autoPermutation Permutation_permuteBlocksRandomly (Permutation me, integer from, integer to, integer blocksize, bool permuteWithinBlocks, bool noDoublets);
  49. /* Permute blocks of size blocksize randomly. If permuteWithinBlocks=true and noDoublets=true forbid that the last
  50. number in a block and the first number in the following block are 'equal modulo blocksize'. */
  51. integer Permutation_getValueAtIndex (Permutation me, integer i);
  52. /* return i > 0 && i < my n ? my p[i] : -1 */
  53. integer Permutation_getIndexAtValue (Permutation me, integer value);
  54. /* Find i for which p[i] = value */
  55. autoPermutation Permutation_invert (Permutation me);
  56. /* */
  57. void Permutation_reverse_inline (Permutation me, integer from, integer to);
  58. autoPermutation Permutation_reverse (Permutation me, integer from, integer to);
  59. /* (n1,n2,...nn) to (nn,...n2,n1) */
  60. void Permutation_next_inplace (Permutation me);
  61. void Permutation_previous_inplace (Permutation me);
  62. autoPermutation Permutations_multiply2 (Permutation me, Permutation thee);
  63. autoPermutation Permutations_multiply (OrderedOf<structPermutation>* me);
  64. #endif /* _Permutation_h_ */