/*---------------------------- Ingeneue source code ?Copyright 2000 by George von Dassow, Eli Meir, Edwin Munro, and Garrett Odell. Permission is granted for use by private individuals and by individuals and groups at all non-profit institutions, as long as those using the software or examining the code do not intend to make a profit from its use, and subject to all other conditions given on the website www.ingenenue.org. www.ingeneue.org contact@ingeneue.org ----------------------------*/ package main; import java.lang.*; import java.util.*; import java.io.*; import java.awt.*; import java.awt.geom.*; import affectors.Affector; /** This class represents a single cell in the model. Each cell stores its own set of nodes (rna and protein types), and can have separate nodes for each side of the cell. Cells are involved in setting up the model, but once the model is set up they are not very involved in integrating - they just call their nodes to do the integration. One future addition we need to make is to get cells so that they can dynamically switch neighbors. */ public class Cell extends Object { /** */ private int itsNum; // GvonD added 11/28/99 to help with indexing partial derivatives /** */ public static int arrayWidth=0, arrayHeight=0; /** */ private Polygon ItsPolygon; /** The cell's neighbors - set up by the init object */ public Cell [] neighbors; /** */ public Node [] nodes; /** */ private Network network; /** This used to be where initial values for each node in each cell were stored, but I'm not sure if its used anymore. */ private float [] nodeInitValues; /** The x,y position of the cell */ private Point2D.Float Location = new Point2D.Float(0,0); /** The radius of each cell in pixels. For polygonally drawn cells, this is distance from middle to farthest edge. */ private static int CellRadius = 2; /** Main constructor @param float x - the x coordinant of the cell on the surface. @param float y - the y coordinant of the cell on the surface. */ public Cell(float x, float y) { neighbors = new Cell[Globals.cellNumSides]; for (int i = 0; i < Globals.cellNumSides; i++) neighbors[i] = null; setLocation(new Point2D.Float(x,y)); } // GvonD added these 11/28/99 because the index is useful in keeping track of partial derivatives protected void setItsNum(int n) { itsNum = n; } public int getItsNum() { return itsNum; } public void save(PrintWriter out) { float val; for(int i = 0; i < nodes.length; i++) { val = 0; for(int j = 0; j < nodes[i].numSides; j++) val += nodes[i].getValue(j); out.print("\t" + val); } } public void saveHeadings(PrintWriter out) { for(int i = 0; i < nodes.length; i++) out.print("\t" + network.getNode(i).getName()); } public void addNodes(Network net) { nodes = net.getNodesForCell(); network = net; nodeInitValues = new float[nodes.length]; for(int i = 0; i < nodeInitValues.length; i++) nodeInitValues[i] = 0f; } public void addAffectors(Network net) throws Exception { for(int i = 0; i < nodes.length; i++) { Vector affectors = net.getAffectorsForNode(nodes[i].getNodeNum()); nodes[i].setAffectors(affectors, this); } } public void addNeighbor(Cell neighbor) { int i = 0; while(neighbors[i] != null) i++; neighbors[i] = neighbor; } /** Returns the cells shape. @return Polygon - The shape of the cell. @author WJS */ public Polygon getCellShape() { return(ItsPolygon); } public Node getNeighborNode(int side, String name) throws Exception { return(neighbors[side].getNode(name)); } public Node getNode(String name) throws Exception { int i = 0; while(i < nodes.length && !name.equals(network.getNode(i).getName())) i++; if(i < nodes.length) return(nodes[i]); else throw new Exception("Node " + name + " not found"); } public int getNodeNum(String name) throws Exception { int i = 0; while(i < nodes.length && !name.equals(network.getNode(i).getName())) i++; if(i < nodes.length) return(i); else throw new Exception("Node " + name + " not found"); } public void setInitialValue(String nodename, float val) throws Exception { int n = getNodeNum(nodename); nodeInitValues[n] = val; } public void setInitialValue(int nodeNum, float val) { nodeInitValues[nodeNum] = val; } public float getInitialValue(String nodename) throws Exception { int n = getNodeNum(nodename); return nodeInitValues[n]; } public float getInitialValue(int nodeNum) { return nodeInitValues[nodeNum]; } public void addExperimentToNode(String nodename, Affector aff) { try { int nodenum = getNodeNum(nodename); nodes[nodenum].addExpAffector(aff, this); } catch(Exception e) {} } public void clearExperiment() { for(int i = 0; i < nodes.length; i++) nodes[i].removeExpAffectors(); } public float nodePeek(String name) { // called by StopConditions try { Node n = getNode(name); float v = n.getSum(); return(v); } catch(Exception e) { System.err.println(e.toString()); return(0f); // this can't be the right thing to do... } } public void init() { for(int i = 0; i < nodes.length; i++) nodes[i].setValue(nodeInitValues[i]); } /** initialize network from a stored previous state (if from_last_state == true) else from stored ICs */ public void init(boolean from_last_state) { if(from_last_state) { System.out.println("ERROR: Tried to set model from last state. Not sure what this is supposed to do anymore"); } else { for(int i = 0; i < nodes.length; i++) nodes[i].setValue(nodeInitValues[i]); } } public float getValue(int node_num) { return nodes[node_num].getSum(); } /** Returns all the node values for a cell in the form of an array of floats @return float[] @author WJS */ public float[] getValues() { float[] ret = new float[nodes.length]; for (int i=0;i