00001 /* 00002 * Created on Oct 27, 2009 00003 * 00004 * TODO To change the template for this generated file go to 00005 * Window - Preferences - Java - Code Style - Code Templates 00006 */ 00007 package edu.tum.cs.srl.bayesnets.bln.coupling; 00008 00009 import edu.tum.cs.logic.GroundAtom; 00010 import edu.tum.cs.logic.GroundLiteral; 00011 import edu.tum.cs.logic.PossibleWorld; 00012 import edu.tum.cs.logic.WorldVariables; 00013 import edu.tum.cs.logic.WorldVariables.Block; 00014 import edu.tum.cs.util.datastruct.ArraySlice; 00015 00016 public class BlockVariable implements IVariableLogicCoupler { 00017 protected Block block; 00018 00019 public BlockVariable(Block b) { 00020 block = b; 00021 } 00022 00023 public int getValue(PossibleWorld w) { 00024 int i = 0; 00025 for(GroundAtom ga : block) { 00026 if(ga.isTrue(w)) 00027 return i; 00028 ++i; 00029 } 00030 throw new RuntimeException("No true atom in block " + block); 00031 } 00032 00033 public GroundLiteral getGroundLiteral(int domIdx, WorldVariables worldVars) { 00034 GroundAtom ga = block.get(domIdx); 00035 return new GroundLiteral(true, ga); 00036 } 00037 00038 public void setValue(PossibleWorld w, int domIdx) { 00039 int i = 0; 00040 for(GroundAtom ga : block) { 00041 w.set(ga, domIdx == i); 00042 ++i; 00043 } 00044 } 00045 00046 public Iterable<String> getOriginalParams() { 00047 return new ArraySlice<String>(block.get(0).args, 0, -1); 00048 } 00049 }