⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forgraphics.java

📁 一些常用的java程序,包括swing.net.io,matrix等
💻 JAVA
字号:
package mymath;

public class ForGraphics {
	public static final int UNAPPOINTED = -1;  //when we don't need to appointed a number of Point or Arc
	Matrix mt;
	//MatrixProcess mp = new MatrixProcess();
	public ForGraphics(Matrix imt){
		mt = imt;
	}
	//minimal root is 0
	public int getTreeNumberSpecifiedRoot(int rootindex){
		if(rootindex >= mt.RowDim){
			System.out.println("getTreeNumberSpecifiedRoot(rootindex): rootindex>=mt.RowDim rootindex = "+rootindex);
			mt.outputMatrix();
			System.exit(0);
		}
		for(int i = 0; i < mt.matrix[0].length; i++){
			if(mt.matrix[rootindex][i] == -1){
				System.err.println("getTreeNumberSpecifiedRoot(rootindex):matrix[rootindex][i] == -1. rootindex = "+rootindex);
				mt.outputMatrix("happy");
				System.err.println("Be Careful: it rootindex, which means the integer must begin from 0");
				System.exit(0);
			}
		}
		Matrix temp = mt;
		//mt = mt.deleteRow(rootindex);
		temp = temp.changeValue(1, 0);
		temp.outputMatrix();
		return new ForGraphics(temp).getTreeNumber(rootindex);
	}
	
	public int getTreeNumberSpecifiedRootAndWithoutArc(int rootindex, int arcindex){
		Matrix temp = mt.deleteLine(arcindex);
		return  new ForGraphics(temp).getTreeNumberSpecifiedRoot(rootindex);
	}
	
	public int getTreeNumber(int deletedRowIndex){
		if(deletedRowIndex >= mt.RowDim){
			System.err.println("getTreeNumber(deletedRowIndex): deletedRowIndex = "+deletedRowIndex);
			mt.outputMatrix();
			System.exit(0);
		}
		Matrix mt2 = mt.deleteRow(deletedRowIndex);
		mt2.outputMatrix();
		Matrix im = mt2.getInvertedMatrix();
		Matrix mm = Matrix.MultiplicationOfMatrix(mt2, im);
		//mm.outputMatrix(); 	
		return (int)mm.getDeterminant();
	}
	
	public int getTreeNumber(){
		Matrix mt2 = mt.deleteRow(mt.RowDim - 1);
		Matrix im = mt2.getInvertedMatrix();
		Matrix mm = Matrix.MultiplicationOfMatrix(mt2, im);
		//mm.outputMatrix(); 	
		return (int)mm.getDeterminant();
	}
	
	public int getTreeNumberWithoutAppointedArc(int srcindex, int dstindex, int arcindex){
		if(mt.matrix[srcindex][arcindex]*mt.matrix[dstindex][arcindex] != -1){
			System.err.println("getTreeNumberWithoutAppointedArc(): mt.matrix[srcindex][arcindex]*mt.matrix[dstindex][arcindex] != -1");
			mt.outputMatrix();			
			System.exit(0);
		}
		
		Matrix temp = mt;
		//out("after init:");
		//temp.outputMatrix();
		
		temp = temp.deleteLine(arcindex);
		//out("after deleteLine");
		//temp.outputMatrix();
		
		temp = temp.deleteRow(temp.RowDim - 1);
		//out("after deleteRow");
		//temp.outputMatrix();
		
		Matrix imm = temp.getInvertedMatrix();
		Matrix mmm = Matrix.MultiplicationOfMatrix(temp, imm);
		//out("after multiplication");
		//mmm.outputMatrix();
		//out("mp "+mp.getDeterminant(mmm));
	//	mmm.outputMatrix();
		return mmm.getDeterminant();
	}
	
	public int getTreeNumberWithAppointedArc(int srcindex, int dstindex, int arcindex){
		if(mt.matrix[srcindex][arcindex]*mt.matrix[dstindex][arcindex] != -1){
			System.err.println("getTreeNumberWithoutAppointedArc(): mt.matrix[srcindex][arcindex]*mt.matrix[dstindex][arcindex] != -1");
			mt.outputMatrix();
			System.exit(0);
		}
		
		Matrix temp = mt;
		//out("after init:");
		//temp.outputMatrix();
		
		temp = temp.deleteLine(arcindex);
		for(int i = 0; i < temp.LineDim; i++){
			temp.matrix[srcindex][i] = temp.matrix[srcindex][i]+temp.matrix[dstindex][i];
		}
		//out("after vsrc + vdst ");
		////temp.outputMatrix();
		temp = temp.deleteRow(dstindex);
		//out("after deleteRow and deleteLine");
		//temp.outputMatrix();
		
		temp = temp.deleteRow(temp.RowDim - 1);
		
		Matrix imm = temp.getInvertedMatrix();
		Matrix mmm = Matrix.MultiplicationOfMatrix(temp, imm);
		
		//out("mp :"+mp.getDeterminant(mmm));
		//mmm.outputMatrix();
		return mmm.getDeterminant();
	}
	
	public void out(String msg){
		System.out.println(msg);
	}
	/*
	public int getTreeNumber(){
		Matrix mt2 = mp.deleteRow(mt, mt.RowDim - 1);

		Matrix im = mp.getInvertedMatrix(mt2);
		Matrix mm = mp.MultiplicationOfMatrix(mt2, im);
		//mm.outputMatrix();
		return (int)mp.getDeterminant(mm);
	}
	
	public int getTreeNumberWithoutAppointedArc(int srcindex, int dstindex, int arcindex){
		if(mt.matrix[srcindex][arcindex]*mt.matrix[dstindex][arcindex] != -1){
			System.err.println("getTreeNumberWithoutAppointedArc(): mt.matrix[srcindex][arcindex]*mt.matrix[dstindex][arcindex] != -1");
			System.exit(0);
		}
		
		Matrix temp = mt;
		//out("after init:");
		//temp.outputMatrix();
		
		temp = mp.deleteLine(temp, arcindex);
		//out("after deleteLine");
		//temp.outputMatrix();
		
		temp = mp.deleteRow(temp, temp.RowDim - 1);
		//out("after deleteRow");
		//temp.outputMatrix();
		
		Matrix imm = mp.getInvertedMatrix(temp);
		Matrix mmm = mp.MultiplicationOfMatrix(temp, imm);
		//out("after multiplication");
		//mmm.outputMatrix();
		//out("mp "+mp.getDeterminant(mmm));
	//	mmm.outputMatrix();
		return mp.getDeterminant(mmm);
	}
	
	public int getTreeNumberWithAppointedArc(int srcindex, int dstindex, int arcindex){
		if(mt.matrix[srcindex][arcindex]*mt.matrix[dstindex][arcindex] != -1){
			System.err.println("getTreeNumberWithoutAppointedArc(): mt.matrix[srcindex][arcindex]*mt.matrix[dstindex][arcindex] != -1");
			System.exit(0);
		}
		
		Matrix temp = mt;
		//out("after init:");
		//temp.outputMatrix();
		
		temp = mp.deleteLine(temp, arcindex);
		for(int i = 0; i < temp.LineDim; i++){
			temp.matrix[srcindex][i] = temp.matrix[srcindex][i]+temp.matrix[dstindex][i];
		}
		//out("after vsrc + vdst ");
		////temp.outputMatrix();
		temp = mp.deleteRow(temp, dstindex);
		//out("after deleteRow and deleteLine");
		//temp.outputMatrix();
		
		temp = mp.deleteRow(temp, temp.RowDim - 1);
		
		Matrix imm = mp.getInvertedMatrix(temp);
		Matrix mmm = mp.MultiplicationOfMatrix(temp, imm);
		
		//out("mp :"+mp.getDeterminant(mmm));
		//mmm.outputMatrix();
		return mp.getDeterminant(mmm);
	}
	
	public void out(String msg){
		System.out.println(msg);
	}*/
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -