CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Jul 2021
    Posts
    9

    Find cartesians that fills zero-one matrix

    Hi All! I am new here.
    I am wondering what is the name for the following algorithm I need to code. If I know the name I could find the algorithm.

    1st example
    Suppose I have a matrix
    Code:
     123
    Aoo 
    Boo
    C oo
    D  o
    E oo
    Having it as an input I need to create an output like this:
    ABx12, CEx23, Dx3 (x means cartesian product)

    2nd example
    Code:
     12345
    A oo o
    B o  o
    Coo
    Doo oo
    Eo  oo
    F  ooo
    should give me an output like
    ABx25, CDx12, DEFx45, AFx3, Ex1

    May you help me, please?

    Thanks in advance,
    Jacek
    Last edited by JackK; July 14th, 2021 at 07:34 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,084

    Re: Find cartesians for matrix elements

    It is absolutely not clear what you want to get and what your initial matrices are. What are the dimensions of your matrices?

    You may also try to find out something useful and similar to your need here:
    https://www.google.com/search?q=cart...2VwigSGUNw7sRM
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2021
    Posts
    9

    Re: Find cartesians for matrix elements

    Quote Originally Posted by VictorN View Post
    It is absolutely not clear what you want to get and what your initial matrices are. What are the dimensions of your matrices?
    Hmm... The former matrix's dimension is 3x5, the latter is 5x6.
    I thought I wrote it rather clear

  4. #4
    Join Date
    Jul 2021
    Posts
    9

    Re: Find cartesians for matrix elements

    So maybe another example will be more clear.

    Matrix is (dimension 3x3)
    Code:
    101
    111
    110
    Output should be
    Code:
    000   001   100
    110 + 001 + 000
    110   000   000
    or
    Code:
    101   000   000
    101 + 010 + 000
    000   010   100

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,084

    Re: Find cartesians for matrix elements

    Quote Originally Posted by JackK View Post
    Hmm... The former matrix's dimension is 3x5, the latter is 5x6.
    I thought I wrote it rather clear
    No, you didn't.
    Victor Nijegorodov

  6. #6
    Join Date
    Jul 2021
    Posts
    9

    Re: Find cartesians for matrix elements


  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,084

    Re: Find cartesians for matrix elements

    Quote Originally Posted by JackK View Post
    So maybe another example will be more clear.

    Matrix is (dimension 3x3)
    Code:
    101
    111
    110
    DO you mean
    Code:
    1 0 1
    1 1 1
    1 1 0
    or something else?

    Quote Originally Posted by JackK View Post
    Output should be
    Code:
    000   001   100
    110 + 001 + 000
    110   000   000
    or
    Code:
    101   000   000
    101 + 010 + 000
    000   010   100
    What is the dimension of "Output"?
    What are these "+" (plus) symbols mean?

    BTW, did you find something useful and similar to your needs in the pictures I have posted?
    Victor Nijegorodov

  8. #8
    Join Date
    Jul 2021
    Posts
    9

    Re: Find cartesians for matrix elements

    Quote Originally Posted by VictorN View Post
    Do you mean
    Code:
    1 0 1
    1 1 1
    1 1 0
    or something else?
    I do mean exactly this.

    Quote Originally Posted by VictorN View Post
    What is the dimension of "Output"?
    The same as "Input".

    Quote Originally Posted by VictorN View Post
    What are these "+" (plus) symbols mean?
    "+" means that my "Input" is a sum of "Output" matrixes.

    Quote Originally Posted by VictorN View Post
    BTW, did you find something useful and similar to your needs in the pictures I have posted?
    No, rather not.

  9. #9
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,537

    Re: Find cartesians for matrix elements

    See https://stackoverflow.com/questions/...n-product-in-c re info about generating cartesian product sets.

    Also
    https://gist.github.com/Alexhuszagh/...529ed97586646a

    Doing an Internet search https://uk.search.yahoo.com/search?f...duct%20c%2B%2B provides many links to info re implementing cartesian products in C++
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.11.3)

  10. #10
    Join Date
    Jul 2021
    Posts
    9

    Re: Find cartesians for matrix elements

    Maybe I put my requirement in a wrong way.

    My requirement is to find submatrixes (minimum amount of them) which sum to my input matrix. Each submatrix must be possible to represent as a one and only one cartesian product. Input matrix is matrix of only 0 and 1 elements.

    For example:
    input
    Code:
      a b c d
    A 0 1 1 1
    B 0 1 1 1
    C 0 1 1 0
    D 1 1 0 0
    output (x means cartesian product)
    1. (A,B)x(b,c,d) + (C)x(b,c) + (D)x(a,b)
    what is equal to
    Code:
      a b c d   a b c d   a b c d
    A 0 1 1 1   0 0 0 0   0 0 0 0
    B 0 1 1 1   0 0 0 0   0 0 0 0
    C 0 0 0 0 + 0 1 1 0 + 0 0 0 0
    D 0 0 0 0   0 0 0 0   1 1 0 0
    or
    2. (A,B,C)x(b,c) + (A,B)x(d) + (D)x(a,b)
    what is equal to
    Code:
      a b c d   a b c d   a b c d
    A 0 1 1 0   0 0 0 1   0 0 0 0
    B 0 1 1 0   0 0 0 1   0 0 0 0
    C 0 1 1 0 + 0 0 0 0 + 0 0 0 0
    D 0 0 0 0   0 0 0 0   1 1 0 0
    (so my input matrix can be split into 3 submatrices)
    Last edited by JackK; July 14th, 2021 at 07:45 AM.

  11. #11
    Join Date
    Jul 2021
    Posts
    9

    Re: Find cartesians for matrix elements

    Is there still not all clear in my requirement?
    Should I explain it more (if possible)?

  12. #12
    Join Date
    Jul 2021
    Posts
    9

    Re: Find cartesians for matrix elements

    No more help?

  13. #13
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,537

    Re: Find cartesians for matrix elements

    As this is not a C++ question, but an algorithm question - the only help I can provide is to suggest that first you solve this using pen/paper to develop the algorithm. Once you produce what you require that way, then you can produce a program design and code from the design.

    Sorry, but I can't help you with the required algorithm. But once you have the design, I'll probably be able to provide guidance with the C++ coding.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.11.3)

  14. #14
    Join Date
    Jul 2021
    Posts
    9

    Re: Find cartesians for matrix elements

    But the problem is that the algorithm is unknown to me yet.
    I thought that it's maybe known to some of you.

  15. #15
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,537

    Re: Find cartesians for matrix elements

    Presumably not.......
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.11.3)

Page 1 of 2 12 LastLast

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