CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2006
    Location
    Wantagh,NY
    Posts
    151

    How to do this??

    I saw this code on another site and it does exactly what I want it to, problem is that in order to have acccess to the header file, you must register and pay. Is there another way to do this easily?

    Code:
    #include <codecogs/maths/combinatorics/permutations/partition.h>
    #include <iostream>
    int main()
    {
      int tau[9] = {2, 3, 9, 6, 7, 8, 5, 4, 1};
      std::vector<int> result = Maths::Combinatorics::Permutations::partition(9, tau);
      std::cout << "The partition of the [9] set induced by the Tau permutation is:";
      std::cout << std::endl;
      for (int i = 1; i <= 9; i++)
      {
        for (int j = 0; j < 9; j++)
          if (result[j] == i)
          {
            std::cout << "Subset " << i << " : { ";
            for (; j < 9; j++)
              if (result[j] == i)
                std::cout << tau[j] << " ";
            std::cout << "}" << std::endl;
          }
      }
      return 0;
    }
    Output:
    The partition of the [9] set induced by the Tau permutation is:
    Subset 1 : { 2 3 9 1 }
    Subset 2 : { 6 8 4 }
    Subset 3 : { 7 5 }

    Note: This is not my compiled output, this is the output posted on the site.
    Last edited by gammaman; February 13th, 2009 at 07:25 PM.

  2. #2
    Join Date
    Jun 2008
    Posts
    37

    Re: How to do this??

    Quote Originally Posted by gammaman View Post
    I saw this code on another site and it does exactly what I want it to, problem is that in order to have acccess to the header file, you must register and pay. Is there another way to do this easily?

    Code:
    #include <codecogs/maths/combinatorics/permutations/partition.h>
    #include <iostream>
    int main()
    {
      int tau[9] = {2, 3, 9, 6, 7, 8, 5, 4, 1};
      std::vector<int> result = Maths::Combinatorics::Permutations::partition(9, tau);
      std::cout << "The partition of the [9] set induced by the Tau permutation is:";
      std::cout << std::endl;
      for (int i = 1; i <= 9; i++)
      {
        for (int j = 0; j < 9; j++)
          if (result[j] == i)
          {
            std::cout << "Subset " << i << " : { ";
            for (; j < 9; j++)
              if (result[j] == i)
                std::cout << tau[j] << " ";
            std::cout << "}" << std::endl;
          }
      }
      return 0;
    }
    Output:
    The partition of the [9] set induced by the Tau permutation is:
    Subset 1 : { 2 3 9 1 }
    Subset 2 : { 6 8 4 }
    Subset 3 : { 7 5 }

    Note: This is not my compiled output, this is the output posted on the site.
    We need to understand your type correctly in the partition.h before compiling the program
    Show me your code. We will go further

  3. #3
    Join Date
    Sep 2006
    Location
    Wantagh,NY
    Posts
    151

    Re: How to do this??

    Let me make myself clearer. I copied and pasted the code straight from another site. The ".h" you are refering to, is the problem. I do not have access to it unless I register and pay at the site. What I want to know is if there is another way to perfrom the same permutation as the code does.

  4. #4
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: How to do this??

    Of course, but without knowing the details of the algorithm used I wouldn't know where to start.

    Whats a tau permutation and just how are they partitioning it??
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  5. #5
    Join Date
    Sep 2006
    Location
    Wantagh,NY
    Posts
    151

    Re: How to do this??

    Well the way that I think I would like to partition it is as follows

    S= {1-2,1-3,4-5,5-6,-7-8}

    P1= {1,2,3}
    P2 = {4,5,6}
    P3 = {7-8}

    Another words, once a number is in a given P{}, it cannot appear again. So if you look at 4-5 and 5-6 in S, they both have to belong to the same P{}.

  6. #6
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: How to do this??

    They use this set...

    {2, 3, 9, 6, 7, 8, 5, 4, 1}

    which gives them these 3 subsets...

    { 2 3 9 1 }
    { 6 8 4 }
    { 7 5 }

    Perhaps you could show us how their algorithm works out that theres 3 subsets of different lengths and why the subsets are as they are instead of
    {2 3 9 1 6 8 4}
    {7 5}

    etc.

    If i could see how the set is being partitioned i could probably show you how to do it in code, but im a bit lost on the maths side of things here.
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  7. #7
    Join Date
    Sep 2006
    Location
    Wantagh,NY
    Posts
    151

    Re: How to do this??

    I am trying to figure that out myself. What I posted above is how I know to partition. But like you because of the "Math", I do not know how to code it.

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: How to do this??

    More than likely there's a lib or dll file to go along with it too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured