/*
 * Created on Apr 4, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package ps6.v2;

import ps6.Message;

/**
 * @author knorton
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class SoftEquals extends Gate {

	public void update() {
		int n = this.connects.size();
		Message[] r = new Message[n];
		
		System.out.println("beg SoftEquals");
		for (int i=0;i<n;i++) {
			
			double p0 = 1.0;
			double p1 = 1.0;
			
			System.out.print("Equals: ");
			for (int j=0;j<n;j++) {
				if (i==j)
					continue;
				
				Message m = this.getConnector(j).receive(this);
				System.out.print("*"+m);
				p0 *= m.getP(0);
				p1 *= m.getP(1);
			}
			
			r[i]=new Message(p0,p1);
			System.out.println(" = "+r[i]);
		}
		
		this.setResult(r);
		System.out.println("end SoftEquals");
	}

}
