it.ssc.pl.milp.util.A_DataMatrix Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsr331-ssc Show documentation
Show all versions of jsr331-ssc Show documentation
This is a JSR331 interface for SSC (Software for the Calculation of the Simplex) is a java library for solving linear programming problems v. 3.0.1.
SSC was designed and developed by Stefano Scarioli.
The newest version!
package it.ssc.pl.milp.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Random;
import it.ssc.io.FileNotFound;
import it.ssc.io.UtilFile;
public class A_DataMatrix {
/*
* Questa matrice deve memorizzare la tabella standard.
* Il nome da dare alla matrice non deve esistere e sara dato da
* A_numero_casuale. La creazione avverra nel costruttore , per cui per
* accedere alla matrice occorre sempre avere il riferimento dell'oggetto.
* La matrice verra creata nel path, che per adesso e definita come l'area di
* work della sessione.
*/
private int nRow;
private int nCol;
private File file;
private double[] tempRowI;
private DataInputStream input;
public int getnRow() {
return nRow;
}
public int getnCol() {
return nCol;
}
public A_DataMatrix(double[][] A, String path) throws FileNotFoundException, IOException {
this.nRow=A.length;
this.nCol=A[0].length;
tempRowI = new double[nCol];
file=createRandomNameFile(path);
DataOutputStream out=getDataOutputStream(file);
writeDataFromArray(A,out);
out.close();
}
private void writeDataFromArray(double[][] A,DataOutputStream out) throws IOException {
for(int i=0;i= nRow) throw new java.lang.ArrayIndexOutOfBoundsException("Riga della matrice fuori indice");
if(row==0) input=getDataInputStream(file);
for (int i = 0; i < tempRowI.length; i++) {
tempRowI[i] = input.readDouble();
}
if(row==(nRow-1)) input.close();
return tempRowI;
}
public void close() throws IOException {
if(input!=null) input.close();
this.tempRowI=null;
}
}