Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone!
 
I would like to know how you can put a matrix that came from c + + code in the Java console in an matrix in java. In fact, I send parameter to my c + + code from the java code, and the receipt of income is at the java console in the form of a text. so, I want to extract the matrix from the text .I need later in the code, I honestly do not know how.
 
below, this is my java code
Java
OutputStream out = null;
     OutputStream err = null;
     PipedInputStream pipedInput = new PipedInputStream();
     PipedOutputStream pipedOutput = new PipedOutputStream(pipedInput);
     Program prog = new Program("C:\\Users\\abdelhalim\\Desktop\\ExempleMMKP33.exe", System.out, System.err, pipedInput);
        // TODO: Write pipedOutput from your favorite thread to send input to the program and finally close the stream.
        // I will use a PrintWriter because we are working here with text and not binary data.
        PrintWriter pw = new PrintWriter(pipedOutput);
        // println outputs platform specific newline but pw.print("5\n" ) would also convert "\n" to platform specific newline.
      
      
       res1= new int[n][m];
        pw.println(m);
        pw.println(n);
        pw.println(m);
        pw.println(n);
      
        for(int k=0; k<R.size();k++)
        { 
        pw.println(R.get(k));
        }
      
        for(int k=0; k<C.size();k++)
        {
       
        pw.println(C.get(k));
        }
        for(int k=0; k<B.size();k++)
        {
       
        pw.println(B.get(k));
        }
        for(int k=0; k<Dr.size();k++)
        {
       
        pw.println(Dr.get(k));
        }
        for(int k=0; k<Dc.size();k++)
        {
       
        pw.println(Dc.get(k));
        }
        for(int k=0; k<Db.size();k++)
        {
       
        pw.println(Db.get(k));
        }
        /*for(int k=0; k<n;k++)
        {
      for(int j=0; j<m;j++)
 	    pw.println(GainMatrix[k][j]);
 	   }*/
        pw.println(n);
        pw.println(m);
        pw.println(m);
        pw.println(m);
pw.close();


and this is what I get in the java console:

0   0   0   0   1   0
   0   0   0   0   0   1
   0   1   0   0   0   0
   0   0   0   1   0   0
   0   0   0   0   1   0
   0   0   1   0   0   0
Initial
propagators: 24
branchers:   1
Summary
runtime:      1.735 (1735.000 ms)
solutions:    48
propagations: 1715
nodes:        153
failures:     29
restarts:     0
peak depth:   7
peak memory:  13 KB


I want to put this matrix in a java code matrix (matrix type res1 = new int [n] [m]) after the reception and I do not know how to do it ??,,
 
you have an idea about that?? thank you very much for your help
Posted
Comments
Richard MacCutchan 1-Nov-13 14:22pm    
Read the text data and convert each field to integer and store in the matrix.
Manel1989 1-Nov-13 16:42pm    
thank you very much

1 solution

Read the console output as string and scan it. A space means end of integer, a new line a new row. You scans the string twice: first run to detect the dimensions and second run to read the values.

Very important: Implement robust error handling!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900