Hi everyone!
I have in my GUI and two radio button choco and gecode and under each button (choco or gecode)I have 2 radio buttons solution optimal and Feasible solution: my problem lies in the selection buttons. Let me explain:
when I click the radio button choco, I want to have the optimal solution of the model choco so I click on the optimal solution, but the radio button choco is no longer selected but i need it to be selected , the same for the gecode button.
here is a piece of code but it does not work incorrectly:
if ( radio1.isSelected())// bouton du modèle choco
{
{
int[] R1=new int[m];
int[] C1=new int[m];
int[] B1=new int[m];
int[] Dr1=new int[n];
int[] Dc1=new int[n];
int[] Db1=new int[n];
for(int i=0;i<n;i++)
{
Dr1[i]=Integer.parseInt(Dr.get(i).toString());
Dc1[i]=Integer.parseInt(Dc.get(i).toString());
Db1[i]=Integer.parseInt(Db.get(i).toString());
}
for(int i=0;i<m;i++)
{
R1[i]=Integer.parseInt(R.get(i).toString());
C1[i]=Integer.parseInt(C.get(i).toString());
B1[i]=Integer.parseInt(B.get(i).toString());
}
MMKP model=new MMKP();
res= new int[n][m];
res2= new int[n][m];
if ( radio3.isSelected())// bouton de la solution optimal du modèle choco
{
res=model.find_Optimal_Solution(n, m, R1, C1, B1, Dr1, Dc1, Db1, GainMatrix1);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
System.out.print(res[i][j]+" " );
System.out.println();
}
}
else if ( radio4.isSelected())// bouton de la solution réalisable du modèle choco
{
res2=model.find_realizable_solution(n, m, R1, C1, B1, Dr1, Dc1, Db1);
System.out.println("///////////////////////////" );
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
System.out.print(res2[i][j]+" " );
System.out.println();
}}
}
}
else if ( radio2.isSelected()) // bouton du modèle Gocode
{
if( radio5.isSelected())// bouton pour la solution optimal du modèle gecode
{
try {
//Appel du programme C++ a partir de Java
ProcessBuilder pb = new ProcessBuilder("C:\\Users\\abdelhalim\\Desktop\\MMKPcost1.exe" );
Process p = pb.start();
//Creation de 2 threads pour lire les flux de sortie et derreur du programme C++
ExecutorService executor = Executors.newFixedThreadPool(2);
Callable<String> callableFluxSortie = new AfficheurFlux(p.getInputStream());
Callable<String> callableFluxErreur = new AfficheurFlux(p.getErrorStream());
Future<String> futureSortie = executor.submit(callableFluxSortie);
Future<String> futureErreur = executor.submit(callableFluxErreur);
executor.shutdown();
OutputStream stdin = p.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
//nb ligne matrice
writer.write(String.valueOf(m));
writer.newLine();
//nb colonne matrice
writer.write(String.valueOf(n));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
//nb colonne matrice
writer.write(String.valueOf(n));
writer.newLine();
for(int i=0; i<R.size();i++)
{
writer.write(String.valueOf(R.get(i)));
writer.newLine();
}
for(int i=0; i<C.size();i++)
{
writer.write(String.valueOf(C.get(i)));
writer.newLine();
}
for(int i=0; i<B.size();i++)
{
writer.write(String.valueOf(B.get(i)));
writer.newLine();
} for(int i=0; i<Dr.size();i++)
{
writer.write(String.valueOf(Dr.get(i)));
writer.newLine();
} for(int i=0; i<Dc.size();i++)
{
writer.write(String.valueOf(Dc.get(i)));
writer.newLine();
}
for(int i=0; i<Db.size();i++)
{
writer.write(String.valueOf(Db.get(i)));
writer.newLine();
}
/*for(int k=0; k<n;k++)
{
for(int j=0; j<m;j++)
writer.write(String.valueOf(GainMatrix[k][j]));
writer.newLine();
}*/
writer.write(String.valueOf(n));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
writer.write(String.valueOf(n));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
writer.write(String.valueOf(n));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
writer.write(String.valueOf(n));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
writer.flush();
writer.close();
//Attente fin du programme C++
p.waitFor();
try {
System.out.println("\nFlux sortie : \n" + futureSortie.get());
String resultat= futureSortie.get().toString();
// convert String into InputStream
InputStream is = new ByteArrayInputStream(resultat.getBytes());
// read it with BufferedReader
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
try {
int nbLine = n+1;
int nbCol = m;
int cpt = 0;
int[][] mat = new int[nbLine][nbCol];
while ((line = br.readLine()) != null) {
if(cpt>=nbLine) break;
String[] split = line.trim().split("\\s+" );
try{
for(int i = 0; i<split.length && i<nbCol; i++){
mat[cpt][i] = Integer.parseInt(split[i]);
}
}
catch(NumberFormatException e){
}
cpt++;
}
System.out.println("Matrice :" );
for(int[] rows : mat){
for(int cel : rows){
System.out.print(cel + " " );
}
System.out.println();
}
res1= new int[nbLine-1][nbCol];
int nRows = mat.length;
int nColumns = mat[0].length;
int newTabRow = 0;
int newTabCol = 0;
int index=0;
for(int i = 0 ; i<nRows ; ++i){
if(i != index){
for(int j = 0 ; j<nColumns ; ++j){
res1[newTabRow][newTabCol] = mat[i][j];
++newTabCol;
}
++newTabRow;
newTabCol = 0;
}
}
for(int[] rows : res1){
for(int cel : rows){
System.out.print(cel + " " );
System.out.println();
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (ExecutionException e) {
e.printStackTrace();
}
try {
System.out.println("\nFlux erreur : \n" + futureErreur.get());
} catch (ExecutionException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
else if( radio6.isSelected())// boutons radio pour la solution réalisable de gecode
{
try {
//Appel du programme C++ a partir de Java
ProcessBuilder pb = new ProcessBuilder("C:\\Users\\abdelhalim\\Desktop\\ReadInput.exe" );
Process p = pb.start();
//Creation de 2 threads pour lire les flux de sortie et derreur du programme C++
ExecutorService executor = Executors.newFixedThreadPool(2);
Callable<String> callableFluxSortie = new AfficheurFlux(p.getInputStream());
Callable<String> callableFluxErreur = new AfficheurFlux(p.getErrorStream());
Future<String> futureSortie = executor.submit(callableFluxSortie);
Future<String> futureErreur = executor.submit(callableFluxErreur);
executor.shutdown();
OutputStream stdin = p.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
//nb ligne matrice
writer.write(String.valueOf(m));
writer.newLine();
//nb colonne matrice
writer.write(String.valueOf(n));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
//nb colonne matrice
writer.write(String.valueOf(n));
writer.newLine();
for(int i=0; i<R.size();i++)
{
writer.write(String.valueOf(R.get(i)));
writer.newLine();
}
for(int i=0; i<C.size();i++)
{
writer.write(String.valueOf(C.get(i)));
writer.newLine();
}
for(int i=0; i<B.size();i++)
{
writer.write(String.valueOf(B.get(i)));
writer.newLine();
} for(int i=0; i<Dr.size();i++)
{
writer.write(String.valueOf(Dr.get(i)));
writer.newLine();
} for(int i=0; i<Dc.size();i++)
{
writer.write(String.valueOf(Dc.get(i)));
writer.newLine();
}
for(int i=0; i<Db.size();i++)
{
writer.write(String.valueOf(Db.get(i)));
writer.newLine();
}
/*for(int k=0; k<n;k++)
{
for(int j=0; j<m;j++)
writer.write(String.valueOf(GainMatrix[k][j]));
writer.newLine();
}*/
writer.write(String.valueOf(n));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
writer.write(String.valueOf(n));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
writer.write(String.valueOf(n));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
writer.write(String.valueOf(n));
writer.newLine();
writer.write(String.valueOf(m));
writer.newLine();
writer.flush();
writer.close();
//Attente fin du programme C++
p.waitFor();
try {
System.out.println("\nFlux sortie : \n" + futureSortie.get());
String resultat= futureSortie.get().toString();
// convert String into InputStream
InputStream is = new ByteArrayInputStream(resultat.getBytes());
// read it with BufferedReader
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
try {
int nbLine = n+1;
int nbCol = m;
int cpt = 0;
int[][] mat = new int[nbLine][nbCol];
while ((line = br.readLine()) != null) {
if(cpt>=nbLine) break;
String[] split = line.trim().split("\\s+" );
try{
for(int i = 0; i<split.length && i<nbCol; i++){
mat[cpt][i] = Integer.parseInt(split[i]);
}
}
catch(NumberFormatException e){
}
cpt++;
}
System.out.println("Matrice :" );
for(int[] rows : mat){
for(int cel : rows){
System.out.print(cel + " " );
}
System.out.println();
}
res1= new int[nbLine-1][nbCol];
int nRows = mat.length;
int nColumns = mat[0].length;
int newTabRow = 0;
int newTabCol = 0;
int index=0;
for(int i = 0 ; i<nRows ; ++i){
if(i != index){
for(int j = 0 ; j<nColumns ; ++j){
res1[newTabRow][newTabCol] = mat[i][j];
++newTabCol;
}
++newTabRow;
newTabCol = 0;
}
}
for(int[] rows : res1){
for(int cel : rows){
System.out.print(cel + " " );
System.out.println();
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (ExecutionException e) {
e.printStackTrace();
}
try {
System.out.println("\nFlux erreur : \n" + futureErreur.get());
} catch (ExecutionException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
what I want is that when I select the radio button choco remains selected when I select fesable Optimal solution or solution that belong to this choco button (same thing for the radio button gecode)
Can YOU help me to solve this problem??
is it preferable to choose another way other than the radio buttons to these satsfaire these conditions?
Thank you very much for your help