All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.ssc.pl.milp.util.A_Matrix Maven / Gradle / Ivy

Go to download

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.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Date;
import java.util.Random;


import it.ssc.io.FileNotFound;
import it.ssc.io.UtilFile;

public final class A_Matrix {
	
	/*
	 * Questa matrice deve memorizzare la tabella normalizzata. 
	 * 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 double[] tempRowI;
	private RandomAccessFile RAF;
	private int currentRow=-1;
	
	public int getnRow() {
		return nRow;
	}


	public int getnCol() {
		return nCol;
	}


	public A_Matrix(int row, int col, String path) throws FileNotFoundException, IOException {
		this.nCol=col;
		this.nRow=row;
		this.tempRowI = new double[nCol];
		RAF=getRandomAccesFile(createRandomNameFile(path));
	}
	
	public A_Matrix(double[][] A, String path) throws FileNotFoundException, IOException {
		this.nRow=A.length;
		this.nCol=A[0].length;
		this.tempRowI = new double[nCol];
		RAF=getRandomAccesFile(createRandomNameFile(path));
		writeDataFromArray(A);
	}
	
	private void writeDataFromArray(double[][] A) throws IOException {
		for(int i=0;i= nRow) throw new java.lang.ArrayIndexOutOfBoundsException("Riga della matrice fuori indice");
		if(currentRow==row) return tempRowI;
		else currentRow=row;
		
		long start=(row *nCol) *8;
		RAF.seek(start);
		for (int i = 0; i < tempRowI.length; i++) {
			tempRowI[i] = RAF.readDouble();
		}
		return tempRowI;
	}
	
	
	public double readValue(int row,int col) throws IOException {
		if(row >= nRow) throw new java.lang.ArrayIndexOutOfBoundsException("Riga della matrice fuori indice");
		
		
		long start=(row *nCol) *8 + col*8;
		RAF.seek(start);
		
		return RAF.readDouble();
		
	}
	
	public void close() throws IOException {
		RAF.close();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy