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

📄 cell.java

📁 利用系统仿真软件swarm及Java的swarm库对人体的免疫功能进行模拟
💻 JAVA
字号:
import swarm.objectbase.SwarmObjectImpl;
import swarm.defobj.Zone;
import java.lang.Math;
import swarm.Globals;

public class Cell extends SwarmObjectImpl implements Comparable
{
	private int[] gene;					//抗体的基因
	private int matchValue = 0;					//免疫细胞与抗体的匹配度
	private static double abePro = 0.01;
/**
*	函数功能:指定基因的免疫细胞的构造函数
*/
	public Cell(Zone aZone,int[] geneA) 
	{
		super(aZone);
		gene = geneA;
	}
/**
*	函数功能:仅指定基因的免疫细胞的构造函数
*/
	public Cell(Zone aZone,int genLen1)
	{
		super(aZone);
		gene = new int[genLen1];
		for (int i = 0; i < genLen1; ++i)
		{
			if (Math.random() < 0.5)
				gene[i] = 0;
			else gene[i] = 1;
		}
	}
/**
*	函数功能:将当前免疫细胞与抗原的匹配度与o的相比较,
*		若当前的匹配度高,则返回1,
*			匹配度相等,返回0
*			匹配度低,返回-1
*/
	public int compareTo(Object o) 
	{
		int matchValue1 = ((Cell)o).getMatchValue();
		if (matchValue < matchValue1)
			return -1;
		else if (matchValue == matchValue1)
			return 0;
		else
			return 1;
	}
/**
*	函数功能:当前免疫细胞(含抗体)与抗原发生免疫反应,
*		计算抗体与抗原antigen的匹配度:matchValue
*/
	public int immunoreaction(Antigen antigen)
	{
		int[] geneA = antigen.getGene();
		int k = 0,kc = 0;

		matchValue = 0;
		for (int i = 0; i < gene.length && i < geneA.length; ++i)
		{
			if (gene[i] != geneA[i])
				++k;
			else if (k == 0)
				continue;
			else {
				matchValue += (int)(Math.pow(2,k)+0.1);
				kc += k;
				k = 0;
			}
		}
		if (k != 0) {
			matchValue += (int)(Math.pow(2,k)+0.1);
			kc += k;
		}
		matchValue += kc;
		return matchValue;
	}
/**
*	函数功能:为了找到与抗原匹配的抗体,
*		免疫细胞在遗传中发生变异
*		变异概率:abePro,需在实验中慢慢调整
*/
	public void aberrance() 
	{
		for (int i = 0; i < gene.length; ++i) 
		{
			if (Math.random() <0.1)
			{
				if (gene[i] == 1)
					gene[i] = 0;
				else gene[i] = 1;
			}
		}
	}
/**
*	函数功能:返回免疫细胞的基因信息
*/
	public int[] getGene()
	{
		return gene;
	}

/**
*	函数功能:返回免疫细胞与抗原的匹配度
*/
	public int getMatchValue() 
	{
		return matchValue;
	}

	public static void main(String[] args)
	{
		int[] g1 = {0,1,1,0,0,0,0,1,1,1,1,0,1,1,0};
		int[] g2 = {1,0,0,1,1,1,0,0,0,1,0,1,1,0,1};
		
		Cell c1 = new Cell(Globals.env.globalZone,g1);
		Antigen c2 = new Antigen(Globals.env.globalZone,g2);

		System.out.println(c1.immunoreaction(c2));
	}
}

⌨️ 快捷键说明

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