Browse Source

first commit

Debashis Chandra 7 years ago
commit
6fcabbb48f
88 changed files with 9833 additions and 0 deletions
  1. BIN
      CertainTrustSimple Documentation.docx
  2. BIN
      CertainTrustSimple Documentation.pdf
  3. BIN
      Consensus-Discounting Documentation.docx
  4. BIN
      Consensus-Discounting Documentation.pdf
  5. 7 0
      Java/Java_Examples/JavaDemonstrator/.classpath
  6. 18 0
      Java/Java_Examples/JavaDemonstrator/.project
  7. BIN
      Java/Java_Examples/JavaDemonstrator/CertainTrustSDK-1.0.jar
  8. 0 0
      Java/Java_Examples/JavaDemonstrator/This is an Eclipse Juno project
  9. BIN
      Java/Java_Examples/JavaDemonstrator/bin/ANDObserver.class
  10. BIN
      Java/Java_Examples/JavaDemonstrator/bin/CONSENSUSObserver.class
  11. BIN
      Java/Java_Examples/JavaDemonstrator/bin/DISCOUNTINGObserver.class
  12. BIN
      Java/Java_Examples/JavaDemonstrator/bin/Demonstrator.class
  13. BIN
      Java/Java_Examples/JavaDemonstrator/bin/DemonstratorCD.class
  14. BIN
      Java/Java_Examples/JavaDemonstrator/bin/DemonstratorStarter.class
  15. BIN
      Java/Java_Examples/JavaDemonstrator/bin/Minimal.class
  16. BIN
      Java/Java_Examples/JavaDemonstrator/bin/ORObserver.class
  17. BIN
      Java/Java_Examples/JavaDemonstrator/demonstrator.jar
  18. 35 0
      Java/Java_Examples/JavaDemonstrator/src/ANDObserver.java
  19. 35 0
      Java/Java_Examples/JavaDemonstrator/src/CONSENSUSObserver.java
  20. 35 0
      Java/Java_Examples/JavaDemonstrator/src/DISCOUNTINGObserver.java
  21. 152 0
      Java/Java_Examples/JavaDemonstrator/src/Demonstrator.java
  22. 152 0
      Java/Java_Examples/JavaDemonstrator/src/DemonstratorCD.java
  23. 25 0
      Java/Java_Examples/JavaDemonstrator/src/DemonstratorStarter.java
  24. 62 0
      Java/Java_Examples/JavaDemonstrator/src/Minimal.java
  25. 35 0
      Java/Java_Examples/JavaDemonstrator/src/ORObserver.java
  26. 7 0
      Java/Java_Examples/JavaSDKExample/.classpath
  27. 17 0
      Java/Java_Examples/JavaSDKExample/.project
  28. BIN
      Java/Java_Examples/JavaSDKExample/bin/Minimal.class
  29. 62 0
      Java/Java_Examples/JavaSDKExample/src/Minimal.java
  30. 7 0
      Java/Java_SDK/.classpath
  31. 17 0
      Java/Java_SDK/.project
  32. BIN
      Java/Java_SDK/CertainTrustSDK-1.0.jar
  33. BIN
      Java/Java_SDK/CertainTrustSDK_Update.jar
  34. 373 0
      Java/Java_SDK/Mozilla Public License Version 2.0.txt
  35. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrust.class
  36. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustCanvas$1.class
  37. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustCanvas$2.class
  38. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustCanvas.class
  39. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustHTI$1.class
  40. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustHTI$2.class
  41. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustHTI$3.class
  42. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustHTI$CertainTrustActionFocusListener.class
  43. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustHTI.class
  44. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustSimple.class
  45. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleCanvas$1.class
  46. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleCanvas$2.class
  47. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleCanvas.class
  48. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleHTI$1.class
  49. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleHTI$2.class
  50. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleHTI$3.class
  51. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleHTI$CertainTrustActionFocusListener.class
  52. BIN
      Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleHTI.class
  53. 373 0
      Java/Java_SDK/bin/CertainTrust/Mozilla Public License Version 2.0.txt
  54. BIN
      Java/Java_SDK/bin/CertainTrust/VerticalLabelUI.class
  55. 782 0
      Java/Java_SDK/src/CertainTrust/CertainTrust.java
  56. 177 0
      Java/Java_SDK/src/CertainTrust/CertainTrustCanvas.java
  57. 289 0
      Java/Java_SDK/src/CertainTrust/CertainTrustHTI.java
  58. 650 0
      Java/Java_SDK/src/CertainTrust/CertainTrustSimple.java
  59. 177 0
      Java/Java_SDK/src/CertainTrust/CertainTrustSimpleCanvas.java
  60. 289 0
      Java/Java_SDK/src/CertainTrust/CertainTrustSimpleHTI.java
  61. 373 0
      Java/Java_SDK/src/CertainTrust/Mozilla Public License Version 2.0.txt
  62. 197 0
      Java/Java_SDK/src/CertainTrust/VerticalLabelUI.java
  63. 984 0
      JavaScript/JavaScript_Examples/CertainTrust.js
  64. 373 0
      JavaScript/JavaScript_Examples/Mozilla Public License Version 2.0.txt
  65. 34 0
      JavaScript/JavaScript_Examples/certainTrustHTI.css
  66. 461 0
      JavaScript/JavaScript_Examples/certainTrustHTI.js
  67. 38 0
      JavaScript/JavaScript_Examples/certainTrustTViz.css
  68. 328 0
      JavaScript/JavaScript_Examples/certainTrustTViz.js
  69. 59 0
      JavaScript/JavaScript_Examples/consensus_operator.html
  70. 78 0
      JavaScript/JavaScript_Examples/demoTViz.html
  71. 110 0
      JavaScript/JavaScript_Examples/demonstrator.html
  72. 100 0
      JavaScript/JavaScript_Examples/demonstrator_cfusion.html
  73. 185 0
      JavaScript/JavaScript_Examples/demonstrator_updated.html
  74. 142 0
      JavaScript/JavaScript_Examples/demonstrator_updated_test.html
  75. 110 0
      JavaScript/JavaScript_Examples/evidences.html
  76. 58 0
      JavaScript/JavaScript_Examples/index.html
  77. BIN
      JavaScript/JavaScript_Examples/logo_softwarecluster.png
  78. BIN
      JavaScript/JavaScript_Examples/logo_tudarmstadt.png
  79. 41 0
      JavaScript/JavaScript_Examples/minimal.html
  80. 217 0
      JavaScript/JavaScript_Examples/multinomial.html
  81. 935 0
      JavaScript/JavaScript_SDK/CertainTrust.js
  82. 373 0
      JavaScript/JavaScript_SDK/Mozilla Public License Version 2.0.txt
  83. 34 0
      JavaScript/JavaScript_SDK/certainTrustHTI.css
  84. 461 0
      JavaScript/JavaScript_SDK/certainTrustHTI.js
  85. 38 0
      JavaScript/JavaScript_SDK/certainTrustTViz.css
  86. 328 0
      JavaScript/JavaScript_SDK/certainTrustTViz.js
  87. BIN
      QuickStart.pdf
  88. BIN
      Tutorial.pdf

BIN
CertainTrustSimple Documentation.docx


BIN
CertainTrustSimple Documentation.pdf


BIN
Consensus-Discounting Documentation.docx


BIN
Consensus-Discounting Documentation.pdf


+ 7 - 0
Java/Java_Examples/JavaDemonstrator/.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="lib" path="D:/Hiwi/CertainTrustSDK-1.0_Update/Java/Java_SDK/CertainTrustSDK_Update.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 18 - 0
Java/Java_Examples/JavaDemonstrator/.project

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>JavaDemonstrator</name>
+	<comment></comment>
+	<projects>
+		<project>CertainTrust</project>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

BIN
Java/Java_Examples/JavaDemonstrator/CertainTrustSDK-1.0.jar


+ 0 - 0
Java/Java_Examples/JavaDemonstrator/This is an Eclipse Juno project


BIN
Java/Java_Examples/JavaDemonstrator/bin/ANDObserver.class


BIN
Java/Java_Examples/JavaDemonstrator/bin/CONSENSUSObserver.class


BIN
Java/Java_Examples/JavaDemonstrator/bin/DISCOUNTINGObserver.class


BIN
Java/Java_Examples/JavaDemonstrator/bin/Demonstrator.class


BIN
Java/Java_Examples/JavaDemonstrator/bin/DemonstratorCD.class


BIN
Java/Java_Examples/JavaDemonstrator/bin/DemonstratorStarter.class


BIN
Java/Java_Examples/JavaDemonstrator/bin/Minimal.class


BIN
Java/Java_Examples/JavaDemonstrator/bin/ORObserver.class


BIN
Java/Java_Examples/JavaDemonstrator/demonstrator.jar


+ 35 - 0
Java/Java_Examples/JavaDemonstrator/src/ANDObserver.java

@@ -0,0 +1,35 @@
+/**
+ * CertainTrust Demonstrator in Java
+ * 
+ * The ANDObserver is used to update the result of the AND operation
+ * when the operands change and display the result in the result HTI.
+ * 
+ * @author	Florian Volk <florian.volk@cased.de>
+ */
+
+import java.util.Observable;
+import java.util.Observer;
+
+import CertainTrust.CertainTrust;
+
+
+public class ANDObserver implements Observer {
+
+	private CertainTrust Operand1;
+	private CertainTrust Operand2;
+	private CertainTrust Result;
+	
+	public ANDObserver(CertainTrust Operand1, CertainTrust Operand2, CertainTrust Result) {
+		this.Operand1 = Operand1;
+		this.Operand2 = Operand2;
+		this.Result = Result;
+	}
+
+	@Override
+	public void update(Observable arg0, Object arg1) {
+		// calculate the result of the AND operation and update the Result CertainTrust data object
+		CertainTrust ANDResult = this.Operand1.AND(this.Operand2);
+		this.Result.setF(ANDResult.getF());
+		this.Result.setTC(ANDResult.getT(), ANDResult.getC());
+	}
+}

+ 35 - 0
Java/Java_Examples/JavaDemonstrator/src/CONSENSUSObserver.java

@@ -0,0 +1,35 @@
+/**
+ * CertainTrust Demonstrator in Java
+ * 
+ * The ANDObserver is used to update the result of the AND operation
+ * when the operands change and display the result in the result HTI.
+ * 
+ * @author	Florian Volk <florian.volk@cased.de>
+ */
+
+import java.util.Observable;
+import java.util.Observer;
+
+import CertainTrust.CertainTrust;
+
+
+public class CONSENSUSObserver implements Observer {
+
+	private CertainTrust Operand1;
+	private CertainTrust Operand2;
+	private CertainTrust Result;
+	
+	public CONSENSUSObserver(CertainTrust Operand1, CertainTrust Operand2, CertainTrust Result) {
+		this.Operand1 = Operand1;
+		this.Operand2 = Operand2;
+		this.Result = Result;
+	}
+
+	@Override
+	public void update(Observable arg0, Object arg1) {
+		// calculate the result of the CONSENSUS operation and update the Result CertainTrust data object
+		CertainTrust CONSENSUSResult = this.Operand1.CONSENSUS(this.Operand2);
+		this.Result.setF(CONSENSUSResult.getF());
+		this.Result.setTC(CONSENSUSResult.getT(), CONSENSUSResult.getC());
+	}
+}

+ 35 - 0
Java/Java_Examples/JavaDemonstrator/src/DISCOUNTINGObserver.java

@@ -0,0 +1,35 @@
+/**
+ * CertainTrust Demonstrator in Java
+ * 
+ * The ANDObserver is used to update the result of the AND operation
+ * when the operands change and display the result in the result HTI.
+ * 
+ * @author	Florian Volk <florian.volk@cased.de>
+ */
+
+import java.util.Observable;
+import java.util.Observer;
+
+import CertainTrust.CertainTrust;
+
+
+public class DISCOUNTINGObserver implements Observer {
+
+	private CertainTrust Operand1;
+	private CertainTrust Operand2;
+	private CertainTrust Result;
+	
+	public DISCOUNTINGObserver(CertainTrust Operand1, CertainTrust Operand2, CertainTrust Result) {
+		this.Operand1 = Operand1;
+		this.Operand2 = Operand2;
+		this.Result = Result;
+	}
+
+	@Override
+	public void update(Observable arg0, Object arg1) {
+		// calculate the result of the DISCOUNTING operation and update the Result CertainTrust data object
+		CertainTrust DISCOUNTINGResult = this.Operand1.DISCOUNTING(this.Operand2);
+		this.Result.setF(DISCOUNTINGResult.getF());
+		this.Result.setTC(DISCOUNTINGResult.getT(), DISCOUNTINGResult.getC());
+	}
+}

+ 152 - 0
Java/Java_Examples/JavaDemonstrator/src/Demonstrator.java

@@ -0,0 +1,152 @@
+/**
+ * CertainTrust Demonstrator in Java
+ * 
+ * Demonstrates some capabilities of the CertainTrust SDK
+ * using a Java applet that interactively calculates
+ * AND and OR of two CertainTrust data objects and
+ * visually displays both the input objects and the output.
+ * 
+ * @author	Florian Volk <florian.volk@cased.de>
+ */
+
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Label;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.JApplet;
+import javax.swing.JPanel;
+
+import CertainTrust.CertainTrust;
+import CertainTrust.CertainTrustHTI;
+
+
+public class Demonstrator extends JApplet {
+	private static final long serialVersionUID = -7397289934413234935L;
+	
+	// the CertainTrust data objects
+	private CertainTrust AndOperand1;
+	private CertainTrust AndOperand2;
+	private CertainTrust AndResult;
+	private CertainTrust OrOperand1;
+	private CertainTrust OrOperand2;
+	private CertainTrust OrResult;
+	private static int N = 10;
+	
+	// the HTI objects that hold the CertainTrust data
+	private CertainTrustHTI HTIAndOperand1;
+	private CertainTrustHTI HTIAndOperand2;
+	private CertainTrustHTI HTIAndResult;
+	private CertainTrustHTI HTIOrOperand1;
+	private CertainTrustHTI HTIOrOperand2;
+	private CertainTrustHTI HTIOrResult;
+	
+
+	public Demonstrator() {
+		setupUI();
+		setupLogic();
+	}
+	
+	@Override
+	public void init() {
+		// make sure nothing is cut off due to a too small applet
+		setSize(1200, 500);
+	}
+	
+	/**
+	 * setupUI() creates the user interface and
+	 * binds all HTIs to the related CertainTrust data objects
+	 */
+	private void setupUI() {
+		// use GridBayLayout to align all the elements
+		GridBagConstraints constraints = new GridBagConstraints();
+		setLayout(new GridBagLayout());
+		
+		// title line "Demonstrator for CertainTrust"
+		constraints.gridwidth = GridBagConstraints.REMAINDER;
+		constraints.gridheight = 1;
+		constraints.insets = new Insets(10, 0, 0, 0);
+		Label title = new Label("Demonstrator for CertainTrust");
+		title.setFont(new Font("Sans Serif", Font.BOLD, 24));
+		add(title, constraints);
+		
+		// subtitle line
+		constraints.insets = new Insets(0, 0, 10, 0);
+		add(new Label("CertainTrust provides a means for the evaluation of propositional logic terms under uncertainty."), constraints);
+		
+		
+		// operands and result for AND operation
+		JPanel AndPanel = new JPanel();
+		AndPanel.setLayout(new FlowLayout());
+		
+		this.AndOperand1 = new CertainTrust(N);
+		this.HTIAndOperand1 = new CertainTrustHTI(this.AndOperand1);
+		AndPanel.add(this.HTIAndOperand1);
+
+		AndPanel.add(new Label("AND"));
+		
+		this.AndOperand2 = new CertainTrust(N);
+		this.HTIAndOperand2 = new CertainTrustHTI(this.AndOperand2);
+		AndPanel.add(this.HTIAndOperand2);
+		
+		AndPanel.add(new Label("="));
+		
+		this.AndResult = new CertainTrust(N);
+		Map<String,String> htiConfig = new HashMap<String, String>();
+		htiConfig.put("readonly", "true");
+		this.HTIAndResult = new CertainTrustHTI(this.AndResult, htiConfig);
+		AndPanel.add(this.HTIAndResult);
+		
+		constraints.insets = new Insets(30, 0, 10, 0);
+		constraints.gridwidth = GridBagConstraints.REMAINDER;
+		add(AndPanel, constraints);
+		
+		
+		// operands and result for OR operation
+		JPanel OrPanel = new JPanel();
+		OrPanel.setLayout(new FlowLayout());
+		
+		this.OrOperand1 = new CertainTrust(N);
+		this.HTIOrOperand1 = new CertainTrustHTI(this.OrOperand1);
+		OrPanel.add(this.HTIOrOperand1);
+
+		OrPanel.add(new Label("OR"));
+		
+		this.OrOperand2 = new CertainTrust(N);
+		this.HTIOrOperand2 = new CertainTrustHTI(this.OrOperand2);
+		OrPanel.add(this.HTIOrOperand2);
+		
+		OrPanel.add(new Label("="));
+		
+		this.OrResult = new CertainTrust(N);
+		this.HTIOrResult = new CertainTrustHTI(this.OrResult, htiConfig);
+		OrPanel.add(this.HTIOrResult);
+		
+		add(OrPanel, constraints);
+	}
+
+	/**
+	 * setupLogic() implements the wiring between the different CertainTrust data objects,
+	 * the HTIs get updates automatically due to the used Observer pattern
+	 */
+	private void setupLogic() {
+		// wire all components forming the AND operation
+		ANDObserver andObserver = new ANDObserver(AndOperand1, AndOperand2, AndResult);
+		AndOperand1.addObserver(andObserver);
+		AndOperand2.addObserver(andObserver);
+		
+		// do an initial update
+		andObserver.update(null, null);
+		
+		
+		// same for the OR operation
+		ORObserver orObserver = new ORObserver(OrOperand1, OrOperand2, OrResult);
+		OrOperand1.addObserver(orObserver);
+		OrOperand2.addObserver(orObserver);
+		orObserver.update(null, null);
+	}
+}

+ 152 - 0
Java/Java_Examples/JavaDemonstrator/src/DemonstratorCD.java

@@ -0,0 +1,152 @@
+/**
+ * CertainTrust Demonstrator in Java for CONSENSUS and DISCOUNTING
+ * 
+ * Demonstrates some capabilities of the CertainTrust SDK
+ * using a Java applet that interactively calculates
+ * AND and OR of two CertainTrust data objects and
+ * visually displays both the input objects and the output.
+ * 
+ * @author	Florian Volk <florian.volk@cased.de>
+ */
+
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Label;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.JApplet;
+import javax.swing.JPanel;
+
+import CertainTrust.CertainTrust;
+import CertainTrust.CertainTrustHTI;
+
+
+public class DemonstratorCD extends JApplet {
+	private static final long serialVersionUID = -7397289934413234935L;
+	
+	// the CertainTrust data objects
+	private CertainTrust CONOperand1;
+	private CertainTrust CONOperand2;
+	private CertainTrust CONResult;
+	private CertainTrust DISOperand1;
+	private CertainTrust DISOperand2;
+	private CertainTrust DISResult;
+	private static int N = 10;
+	
+	// the HTI objects that hold the CertainTrust data
+	private CertainTrustHTI HTIAndOperand1;
+	private CertainTrustHTI HTIAndOperand2;
+	private CertainTrustHTI HTIAndResult;
+	private CertainTrustHTI HTIOrOperand1;
+	private CertainTrustHTI HTIOrOperand2;
+	private CertainTrustHTI HTIOrResult;
+	
+
+	public DemonstratorCD() {
+		setupUI();
+		setupLogic();
+	}
+	
+	@Override
+	public void init() {
+		// make sure nothing is cut off due to a too small applet
+		setSize(1200, 500);
+	}
+	
+	/**
+	 * setupUI() creates the user interface and
+	 * binds all HTIs to the related CertainTrust data objects
+	 */
+	private void setupUI() {
+		// use GridBayLayout to align all the elements
+		GridBagConstraints constraints = new GridBagConstraints();
+		setLayout(new GridBagLayout());
+		
+		// title line "Demonstrator for CertainTrust"
+		constraints.gridwidth = GridBagConstraints.REMAINDER;
+		constraints.gridheight = 1;
+		constraints.insets = new Insets(10, 0, 0, 0);
+		Label title = new Label("Demonstrator for CertainTrust");
+		title.setFont(new Font("Sans Serif", Font.BOLD, 24));
+		add(title, constraints);
+		
+		// subtitle line
+		constraints.insets = new Insets(0, 0, 10, 0);
+		add(new Label("CertainTrust provides a means for the evaluation of propositional logic terms under uncertainty."), constraints);
+		
+		
+		// operands and result for CONSENSUS operation
+		JPanel CONPanel = new JPanel();
+		CONPanel.setLayout(new FlowLayout());
+		
+		this.CONOperand1 = new CertainTrust(N);
+		this.HTIAndOperand1 = new CertainTrustHTI(this.CONOperand1);
+		CONPanel.add(this.HTIAndOperand1);
+
+		CONPanel.add(new Label("CONSENSUS"));
+		
+		this.CONOperand2 = new CertainTrust(N);
+		this.HTIAndOperand2 = new CertainTrustHTI(this.CONOperand2);
+		CONPanel.add(this.HTIAndOperand2);
+		
+		CONPanel.add(new Label("="));
+		
+		this.CONResult = new CertainTrust(N);
+		Map<String,String> htiConfig = new HashMap<String, String>();
+		htiConfig.put("readonly", "true");
+		this.HTIAndResult = new CertainTrustHTI(this.CONResult, htiConfig);
+		CONPanel.add(this.HTIAndResult);
+		
+		constraints.insets = new Insets(30, 0, 10, 0);
+		constraints.gridwidth = GridBagConstraints.REMAINDER;
+		add(CONPanel, constraints);
+		
+		
+		// operands and result for DISCOUNTING operation
+		JPanel DISPanel = new JPanel();
+		DISPanel.setLayout(new FlowLayout());
+		
+		this.DISOperand1 = new CertainTrust(N);
+		this.HTIOrOperand1 = new CertainTrustHTI(this.DISOperand1);
+		DISPanel.add(this.HTIOrOperand1);
+
+		DISPanel.add(new Label("DISCOUNTING"));
+		
+		this.DISOperand2 = new CertainTrust(N);
+		this.HTIOrOperand2 = new CertainTrustHTI(this.DISOperand2);
+		DISPanel.add(this.HTIOrOperand2);
+		
+		DISPanel.add(new Label("="));
+		
+		this.DISResult = new CertainTrust(N);
+		this.HTIOrResult = new CertainTrustHTI(this.DISResult, htiConfig);
+		DISPanel.add(this.HTIOrResult);
+		
+		add(DISPanel, constraints);
+	}
+
+	/**
+	 * setupLogic() implements the wiring between the different CertainTrust data objects,
+	 * the HTIs get updates automatically due to the used Observer pattern
+	 */
+	private void setupLogic() {
+		// wire all components forming the CONSENSUS operation
+		CONSENSUSObserver conObserver = new CONSENSUSObserver(CONOperand1, CONOperand2, CONResult);
+		CONOperand1.addObserver(conObserver);
+		CONOperand2.addObserver(conObserver);
+		
+		// do an initial update
+		conObserver.update(null, null);
+		
+		
+		// same for the OR operation
+		DISCOUNTINGObserver disObserver = new DISCOUNTINGObserver(DISOperand1, DISOperand2, DISResult);
+		DISOperand1.addObserver(disObserver);
+		DISOperand2.addObserver(disObserver);
+		disObserver.update(null, null);
+	}
+}

+ 25 - 0
Java/Java_Examples/JavaDemonstrator/src/DemonstratorStarter.java

@@ -0,0 +1,25 @@
+/**
+ * CertainTrust Demonstrator in Java
+ * 
+ * This class allows the applet to run as Java application.
+ * 
+ * @author	Florian Volk <florian.volk@cased.de>
+ */
+
+public class DemonstratorStarter {
+
+	public static void main(String[] args) {
+		// create the applet
+		DemonstratorCD demonstrator = new DemonstratorCD();
+		demonstrator.init();
+		demonstrator.start();
+		
+		// host the applet in a swing window
+		javax.swing.JFrame window = new javax.swing.JFrame("CertainLogic Demonstrator");
+		window.setContentPane(demonstrator);
+		window.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
+		window.pack();
+		window.setVisible(true);
+	}
+
+}

+ 62 - 0
Java/Java_Examples/JavaDemonstrator/src/Minimal.java

@@ -0,0 +1,62 @@
+/**
+ * Minimal CertainTrust Demonstrator in Java
+ * 
+ * Demonstrates the basic usage of the CertainTrust SDK.
+ * 
+ * @author	Florian Volk <florian.volk@cased.de>
+ */
+
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+
+import CertainTrust.CertainTrust;
+import CertainTrust.CertainTrustHTI;
+
+
+public class Minimal extends JFrame implements ActionListener {
+	private static final long serialVersionUID = -447167281994322634L;
+
+	// this object stores the trust data and implements the operators
+	CertainTrust ctObject;
+	
+	public Minimal() {
+		setTitle("Minimal CertainTrust SDK Demonstrator");
+		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+		setLayout(new FlowLayout());
+		
+		
+		// display a single HTI
+		ctObject = new CertainTrust(10); // first, we need a CertainTrust data object
+		add(new CertainTrustHTI(ctObject));
+		
+		// add a button to read the CertainTrust values
+		JButton button = new JButton("Read CertainTrust values");
+		button.addActionListener(this);
+		add(button);
+		
+		
+		this.setSize(450, 250);
+		this.setVisible(true);
+	}
+	
+	@Override
+	public void actionPerformed(ActionEvent arg0) {
+		// whenever the button is clicked
+		JOptionPane.showMessageDialog(this,
+				"Values of the CertainTrust object:\n"
+				+ "\nInit. value: "	+ this.ctObject.getF()
+				+ "\nTrust: "		+ this.ctObject.getT()
+				+ "\nCertainty: "	+ this.ctObject.getC()
+				+ "\nExpectation: "	+ this.ctObject.getExpectation());
+	}
+	
+	
+	public static void main(String[] args) {
+		new Minimal();
+	}
+}

+ 35 - 0
Java/Java_Examples/JavaDemonstrator/src/ORObserver.java

@@ -0,0 +1,35 @@
+/**
+ * CertainTrust Demonstrator in Java
+ * 
+ * The ORObserver is used to update the result of the OR operation
+ * when the operands change and display the result in the result HTI.
+ * 
+ * @author	Florian Volk <florian.volk@cased.de>
+ */
+
+import java.util.Observable;
+import java.util.Observer;
+
+import CertainTrust.CertainTrust;
+
+
+public class ORObserver implements Observer {
+
+	private CertainTrust Operand1;
+	private CertainTrust Operand2;
+	private CertainTrust Result;
+	
+	public ORObserver(CertainTrust Operand1, CertainTrust Operand2, CertainTrust Result) {
+		this.Operand1 = Operand1;
+		this.Operand2 = Operand2;
+		this.Result = Result;
+	}
+
+	@Override
+	public void update(Observable arg0, Object arg1) {
+		// calculate the result of the AND operation and update the Result CertainTrust data object
+		CertainTrust ORResult = this.Operand1.OR(this.Operand2);
+		this.Result.setF(ORResult.getF());
+		this.Result.setTC(ORResult.getT(), ORResult.getC());
+	}
+}

+ 7 - 0
Java/Java_Examples/JavaSDKExample/.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="lib" path="D:/Hiwi/CertainTrustSDK-1.0_Update/Java/Java_SDK/CertainTrustSDK_Update.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 17 - 0
Java/Java_Examples/JavaSDKExample/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>JavaSDKExample</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

BIN
Java/Java_Examples/JavaSDKExample/bin/Minimal.class


+ 62 - 0
Java/Java_Examples/JavaSDKExample/src/Minimal.java

@@ -0,0 +1,62 @@
+/**
+ * Minimal CertainTrustSimple Demonstrator in Java
+ * 
+ * Demonstrates the basic usage of the CertainTrust SDK.
+ * 
+ * @author	Florian Volk <florian.volk@cased.de>
+ */
+
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+
+import CertainTrust.CertainTrustSimple;
+import CertainTrust.CertainTrustSimpleHTI;
+
+
+public class Minimal extends JFrame implements ActionListener {
+	private static final long serialVersionUID = -447167281994322634L;
+
+	// this object stores the trust data and implements the operators
+	CertainTrustSimple ctObject;
+	
+	public Minimal() {
+		setTitle("Minimal CertainTrust SDK Demonstrator");
+		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+		setLayout(new FlowLayout());
+		
+		
+		// display a single HTI
+		ctObject = new CertainTrustSimple(10); // first, we need a CertainTrust data object
+		add(new CertainTrustSimpleHTI(ctObject));
+		
+		// add a button to read the CertainTrust values
+		JButton button = new JButton("Read CertainTrust values");
+		button.addActionListener(this);
+		add(button);
+		
+		
+		this.setSize(450, 250);
+		this.setVisible(true);
+	}
+	
+	@Override
+	public void actionPerformed(ActionEvent arg0) {
+		// whenever the button is clicked
+		JOptionPane.showMessageDialog(this,
+				"Values of the CertainTrust object:\n"
+				+ "\nInit. value: "	+ this.ctObject.getF()
+				+ "\nTrust: "		+ this.ctObject.getT()
+				+ "\nCertainty: "	+ this.ctObject.getC()
+				+ "\nExpectation: "	+ this.ctObject.getExpectation());
+	}
+	
+	
+	public static void main(String[] args) {
+		new Minimal();
+	}
+}

+ 7 - 0
Java/Java_SDK/.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="lib" path="CertainTrustSDK-1.0.jar"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 17 - 0
Java/Java_SDK/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Java_SDK</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

BIN
Java/Java_SDK/CertainTrustSDK-1.0.jar


BIN
Java/Java_SDK/CertainTrustSDK_Update.jar


+ 373 - 0
Java/Java_SDK/Mozilla Public License Version 2.0.txt

@@ -0,0 +1,373 @@
+Mozilla Public License Version 2.0
+==================================
+
+1. Definitions
+--------------
+
+1.1. "Contributor"
+    means each individual or legal entity that creates, contributes to
+    the creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+    means the combination of the Contributions of others (if any) used
+    by a Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+    means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+    means Source Code Form to which the initial Contributor has attached
+    the notice in Exhibit A, the Executable Form of such Source Code
+    Form, and Modifications of such Source Code Form, in each case
+    including portions thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+    means
+
+    (a) that the initial Contributor has attached the notice described
+        in Exhibit B to the Covered Software; or
+
+    (b) that the Covered Software was made available under the terms of
+        version 1.1 or earlier of the License, but not also under the
+        terms of a Secondary License.
+
+1.6. "Executable Form"
+    means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+    means a work that combines Covered Software with other material, in 
+    a separate file or files, that is not Covered Software.
+
+1.8. "License"
+    means this document.
+
+1.9. "Licensable"
+    means having the right to grant, to the maximum extent possible,
+    whether at the time of the initial grant or subsequently, any and
+    all of the rights conveyed by this License.
+
+1.10. "Modifications"
+    means any of the following:
+
+    (a) any file in Source Code Form that results from an addition to,
+        deletion from, or modification of the contents of Covered
+        Software; or
+
+    (b) any new file in Source Code Form that contains any Covered
+        Software.
+
+1.11. "Patent Claims" of a Contributor
+    means any patent claim(s), including without limitation, method,
+    process, and apparatus claims, in any patent Licensable by such
+    Contributor that would be infringed, but for the grant of the
+    License, by the making, using, selling, offering for sale, having
+    made, import, or transfer of either its Contributions or its
+    Contributor Version.
+
+1.12. "Secondary License"
+    means either the GNU General Public License, Version 2.0, the GNU
+    Lesser General Public License, Version 2.1, the GNU Affero General
+    Public License, Version 3.0, or any later versions of those
+    licenses.
+
+1.13. "Source Code Form"
+    means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+    means an individual or a legal entity exercising rights under this
+    License. For legal entities, "You" includes any entity that
+    controls, is controlled by, or is under common control with You. For
+    purposes of this definition, "control" means (a) the power, direct
+    or indirect, to cause the direction or management of such entity,
+    whether by contract or otherwise, or (b) ownership of more than
+    fifty percent (50%) of the outstanding shares or beneficial
+    ownership of such entity.
+
+2. License Grants and Conditions
+--------------------------------
+
+2.1. Grants
+
+Each Contributor hereby grants You a world-wide, royalty-free,
+non-exclusive license:
+
+(a) under intellectual property rights (other than patent or trademark)
+    Licensable by such Contributor to use, reproduce, make available,
+    modify, display, perform, distribute, and otherwise exploit its
+    Contributions, either on an unmodified basis, with Modifications, or
+    as part of a Larger Work; and
+
+(b) under Patent Claims of such Contributor to make, use, sell, offer
+    for sale, have made, import, and otherwise transfer either its
+    Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+The licenses granted in Section 2.1 with respect to any Contribution
+become effective for each Contribution on the date the Contributor first
+distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+The licenses granted in this Section 2 are the only rights granted under
+this License. No additional rights or licenses will be implied from the
+distribution or licensing of Covered Software under this License.
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
+Contributor:
+
+(a) for any code that a Contributor has removed from Covered Software;
+    or
+
+(b) for infringements caused by: (i) Your and any other third party's
+    modifications of Covered Software, or (ii) the combination of its
+    Contributions with other software (except as part of its Contributor
+    Version); or
+
+(c) under Patent Claims infringed by Covered Software in the absence of
+    its Contributions.
+
+This License does not grant any rights in the trademarks, service marks,
+or logos of any Contributor (except as may be necessary to comply with
+the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+No Contributor makes additional grants as a result of Your choice to
+distribute the Covered Software under a subsequent version of this
+License (see Section 10.2) or under the terms of a Secondary License (if
+permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+Each Contributor represents that the Contributor believes its
+Contributions are its original creation(s) or it has sufficient rights
+to grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+This License is not intended to limit any rights You have under
+applicable copyright doctrines of fair use, fair dealing, or other
+equivalents.
+
+2.7. Conditions
+
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
+in Section 2.1.
+
+3. Responsibilities
+-------------------
+
+3.1. Distribution of Source Form
+
+All distribution of Covered Software in Source Code Form, including any
+Modifications that You create or to which You contribute, must be under
+the terms of this License. You must inform recipients that the Source
+Code Form of the Covered Software is governed by the terms of this
+License, and how they can obtain a copy of this License. You may not
+attempt to alter or restrict the recipients' rights in the Source Code
+Form.
+
+3.2. Distribution of Executable Form
+
+If You distribute Covered Software in Executable Form then:
+
+(a) such Covered Software must also be made available in Source Code
+    Form, as described in Section 3.1, and You must inform recipients of
+    the Executable Form how they can obtain a copy of such Source Code
+    Form by reasonable means in a timely manner, at a charge no more
+    than the cost of distribution to the recipient; and
+
+(b) You may distribute such Executable Form under the terms of this
+    License, or sublicense it under different terms, provided that the
+    license for the Executable Form does not attempt to limit or alter
+    the recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+You may create and distribute a Larger Work under terms of Your choice,
+provided that You also comply with the requirements of this License for
+the Covered Software. If the Larger Work is a combination of Covered
+Software with a work governed by one or more Secondary Licenses, and the
+Covered Software is not Incompatible With Secondary Licenses, this
+License permits You to additionally distribute such Covered Software
+under the terms of such Secondary License(s), so that the recipient of
+the Larger Work may, at their option, further distribute the Covered
+Software under the terms of either this License or such Secondary
+License(s).
+
+3.4. Notices
+
+You may not remove or alter the substance of any license notices
+(including copyright notices, patent notices, disclaimers of warranty,
+or limitations of liability) contained within the Source Code Form of
+the Covered Software, except that You may alter any license notices to
+the extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+You may choose to offer, and to charge a fee for, warranty, support,
+indemnity or liability obligations to one or more recipients of Covered
+Software. However, You may do so only on Your own behalf, and not on
+behalf of any Contributor. You must make it absolutely clear that any
+such warranty, support, indemnity, or liability obligation is offered by
+You alone, and You hereby agree to indemnify every Contributor for any
+liability incurred by such Contributor as a result of warranty, support,
+indemnity or liability terms You offer. You may include additional
+disclaimers of warranty and limitations of liability specific to any
+jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+---------------------------------------------------
+
+If it is impossible for You to comply with any of the terms of this
+License with respect to some or all of the Covered Software due to
+statute, judicial order, or regulation then You must: (a) comply with
+the terms of this License to the maximum extent possible; and (b)
+describe the limitations and the code they affect. Such description must
+be placed in a text file included with all distributions of the Covered
+Software under this License. Except to the extent prohibited by statute
+or regulation, such description must be sufficiently detailed for a
+recipient of ordinary skill to be able to understand it.
+
+5. Termination
+--------------
+
+5.1. The rights granted under this License will terminate automatically
+if You fail to comply with any of its terms. However, if You become
+compliant, then the rights granted under this License from a particular
+Contributor are reinstated (a) provisionally, unless and until such
+Contributor explicitly and finally terminates Your grants, and (b) on an
+ongoing basis, if such Contributor fails to notify You of the
+non-compliance by some reasonable means prior to 60 days after You have
+come back into compliance. Moreover, Your grants from a particular
+Contributor are reinstated on an ongoing basis if such Contributor
+notifies You of the non-compliance by some reasonable means, this is the
+first time You have received notice of non-compliance with this License
+from such Contributor, and You become compliant prior to 30 days after
+Your receipt of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+infringement claim (excluding declaratory judgment actions,
+counter-claims, and cross-claims) alleging that a Contributor Version
+directly or indirectly infringes any patent, then the rights granted to
+You by any and all Contributors for the Covered Software under Section
+2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
+end user license agreements (excluding distributors and resellers) which
+have been validly granted by You or Your distributors under this License
+prior to termination shall survive termination.
+
+************************************************************************
+*                                                                      *
+*  6. Disclaimer of Warranty                                           *
+*  -------------------------                                           *
+*                                                                      *
+*  Covered Software is provided under this License on an "as is"       *
+*  basis, without warranty of any kind, either expressed, implied, or  *
+*  statutory, including, without limitation, warranties that the       *
+*  Covered Software is free of defects, merchantable, fit for a        *
+*  particular purpose or non-infringing. The entire risk as to the     *
+*  quality and performance of the Covered Software is with You.        *
+*  Should any Covered Software prove defective in any respect, You     *
+*  (not any Contributor) assume the cost of any necessary servicing,   *
+*  repair, or correction. This disclaimer of warranty constitutes an   *
+*  essential part of this License. No use of any Covered Software is   *
+*  authorized under this License except under this disclaimer.         *
+*                                                                      *
+************************************************************************
+
+************************************************************************
+*                                                                      *
+*  7. Limitation of Liability                                          *
+*  --------------------------                                          *
+*                                                                      *
+*  Under no circumstances and under no legal theory, whether tort      *
+*  (including negligence), contract, or otherwise, shall any           *
+*  Contributor, or anyone who distributes Covered Software as          *
+*  permitted above, be liable to You for any direct, indirect,         *
+*  special, incidental, or consequential damages of any character      *
+*  including, without limitation, damages for lost profits, loss of    *
+*  goodwill, work stoppage, computer failure or malfunction, or any    *
+*  and all other commercial damages or losses, even if such party      *
+*  shall have been informed of the possibility of such damages. This   *
+*  limitation of liability shall not apply to liability for death or   *
+*  personal injury resulting from such party's negligence to the       *
+*  extent applicable law prohibits such limitation. Some               *
+*  jurisdictions do not allow the exclusion or limitation of           *
+*  incidental or consequential damages, so this exclusion and          *
+*  limitation may not apply to You.                                    *
+*                                                                      *
+************************************************************************
+
+8. Litigation
+-------------
+
+Any litigation relating to this License may be brought only in the
+courts of a jurisdiction where the defendant maintains its principal
+place of business and such litigation shall be governed by laws of that
+jurisdiction, without reference to its conflict-of-law provisions.
+Nothing in this Section shall prevent a party's ability to bring
+cross-claims or counter-claims.
+
+9. Miscellaneous
+----------------
+
+This License represents the complete agreement concerning the subject
+matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent
+necessary to make it enforceable. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+shall not be used to construe this License against a Contributor.
+
+10. Versions of the License
+---------------------------
+
+10.1. New Versions
+
+Mozilla Foundation is the license steward. Except as provided in Section
+10.3, no one other than the license steward has the right to modify or
+publish new versions of this License. Each version will be given a
+distinguishing version number.
+
+10.2. Effect of New Versions
+
+You may distribute the Covered Software under the terms of the version
+of the License under which You originally received the Covered Software,
+or under the terms of any subsequent version published by the license
+steward.
+
+10.3. Modified Versions
+
+If you create software not governed by this License, and you want to
+create a new license for such software, you may create and use a
+modified version of this License if you rename the license and remove
+any references to the name of the license steward (except to note that
+such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+Licenses
+
+If You choose to distribute Source Code Form that is Incompatible With
+Secondary Licenses under the terms of this version of the License, the
+notice described in Exhibit B of this License must be attached.
+
+Exhibit A - Source Code Form License Notice
+-------------------------------------------
+
+  This Source Code Form is subject to the terms of the Mozilla Public
+  License, v. 2.0. If a copy of the MPL was not distributed with this
+  file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular
+file, then You may include the notice in a location (such as a LICENSE
+file in a relevant directory) where a recipient would be likely to look
+for such a notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+---------------------------------------------------------
+
+  This Source Code Form is "Incompatible With Secondary Licenses", as
+  defined by the Mozilla Public License, v. 2.0.

BIN
Java/Java_SDK/bin/CertainTrust/CertainTrust.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustCanvas$1.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustCanvas$2.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustCanvas.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustHTI$1.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustHTI$2.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustHTI$3.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustHTI$CertainTrustActionFocusListener.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustHTI.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustSimple.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleCanvas$1.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleCanvas$2.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleCanvas.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleHTI$1.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleHTI$2.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleHTI$3.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleHTI$CertainTrustActionFocusListener.class


BIN
Java/Java_SDK/bin/CertainTrust/CertainTrustSimpleHTI.class


+ 373 - 0
Java/Java_SDK/bin/CertainTrust/Mozilla Public License Version 2.0.txt

@@ -0,0 +1,373 @@
+Mozilla Public License Version 2.0
+==================================
+
+1. Definitions
+--------------
+
+1.1. "Contributor"
+    means each individual or legal entity that creates, contributes to
+    the creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+    means the combination of the Contributions of others (if any) used
+    by a Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+    means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+    means Source Code Form to which the initial Contributor has attached
+    the notice in Exhibit A, the Executable Form of such Source Code
+    Form, and Modifications of such Source Code Form, in each case
+    including portions thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+    means
+
+    (a) that the initial Contributor has attached the notice described
+        in Exhibit B to the Covered Software; or
+
+    (b) that the Covered Software was made available under the terms of
+        version 1.1 or earlier of the License, but not also under the
+        terms of a Secondary License.
+
+1.6. "Executable Form"
+    means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+    means a work that combines Covered Software with other material, in 
+    a separate file or files, that is not Covered Software.
+
+1.8. "License"
+    means this document.
+
+1.9. "Licensable"
+    means having the right to grant, to the maximum extent possible,
+    whether at the time of the initial grant or subsequently, any and
+    all of the rights conveyed by this License.
+
+1.10. "Modifications"
+    means any of the following:
+
+    (a) any file in Source Code Form that results from an addition to,
+        deletion from, or modification of the contents of Covered
+        Software; or
+
+    (b) any new file in Source Code Form that contains any Covered
+        Software.
+
+1.11. "Patent Claims" of a Contributor
+    means any patent claim(s), including without limitation, method,
+    process, and apparatus claims, in any patent Licensable by such
+    Contributor that would be infringed, but for the grant of the
+    License, by the making, using, selling, offering for sale, having
+    made, import, or transfer of either its Contributions or its
+    Contributor Version.
+
+1.12. "Secondary License"
+    means either the GNU General Public License, Version 2.0, the GNU
+    Lesser General Public License, Version 2.1, the GNU Affero General
+    Public License, Version 3.0, or any later versions of those
+    licenses.
+
+1.13. "Source Code Form"
+    means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+    means an individual or a legal entity exercising rights under this
+    License. For legal entities, "You" includes any entity that
+    controls, is controlled by, or is under common control with You. For
+    purposes of this definition, "control" means (a) the power, direct
+    or indirect, to cause the direction or management of such entity,
+    whether by contract or otherwise, or (b) ownership of more than
+    fifty percent (50%) of the outstanding shares or beneficial
+    ownership of such entity.
+
+2. License Grants and Conditions
+--------------------------------
+
+2.1. Grants
+
+Each Contributor hereby grants You a world-wide, royalty-free,
+non-exclusive license:
+
+(a) under intellectual property rights (other than patent or trademark)
+    Licensable by such Contributor to use, reproduce, make available,
+    modify, display, perform, distribute, and otherwise exploit its
+    Contributions, either on an unmodified basis, with Modifications, or
+    as part of a Larger Work; and
+
+(b) under Patent Claims of such Contributor to make, use, sell, offer
+    for sale, have made, import, and otherwise transfer either its
+    Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+The licenses granted in Section 2.1 with respect to any Contribution
+become effective for each Contribution on the date the Contributor first
+distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+The licenses granted in this Section 2 are the only rights granted under
+this License. No additional rights or licenses will be implied from the
+distribution or licensing of Covered Software under this License.
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
+Contributor:
+
+(a) for any code that a Contributor has removed from Covered Software;
+    or
+
+(b) for infringements caused by: (i) Your and any other third party's
+    modifications of Covered Software, or (ii) the combination of its
+    Contributions with other software (except as part of its Contributor
+    Version); or
+
+(c) under Patent Claims infringed by Covered Software in the absence of
+    its Contributions.
+
+This License does not grant any rights in the trademarks, service marks,
+or logos of any Contributor (except as may be necessary to comply with
+the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+No Contributor makes additional grants as a result of Your choice to
+distribute the Covered Software under a subsequent version of this
+License (see Section 10.2) or under the terms of a Secondary License (if
+permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+Each Contributor represents that the Contributor believes its
+Contributions are its original creation(s) or it has sufficient rights
+to grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+This License is not intended to limit any rights You have under
+applicable copyright doctrines of fair use, fair dealing, or other
+equivalents.
+
+2.7. Conditions
+
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
+in Section 2.1.
+
+3. Responsibilities
+-------------------
+
+3.1. Distribution of Source Form
+
+All distribution of Covered Software in Source Code Form, including any
+Modifications that You create or to which You contribute, must be under
+the terms of this License. You must inform recipients that the Source
+Code Form of the Covered Software is governed by the terms of this
+License, and how they can obtain a copy of this License. You may not
+attempt to alter or restrict the recipients' rights in the Source Code
+Form.
+
+3.2. Distribution of Executable Form
+
+If You distribute Covered Software in Executable Form then:
+
+(a) such Covered Software must also be made available in Source Code
+    Form, as described in Section 3.1, and You must inform recipients of
+    the Executable Form how they can obtain a copy of such Source Code
+    Form by reasonable means in a timely manner, at a charge no more
+    than the cost of distribution to the recipient; and
+
+(b) You may distribute such Executable Form under the terms of this
+    License, or sublicense it under different terms, provided that the
+    license for the Executable Form does not attempt to limit or alter
+    the recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+You may create and distribute a Larger Work under terms of Your choice,
+provided that You also comply with the requirements of this License for
+the Covered Software. If the Larger Work is a combination of Covered
+Software with a work governed by one or more Secondary Licenses, and the
+Covered Software is not Incompatible With Secondary Licenses, this
+License permits You to additionally distribute such Covered Software
+under the terms of such Secondary License(s), so that the recipient of
+the Larger Work may, at their option, further distribute the Covered
+Software under the terms of either this License or such Secondary
+License(s).
+
+3.4. Notices
+
+You may not remove or alter the substance of any license notices
+(including copyright notices, patent notices, disclaimers of warranty,
+or limitations of liability) contained within the Source Code Form of
+the Covered Software, except that You may alter any license notices to
+the extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+You may choose to offer, and to charge a fee for, warranty, support,
+indemnity or liability obligations to one or more recipients of Covered
+Software. However, You may do so only on Your own behalf, and not on
+behalf of any Contributor. You must make it absolutely clear that any
+such warranty, support, indemnity, or liability obligation is offered by
+You alone, and You hereby agree to indemnify every Contributor for any
+liability incurred by such Contributor as a result of warranty, support,
+indemnity or liability terms You offer. You may include additional
+disclaimers of warranty and limitations of liability specific to any
+jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+---------------------------------------------------
+
+If it is impossible for You to comply with any of the terms of this
+License with respect to some or all of the Covered Software due to
+statute, judicial order, or regulation then You must: (a) comply with
+the terms of this License to the maximum extent possible; and (b)
+describe the limitations and the code they affect. Such description must
+be placed in a text file included with all distributions of the Covered
+Software under this License. Except to the extent prohibited by statute
+or regulation, such description must be sufficiently detailed for a
+recipient of ordinary skill to be able to understand it.
+
+5. Termination
+--------------
+
+5.1. The rights granted under this License will terminate automatically
+if You fail to comply with any of its terms. However, if You become
+compliant, then the rights granted under this License from a particular
+Contributor are reinstated (a) provisionally, unless and until such
+Contributor explicitly and finally terminates Your grants, and (b) on an
+ongoing basis, if such Contributor fails to notify You of the
+non-compliance by some reasonable means prior to 60 days after You have
+come back into compliance. Moreover, Your grants from a particular
+Contributor are reinstated on an ongoing basis if such Contributor
+notifies You of the non-compliance by some reasonable means, this is the
+first time You have received notice of non-compliance with this License
+from such Contributor, and You become compliant prior to 30 days after
+Your receipt of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+infringement claim (excluding declaratory judgment actions,
+counter-claims, and cross-claims) alleging that a Contributor Version
+directly or indirectly infringes any patent, then the rights granted to
+You by any and all Contributors for the Covered Software under Section
+2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
+end user license agreements (excluding distributors and resellers) which
+have been validly granted by You or Your distributors under this License
+prior to termination shall survive termination.
+
+************************************************************************
+*                                                                      *
+*  6. Disclaimer of Warranty                                           *
+*  -------------------------                                           *
+*                                                                      *
+*  Covered Software is provided under this License on an "as is"       *
+*  basis, without warranty of any kind, either expressed, implied, or  *
+*  statutory, including, without limitation, warranties that the       *
+*  Covered Software is free of defects, merchantable, fit for a        *
+*  particular purpose or non-infringing. The entire risk as to the     *
+*  quality and performance of the Covered Software is with You.        *
+*  Should any Covered Software prove defective in any respect, You     *
+*  (not any Contributor) assume the cost of any necessary servicing,   *
+*  repair, or correction. This disclaimer of warranty constitutes an   *
+*  essential part of this License. No use of any Covered Software is   *
+*  authorized under this License except under this disclaimer.         *
+*                                                                      *
+************************************************************************
+
+************************************************************************
+*                                                                      *
+*  7. Limitation of Liability                                          *
+*  --------------------------                                          *
+*                                                                      *
+*  Under no circumstances and under no legal theory, whether tort      *
+*  (including negligence), contract, or otherwise, shall any           *
+*  Contributor, or anyone who distributes Covered Software as          *
+*  permitted above, be liable to You for any direct, indirect,         *
+*  special, incidental, or consequential damages of any character      *
+*  including, without limitation, damages for lost profits, loss of    *
+*  goodwill, work stoppage, computer failure or malfunction, or any    *
+*  and all other commercial damages or losses, even if such party      *
+*  shall have been informed of the possibility of such damages. This   *
+*  limitation of liability shall not apply to liability for death or   *
+*  personal injury resulting from such party's negligence to the       *
+*  extent applicable law prohibits such limitation. Some               *
+*  jurisdictions do not allow the exclusion or limitation of           *
+*  incidental or consequential damages, so this exclusion and          *
+*  limitation may not apply to You.                                    *
+*                                                                      *
+************************************************************************
+
+8. Litigation
+-------------
+
+Any litigation relating to this License may be brought only in the
+courts of a jurisdiction where the defendant maintains its principal
+place of business and such litigation shall be governed by laws of that
+jurisdiction, without reference to its conflict-of-law provisions.
+Nothing in this Section shall prevent a party's ability to bring
+cross-claims or counter-claims.
+
+9. Miscellaneous
+----------------
+
+This License represents the complete agreement concerning the subject
+matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent
+necessary to make it enforceable. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+shall not be used to construe this License against a Contributor.
+
+10. Versions of the License
+---------------------------
+
+10.1. New Versions
+
+Mozilla Foundation is the license steward. Except as provided in Section
+10.3, no one other than the license steward has the right to modify or
+publish new versions of this License. Each version will be given a
+distinguishing version number.
+
+10.2. Effect of New Versions
+
+You may distribute the Covered Software under the terms of the version
+of the License under which You originally received the Covered Software,
+or under the terms of any subsequent version published by the license
+steward.
+
+10.3. Modified Versions
+
+If you create software not governed by this License, and you want to
+create a new license for such software, you may create and use a
+modified version of this License if you rename the license and remove
+any references to the name of the license steward (except to note that
+such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+Licenses
+
+If You choose to distribute Source Code Form that is Incompatible With
+Secondary Licenses under the terms of this version of the License, the
+notice described in Exhibit B of this License must be attached.
+
+Exhibit A - Source Code Form License Notice
+-------------------------------------------
+
+  This Source Code Form is subject to the terms of the Mozilla Public
+  License, v. 2.0. If a copy of the MPL was not distributed with this
+  file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular
+file, then You may include the notice in a location (such as a LICENSE
+file in a relevant directory) where a recipient would be likely to look
+for such a notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+---------------------------------------------------------
+
+  This Source Code Form is "Incompatible With Secondary Licenses", as
+  defined by the Mozilla Public License, v. 2.0.

BIN
Java/Java_SDK/bin/CertainTrust/VerticalLabelUI.class


+ 782 - 0
Java/Java_SDK/src/CertainTrust/CertainTrust.java

@@ -0,0 +1,782 @@
+/**
+ * CertainTrust SDK
+ * 
+ * Implements the computational trust model "CertainTrust"
+ * in Java.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ * 
+ * 
+ * Telecooperation Department, Technische Universit�t Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ * 
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ * 
+ * 
+ * @author	Maria Pelevina
+ * @author	David Kalnischkies
+ * @version	1.1
+ */
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+package CertainTrust;
+import java.util.Observable;
+
+/**
+ * 
+ * t - average rating value, [0; 1], from very negative to very positive
+ * c - certainty value, [0; 1] from low certainty (no evidence) to the maximal maximal certainty.
+ * f - initial trust value
+ * w - weight
+ * r - number of positive evidence
+ * s - number of negative evidence
+ * n - maximal number of expected evidence
+ * doc - degree of conflict
+ * 
+ */
+public class CertainTrust extends Observable {
+	
+	private double c, t, f, r, s, doc;
+	private int n, weight = 2;
+
+//=========== Constructors =================
+	/**
+	 * Constructs a CertainTrust object with predefined n value.
+	 * @param n - maximal number of expected evidence
+	 */
+	public CertainTrust(int n) {
+		if (n > 0) {
+			this.n = n;
+			c = 0;
+			t = 0.5;
+			f = 0.5;
+			r = 0;
+			s = 0;
+		}
+		else throw new IllegalArgumentException("N should be greater than 0. Entered n = " + n + "\n");
+	}
+	
+	/**
+	 * Constructs a CertainTrust object with predefined r, s, n values. 
+	 * @param r - number of positive evidence
+	 * @param s - number of negative evidence
+	 * @param n - maximal number of expected evidence
+	 */
+	public CertainTrust(double r, double s, int n) {
+		if (n > 0) {
+			this.n = n;
+			this.c = 0;
+			this.t = 0.5;
+			this.f = 0.5;
+			this.doc = 0;
+			setRS(r, s);
+		}
+		else throw new IllegalArgumentException("N should be greater than 0. Entered n = " + n + "\n");
+	}
+	
+	/**
+	 * Constructs a CertainTrust object with predefined c, t, f, n values. 
+	 * @param c - certainty
+	 * @param t - average rating
+	 * @param f - initial trust value
+	 * @param n - maximal number of expected evidence
+	 */
+	public CertainTrust(double t, double c, double f, int n) {
+		this(t,c,f,n,0);
+	}
+	
+	/**
+	 * Constructs a CertainTrust object with predefined c, t, f, n values. 
+	 * @param c - certainty
+	 * @param t - average rating
+	 * @param f - initial trust value
+	 * @param n - maximal number of expected evidence
+	 * @param doc - initial degree of conflict
+	 */
+	private CertainTrust(double t, double c, double f, int n, double doc) {
+		if (n > 0) {
+			if (f <= 1 && f >= 0) {
+				this.n = n;
+				this.f = f;
+				this.r = 0;
+				this.s = 0;
+				this.doc = doc;
+				setTC(t, c);
+			}
+			else throw new IllegalArgumentException("f should lie within [0;1]. Entered f = " + f + "\n");
+		}
+		else throw new IllegalArgumentException("N should be greater than 0. Entered n = " + n + "\n");
+	}
+	
+	//=========== Setters =================
+	/**
+	 * Resets N value. Renormalises r and s values, recalculates c and t accordingly.  
+	 * @param n - new maximal number of expected evidence
+	 */
+	public void setN(int n) {
+		if (n > 0) {
+			this.n = n;
+			normaliseRS();
+			calculateRStoTC();
+			
+			setChanged();
+			notifyObservers();
+		}
+		else throw new IllegalArgumentException("N should be greater than 0. Entered n = " + n + "\n");
+	}
+	
+	/**
+	 * Sets f value.
+	 * @param f - initial trust value.
+	 */
+	public void setF(double f) {
+		if (f >= 0 && f <= 1) {
+			this.f = f;
+			
+			setChanged();
+			notifyObservers();
+		}
+		
+		else throw new IllegalArgumentException("f should lie within [0;1]. Entered f = " + f + "\n");
+	}
+
+	/**
+	  * Sets Distance of Conflict value.
+	  * @param doc is the new value for DoC
+	  */
+	public void setDoC(double doc) {
+		if (doc > 0) {
+			this.doc = doc;
+		}
+		else throw new IllegalArgumentException("DoC should be greater than 0. Entered DoC = " + doc + "\n");
+	}
+	
+	/**
+	 * Sets c and t values. Recalculates r and s values accordingly.
+	 * @param t - new average trust value
+	 * @param c - new certainty value
+	 */
+	public void setTC(double t, double c) {
+		if (c >= 0 && c <= 1) {
+			if (t >= 0 && t <= 1) {
+				this.c = c;
+				this.t = t;
+				calculateTCtoRS();
+				
+				setChanged();
+				notifyObservers();
+			}
+			else throw new IllegalArgumentException("t should be greater than 0. Entered t = " + t + "\n");
+		}
+		else throw new IllegalArgumentException("c should lie within [0;1]. Entered c = " + c + "\n");
+	}
+	/**
+	 * Sets r and s values. Recalculates c and t values accordingly.
+	 * @param r - new number of positive evidence
+	 * @param s - new number of negative evidence
+	 */
+	public void setRS(double r, double s) {
+		if (r >= 0) {
+			if (s >= 0) {
+				this.r = r;
+				this.s = s;
+				normaliseRS();
+				calculateRStoTC();
+				
+				setChanged();
+				notifyObservers();
+			}
+			else throw new IllegalArgumentException("s should be positive. Entered s = " + s + "\n");
+		}
+		else throw new IllegalArgumentException("r should be positive. Entered r = " + r + "\n");
+	}
+	
+	/**
+	 * Add some positive evidence to r.
+	 * @param posEvidence - number of new positive evidences
+	 */
+	public void addR(int posEvidence) {
+		if (posEvidence >= 0) {
+			r += posEvidence;
+			normaliseRS();
+			calculateRStoTC();
+			
+			setChanged();
+			notifyObservers();
+		}
+		else throw new IllegalArgumentException("Number of positive evidences should be positive. Entered " + posEvidence + "\n");
+	}
+	
+	/**
+	 * Add some negative evidence to s.
+	 * @param negEvidence - number of new negative evidences
+	 */
+	public void addS(int negEvidence) {
+		if (negEvidence >= 0) {
+			s += negEvidence;
+			normaliseRS();
+			calculateRStoTC();
+			
+			setChanged();
+			notifyObservers();
+		}
+		else throw new IllegalArgumentException("Number of negative evidences should be positive. Entered " + negEvidence + "\n");
+	}
+	
+//=========== Internal Calculations ==========
+	/**
+	 * Normalises r and s values according to n - maximal number of expected evidence
+	 * Important! Doesn't notify observers.
+	 */
+	private void normaliseRS() {
+		if (r + s > n){
+			double initR = r;
+			r = r*n / (initR + s);
+			s = s*n / (initR + s);
+		}
+	}
+	/**
+	 * Calculates c and t values based on existing r and s values
+	 * Important! Doesn't notify observers.
+	 */
+	private void calculateRStoTC() {
+		c = n * (r + s) / ( weight*(n-r-s) + n*(r+s));
+		if (c == 0)
+			t = 0.5;
+		else t = r / (r + s);
+	}
+	
+	/**
+	 * Calculates r and s values based on existing c and t values
+	 * Important! Doesn't notify observers.
+	 */
+	private void calculateTCtoRS() {
+		if (c == 0) {
+			r = 0;
+			s = 0;
+			t = 0.5;
+		}
+		else {
+			r = (2*c*weight*n*t) / (2*c*weight + n - c*n);
+			s = (2*c*weight*n - 2*c*weight*n*t) / (2*c*weight + n - c*n);
+		}
+	}
+	
+//=========== Getters =================
+	public double getC() {
+		return c;
+	}
+
+	public double getT() {
+		return t;
+	}
+
+	public double getF() {
+		return f;
+	}
+
+	public double getR() {
+		return r;
+	}
+
+	public double getS() {
+		return s;
+	}
+
+	public int getN() {
+		return n;
+	}
+	
+	public double getDoC() {
+		return doc;
+	}
+	
+	public double getExpectation() {
+		return t*c + (1-c)*f;
+	}
+	
+//=========== Logic =================
+	/**
+	 * Computes OR function for this CertainTrust object and the specified argument. Result is returned as a new object,
+	 * argument and this CertainTrust object remain unchanged.
+	 * N values of both objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param arg - CertainTrust object
+	 * @return - result of OR computation for this object and an argument.
+	 */
+	
+	private CertainTrust OR(CertainTrust arg){
+		double c1 = getC();
+		double t1 = getT();
+		double f1 = getF();
+		
+		double c2 = arg.getC();
+		double t2 = arg.getT();
+		double f2 = arg.getF();
+		
+		double resT = 0.5, resF = 0.5, resC = 0;
+		
+		if (this.getN() != arg.getN()) 
+			throw new IllegalStateException("Different N values. Operation not allowed. \n");
+				
+		resF = f1 + f2 - f1*f2;
+		if (almostEqual(resF, 0))
+			resC = c1 + c2 - c1*c2;
+		else 
+			resC = c1 + c2 - c1*c2 - (c1*f2*(1-c2)*(1-t1)+c2*f1*(1-c1)*(1-t2)) / resF;
+		
+		if (almostEqual(resC, 0)) 
+			resT = 0.5;	
+		else resT = (1/resC) * (c1*t1 + c2*t2 - c1*c2*t1*t2);
+		
+		resT = adjustValue(resT);
+		resC = adjustValue(resC);
+		resF = adjustValue(resF);
+		
+		CertainTrust result = new CertainTrust(resT, resC, resF, n, 0); 
+			
+		return result;	
+	}
+	/**
+	 * Computes OR function for this CertainTrust object and the specified arguments. 
+	 * Result is returned as a new object, arguments and this CertainTrust object remain unchanged.
+	 * Example: a.OR(b, c, d) returns new CertainTrust object that equals a OR b OR c OR d.
+	 * Multiple arguments allowed, but not less than one.
+	 * N values of all objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param args - arguments
+	 * @return - result of OR computation for this object and all arguments.
+	 */
+	public CertainTrust OR(CertainTrust ...args) {
+		CertainTrust result = clone();
+		for (CertainTrust m: args) {
+			if (n != m.getN())
+				throw new IllegalStateException("Different N values. Operation not allowed. \n");
+			result = result.OR(m);
+		}
+			
+		return result;
+	}
+	
+	/**
+	 * Computes AND function for this CertainTrust object and the specified argument. Result is returned as a new object,
+	 * argument and this CertainTrust object remain unchanged.
+	 * N values of both objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param arg - CertainTrust object
+	 * @return - result of AND computation for this object and an argument.
+	 */
+	private CertainTrust AND(CertainTrust arg){
+		double c1 = getC();
+		double f1 = getF();
+		double t1 = getT();
+		
+		double c2 = arg.getC();
+		double f2 = arg.getF();
+		double t2 = arg.getT();
+		
+		double resC = 0, resT = 0.5, resF = 0.5;
+		
+		if (n != arg.getN()) 
+			throw new IllegalStateException("Different N values. Operation not allowed. \n");
+		
+		resF = f1*f2;
+		
+		if (almostEqual(resF, 1))		//avoid division by 0
+			resC = c1 + c2 - c1*c2;
+		else
+			resC = c1 + c2 - c1*c2 - (c2*t2*(1-c1)*(1-f1)+c1*t1*(1-c2)*(1-f2)) / (1 - resF);
+		
+		if (almostEqual(resC, 0)) 
+			resT = 0.5;
+		else if (almostEqual(resF, 1))	//avoid division by 0
+			resT = (1/resC) *  (c1*t1*c2*t2);
+		else resT = (1/resC) *  ((c1*t1*c2*t2) + (c1*f2*t1*(1-c2)*(1-f1)+c2*f1*t2*(1-c1)*(1-f2)) / (1 - resF));
+		
+		resT = adjustValue(resT);
+		resC = adjustValue(resC);
+		resF = adjustValue(resF);
+		
+		CertainTrust result = new CertainTrust(resT, resC, resF, n, 0);
+			
+		return result;
+	}
+	
+	/**
+	 * Computes AND function for this CertainTrust object and the specified arguments. 
+	 * Result is returned as a new object, arguments and this CertainTrust object remain unchanged.
+	 * Example: a.AND(b, c, d) returns new CertainTrust object that equals a AND b AND c AND d.
+	 * Multiple arguments allowed, but not less than one.
+	 * N values of all objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param args - arguments
+	 * @return - result of AND computation for this object and all arguments.
+	 */
+	public CertainTrust AND(CertainTrust ...args) {
+		CertainTrust result = clone();
+		for (CertainTrust m: args) {
+			if (n != m.getN())
+				throw new IllegalStateException("Different N values. Operation not allowed. \n");
+			result = result.AND(m);
+		}
+			
+		return result;
+	}
+	
+	/**
+	 * Returns NOT of this CertainTrust object.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @return - NOT of this CertainTrust object.
+	 */
+	public CertainTrust NOT(){
+		return new CertainTrust(getC(), adjustValue(1 - getT()), adjustValue(1 - getF()), n, 0);
+	}
+	
+	/**
+	 * an internal implementation of fusion function.
+	 * Is called by wFusion and cFusion
+	 * @param args - an array of CertainTrust objects
+	 * @param weights - an integer array of corresponding weights
+	 * @param doc - a degree of conflict (always 0 for wFusion)
+	 * @return - new CertainTrust object
+	 */
+	private static CertainTrust internalFusion(CertainTrust[] args, int[] weights, double doc) {
+		double resC, resT, resF;
+		boolean allOne = true;
+		boolean allZero = true;
+		boolean allWeightsZero = true;
+		boolean atLeastOne1 = false;
+		int arrLength = args.length;
+		
+		// set the flags about C and Weight values
+		for (int i = 0; i < arrLength; i++) 
+			if (args[i].getC() != 1) {
+				allOne = false;
+				i = arrLength;
+			}
+		for (int i = 0; i < arrLength; i++) 
+			if (args[i].getC() != 0) {
+				allZero = false;
+				i = arrLength;
+			}
+		for (int i = 0; i < arrLength; i++) 
+			if (weights[i] != 0) {
+				allWeightsZero = false;
+				i = arrLength;
+			}
+		for (int i = 0; i < arrLength; i++)
+			if (args[i].getC() == 1) {
+				atLeastOne1 = true;
+				i = arrLength;
+			}
+		
+		//Calculate T and C
+		
+		// 1. all C's  = 1
+		if (allOne) {
+			// set C
+			resC = 1 * (1 - doc);
+			// set T
+			if (allWeightsZero) {// save some calculation time 
+				resT = 0;
+			}
+			else {				// or use the function
+				double numeratorT = 0, denominatorT = 0;
+				for (int i = 0; i < arrLength; i++) {
+					numeratorT += weights[i] * args[i].getT();
+					denominatorT += weights[i];
+				}
+				resT = numeratorT/denominatorT;
+			}
+		}
+		
+		else {
+			if (atLeastOne1)
+				throw new IllegalStateException("Illeagal arguments. Either all C values must equal 1 or none of them. Operation not allowed \n");
+
+			// 2. Any other combination
+			if (allWeightsZero) { // save some calculation time
+				resT = 0;
+				resC = 0;
+			}
+			else {					// or use the function
+				double numeratorT = 0, denominatorT = 0, numeratorC = 0, denominatorC = 0, mult;
+				for (int i = 0; i < arrLength; i++) {
+					mult = 1;
+					for (int j = 0; j < arrLength; j++) // Count the product for each sum element
+						if (j != i) 
+							mult *= 1 - args[j].getC();	
+					numeratorT += weights[i] * args[i].getT() * args[i].getC() * mult;
+					denominatorT += weights[i] * args[i].getC() * mult;
+					denominatorC += weights[i] * mult;
+				}
+				numeratorC = denominatorT;
+				resC = (numeratorC/denominatorC) * (1 - doc);
+				if (allZero)
+					resT = 0.5;
+				else 		
+					resT = numeratorT/denominatorT;
+			}
+			
+			// Special case for T
+			if (allZero)
+				resT = 0.5;
+		}
+		
+		// Calculate F
+		if (allWeightsZero)
+			resF = 0;
+		else {
+			double numerator = 0, denominator = 0;
+			for (int i = 0; i < arrLength; i ++) {
+				numerator += weights[i] * args[i].getF();
+				denominator += weights[i];
+			}
+			resF = numerator/denominator;
+		}
+		return new CertainTrust(resT, resC, resF, args[0].getN(), doc);
+	}
+	
+	/**
+	 * Performs weighted fusion for an array of CertainTrust objects in correspondence with 
+	 * an array of weights. Returns new CertainTrust object.
+	 * Requirements: N values of CertainTrust objects must be equal.
+	 * Number of weights should equal the number of CertainTrust objects.
+	 * Arrays must be non-empty
+	 * Either all of CertainTrust must be of certainty 1 or none of them.
+	 * @param args - an array of CertainTrust objects
+	 * @param weights - an integer array of corresponding weights
+	 * @return - new CertainTrust object
+	 */
+	public static CertainTrust wFusion(CertainTrust[] args, int[] weights) {
+		//arrays should be equal
+		if (args.length == weights.length) {
+			//and not empty
+			if (args.length != 0) {
+				boolean equalNs = true;
+				int N = args[0].getN();
+				for (int i = 1; i < args.length; i++)
+					if (N != args[i].getN()) {
+						equalNs = false;
+						i = args.length;
+					}
+				//and all N's of TC's must be equal
+				if (equalNs) {
+					return internalFusion(args, weights, 0);
+				}
+				throw new IllegalStateException("Different N values. Operation not allowed. \n");
+			}
+			throw new IllegalStateException("Arrays are empty. Operation not allowed. \n");
+		}
+		throw new IllegalStateException("Different lengths of arrays. Operation not allowed. \n");
+	}
+	
+	/**
+	 * Conflicted Fusion is a variation of weighted fusion, which additionally computes the degree of conflict 
+	 * between given opinions (CertainTrust objects) and takes it into consideration while performing fusion.
+	 * The degree of conflict is then saved in the resulting CertainTrust object and may be checked with getDoC() function.
+	 * @param args - an array of CertainTrust objects
+	 * @param weights - an integer array of corresponding weights
+	 * @return - new CertainTrust object
+	 */
+	public static CertainTrust cFusion(CertainTrust[] args, int[] weights) {
+		//arrays should be equal
+		if (args.length == weights.length) {
+			//and not empty
+			if (args.length != 0) {
+				boolean equalNs = true;
+				int N = args[0].getN();
+				for (int i = 1; i < args.length; i++)
+					if (N != args[i].getN()) {
+						equalNs = false;
+						i = args.length;
+					}
+				//and all N's of TC's must be equal
+				if (equalNs) {
+					double denominator = args.length*(args.length - 1) / 2;
+					double numerator = 0;
+					for (int i = 0; i < args.length; i++) 
+						for (int j = i; j < args.length; j++)
+							numerator += Math.abs(args[i].getT() - args[j].getT()) * args[i].getC() * args[j].getC()*(1 - Math.abs((double)(weights[i] - weights[j])/(weights[i] + weights[j])));	
+					double doc = numerator/denominator;	
+					return internalFusion(args, weights, doc);
+				}
+				throw new IllegalStateException("Different N values. Operation not allowed. \n");
+			}
+			throw new IllegalStateException("Arrays are empty. Operation not allowed. \n");
+		}
+		throw new IllegalStateException("Different lengths of arrays. Operation not allowed. \n");
+	}
+	
+	/**
+	 * Computes CONSENSUS function for this CertainTrust object and the specified argument. Result is returned as a new object,
+	 * argument and this CertainTrust object remain unchanged.
+	 * N values of both objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param arg - CertainTrust object
+	 * @return - result of CONSENSUS computation for this object and an argument.
+	 */
+	private CertainTrust CONSENSUS(CertainTrust arg){
+		double c1 = getC();
+		double f1 = getF();
+		double t1 = getT();
+		
+		double c2 = arg.getC();
+		double f2 = arg.getF();
+		double t2 = arg.getT();
+		
+		double resC = 0, resT = 0.5, resF = 0.5;
+		
+		if (n != arg.getN()) 
+			throw new IllegalStateException("Different N values. Operation not allowed. \n");
+		
+		//resF = f1*f2;
+		
+		if (almostEqual(resF, 1))		//avoid division by 0
+			resC = (c1+c2-2*c1*c2)/(1-c1*c2);
+		else
+			resC = (c1+c2-2*c1*c2)/(1-c1*c2);
+		
+		if (almostEqual(resC, 0)) 
+			resT = 0.5;
+		else if (almostEqual(resF, 1))	//avoid division by 0
+			resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1*(1-c2)+c2*(1-c1));
+		else resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1*(1-c2)+c2*(1-c1));
+		
+		resT = adjustValue(resT);
+		resC = adjustValue(resC);
+		resF = adjustValue(resF);
+		
+		CertainTrust result = new CertainTrust(resT, resC, resF, n, 0);
+			
+		return result;
+	}
+	
+	/**
+	 * Computes CONSENSUS function for this CertainTrust object and the specified arguments. 
+	 * Result is returned as a new object, arguments and this CertainTrust object remain unchanged.
+	 * Example: a.CONSENSUS(b, c, d) returns new CertainTrust object that equals a CONSENSUS b CONSENSUS c CONSENSUS d.
+	 * Multiple arguments allowed, but not less than one.
+	 * N values of all objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param args - arguments
+	 * @return - result of CONSENSUS computation for this object and all arguments.
+	 */
+	public CertainTrust CONSENSUS(CertainTrust ...args) {
+		CertainTrust result = clone();
+		for (CertainTrust m: args) {
+			if (n != m.getN())
+				throw new IllegalStateException("Different N values. Operation not allowed. \n");
+			result = result.CONSENSUS(m);
+		}
+			
+		return result;
+	}
+
+	/**
+	 * Computes DISCOUNTING function for this CertainTrust object and the specified argument. Result is returned as a new object,
+	 * argument and this CertainTrust object remain unchanged.
+	 * N values of both objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param arg - CertainTrust object
+	 * @return - result of DISCOUNTING computation for this object and an argument.
+	 */
+	private CertainTrust DISCOUNTING(CertainTrust arg){
+		double c1 = getC();
+		double f1 = getF();
+		double t1 = getT();
+		
+		double c2 = arg.getC();
+		double f2 = arg.getF();
+		double t2 = arg.getT();
+		
+		double resC = 0, resT = 0.5, resF = 0.5;
+		
+		if (n != arg.getN()) 
+			throw new IllegalStateException("Different N values. Operation not allowed. \n");
+		
+		//resF = f1*f2;
+		
+		if (almostEqual(resF, 1))	
+			resC = t1*c1*c2;
+		else
+			resC = t1*c1*c2;
+		
+		if (almostEqual(resC, 0)) 
+			resT = 0.5;
+		else if (almostEqual(resF, 1))	
+			resT = t2;
+		else resT = t2;
+		
+		resT = adjustValue(resT);
+		resC = adjustValue(resC);
+		resF = adjustValue(resF);
+		
+		CertainTrust result = new CertainTrust(resT, resC, resF, n, 0);
+			
+		return result;
+	}
+	
+	/**
+	 * Computes DISCOUNTING function for this CertainTrust object and the specified arguments. 
+	 * Result is returned as a new object, arguments and this CertainTrust object remain unchanged.
+	 * Example: a.DISCOUNTING(b, c, d) returns new CertainTrust object that equals a DISCOUNTING b DISCOUNTING c DISCOUNTING d.
+	 * Multiple arguments allowed, but not less than one.
+	 * N values of all objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param args - arguments
+	 * @return - result of DISCOUNTING computation for this object and all arguments.
+	 */
+	public CertainTrust DISCOUNTING(CertainTrust ...args) {
+		CertainTrust result = clone();
+		for (CertainTrust m: args) {
+			if (n != m.getN())
+				throw new IllegalStateException("Different N values. Operation not allowed. \n");
+			result = result.DISCOUNTING(m);
+		}
+			
+		return result;
+	}
+	
+	
+//=========== Additional Functions =================	
+	
+	@Override
+	public CertainTrust clone() {
+		CertainTrust copy = new CertainTrust(n);
+		copy.c = this.c;
+		copy.t = this.t;
+		copy.f = this.f;
+		copy.r = this.r;
+		copy.s = this.s;
+		copy.doc = this.doc;
+		return copy;
+	}
+	
+	/**
+	 * Adjusts the value of a into the allowed range [0,1]. 
+	 * @param a - value to be adjusted
+	 */
+	private double adjustValue(double a) {
+		return Math.max(Math.min(a, 1), 0);
+	}
+	
+	/**
+	 * compares two double values using an epsilon
+	 * @param value - given value
+	 * @param target - expected value
+	 * @return
+	 */
+	private boolean almostEqual(double value, double target) {
+		return Math.abs(value - target) < 1E-10;
+	}
+
+}
+
+
+
+

+ 177 - 0
Java/Java_SDK/src/CertainTrust/CertainTrustCanvas.java

@@ -0,0 +1,177 @@
+/**
+ * CertainTrust SDK
+ * 
+ * Implements the computational trust model "CertainTrust"
+ * in Java.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ * 
+ * 
+ * Telecooperation Department, Technische Universit�t Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ * 
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ * 
+ * 
+ * @author	David Kalnischkies
+ * @version	1.0
+ */
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+package CertainTrust;
+import java.awt.Canvas;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Observable;
+import java.util.Observer;
+
+
+/**
+ * The canvas is a lovely image trying to visualize
+ * certainty and trust in an easy understandable way.
+ *
+ * @author David Kalnischkies <kalnischkies@gmail.com>
+ */
+public class CertainTrustCanvas extends Canvas implements Observer {
+	private static final long serialVersionUID = -8020598465155085223L;
+
+	private static final int CROSSHAIRLENGTH = 5;
+	private CertainTrust cl;
+	private Map<String,String> config;
+
+	private Image buffer;
+	private double old_f = -1;
+
+	/**
+	 * Constructs a new Canvas to display the certainlogic element
+	 * @param certainlogic element to display
+	 */
+	public CertainTrustCanvas(CertainTrust certainlogic) {
+		setup(certainlogic, null);
+	}
+	/**
+	 * Constructs a new Canvas to display the certainlogic element
+	 * 
+	 * Supported config options are:
+	 * - readonly.mouse: disables all mouse actions if set to "true"
+	 * - canvas.height and canvas.width to define the dimensions
+	 * 
+	 * @param certainlogic element to display
+	 * @param config to use for this HTI
+	 */
+	public CertainTrustCanvas(CertainTrust certainlogic, Map<String,String> config) {
+		setup(certainlogic, config);
+	}
+	
+	private void setup(CertainTrust certainlogic, Map<String,String> config) {
+		if (config != null)
+			this.config = config;
+		else
+			this.config = new HashMap<String,String>();
+		
+		// set the requested dimensions
+		if (this.config.containsKey("canvas.width") == false)
+			this.config.put("canvas.width", "120");
+		if (this.config.containsKey("canvas.height") == false)
+			this.config.put("canvas.height", "100");
+		final int canvasWidth = Integer.parseInt(this.config.get("canvas.width")); 
+		final int canvasHeight = Integer.parseInt(this.config.get("canvas.height"));
+		setPreferredSize(new Dimension(canvasWidth, canvasHeight));
+		
+		cl = certainlogic;
+		cl.addObserver(this);
+
+		// register for mouse events if required
+		if (this.config.containsKey("readonly") == false) {
+			if (this.config.containsKey("readonly.mouse") == false)
+				this.config.put("readonly.mouse", "false");
+		} else {
+			String readOnly = this.config.get("readonly");
+			if (this.config.containsKey("readonly.mouse") == false)
+				this.config.put("readonly.mouse", readOnly);
+		}
+		if (this.config.get("readonly.mouse").compareToIgnoreCase("false") == 0) {
+			addMouseListener(new MouseAdapter () {
+			      @Override
+				public void mousePressed(MouseEvent e) {
+				  setTCByMouseEvent(e, canvasWidth, canvasHeight);
+			    }});
+	
+			 addMouseMotionListener(new MouseMotionAdapter () {
+			      @Override
+				public void mouseDragged(MouseEvent e) {
+				  setTCByMouseEvent(e, canvasWidth, canvasHeight);
+			     }});
+		} else if (this.config.get("readonly.mouse").compareToIgnoreCase("true") != 0)
+			throw new IllegalArgumentException("Mouse has no valid readonly setting");
+
+		// call paint() indirectly the first time
+		update(null, null);
+	}
+	
+	private void setTCByMouseEvent(MouseEvent e, int canvasWidth, int canvasHeight) {
+		// mouse position to x and y coordinate 
+		double pointer_x = Math.max(Math.min(canvasWidth, e.getX()), 0);
+		double pointer_y = Math.max(Math.min(canvasHeight, canvasHeight - e.getY()), 0);
+		// ensure that the value is in the interval [0;1]
+		double t = Math.max(Math.min(pointer_x / canvasWidth, 1.0), 0.0);
+		double c = Math.max(Math.min(pointer_y / canvasHeight, 1.0), 0.0);
+		cl.setTC(t, c);
+	}
+
+	@Override
+	public void update(Observable ignored1, Object ignored2) {
+		repaint();
+	}
+
+	@Override
+	public void paint(Graphics g) {
+		final int canvasWidth = Integer.parseInt(this.config.get("canvas.width")); 
+		final int canvasHeight = Integer.parseInt(this.config.get("canvas.height"));
+		if (null == buffer) {
+			buffer = createImage(canvasWidth, canvasHeight);
+		}
+
+		// do we need to update the colorgradient?
+		double initf = cl.getF();
+		if (old_f != initf) {
+			Graphics bg = buffer.getGraphics();
+			for (int y = 0; y < canvasHeight; ++y){
+				double certainty = 1 - ((double)y / canvasHeight);
+				double resultp2 = ((1 - certainty) * initf);
+				for (int x = 0;x < canvasWidth; ++x){
+					double trust = (double)x / canvasWidth;
+					double result = (trust * certainty) + resultp2;
+
+					if (result < 0.5) {
+						bg.setColor(new Color(255, (int) Math.min(255, (255 * 2 * result)), 0));
+					} else {
+						bg.setColor(new Color((int) Math.min(255, (2 - (2 * result)) * 255), 255, 0));
+					}
+
+					bg.drawLine(x, y, x, y);
+				}
+			}
+			old_f = initf;
+		}
+		g.drawImage(buffer, 0, 0, this);
+
+		// draw the crosshair
+		g.setColor(Color.BLACK);
+		int pointer_x = (int) Math.round(cl.getT() * canvasWidth);
+		int pointer_y = (int) Math.round((1 - cl.getC()) * canvasHeight);
+		g.drawLine(pointer_x - CROSSHAIRLENGTH, pointer_y, pointer_x + CROSSHAIRLENGTH, pointer_y);
+		g.drawLine(pointer_x, pointer_y - CROSSHAIRLENGTH, pointer_x, pointer_y + CROSSHAIRLENGTH);
+	}
+}

+ 289 - 0
Java/Java_SDK/src/CertainTrust/CertainTrustHTI.java

@@ -0,0 +1,289 @@
+/**
+ * CertainTrust SDK
+ * 
+ * Implements the computational trust model "CertainTrust"
+ * in Java.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ * 
+ * 
+ * Telecooperation Department, Technische Universität Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ * 
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ * 
+ * 
+ * @author	David Kalnischkies
+ * @author	Florian Volk
+ * @version	1.0
+ */
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+package CertainTrust;
+import java.awt.BorderLayout;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Observable;
+import java.util.Observer;
+
+import javax.swing.BoxLayout;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.EmptyBorder;
+
+/**
+ * The CertainTrustHTI includes a formular to change
+ * the C, T and F values of the given CertainTrust
+ * element and a canvas displaying the expectation
+ * calculated from these values
+ */
+public class CertainTrustHTI extends JPanel implements Observer {
+	private static final long serialVersionUID = -1194437596328826222L;
+
+	/**
+	 * Creates a new HTI to display a CertainTrust element
+	 * 
+	 * @param certainlogic element to display
+	 */
+	public CertainTrustHTI(CertainTrust certainlogic) {
+		setup(certainlogic, null);
+	}
+	
+	/**
+	 * Creates a new HTI to display a CertainTrust element
+	 * 
+	 * Supported config options are:
+	 * - label.lang: language for the text elements (available: "de" and "en" (default))
+	 * - label.f, label.c, label.t and label.e to set the text explicitly
+	 * - readonly: to effect the complete HTI (value either "true" or "false") and
+	 * - readonly.f, readonly.c, readonly.t, readonly.e to set explicitly
+	 * See also {@link CertainTrustCanvas#CertainTrustCanvas(CertainTrust, Map)} for
+	 * additional options which are accepted by the canvas element
+	 * 
+	 * @param certainlogic element to display
+	 * @param config to use for this HTI
+	 */
+	public CertainTrustHTI(CertainTrust certainlogic, Map<String, String> config) {
+		setup(certainlogic, config);
+	}
+	
+	private CertainTrust cl;
+	private JTextField f;
+	private JTextField c;
+	private JTextField t;
+	private JTextField e;
+	private CertainTrustCanvas ctc;
+	private Map<String,String> config;
+	
+	protected CertainTrustCanvas getCanvas() { return ctc; }
+	
+	private static JTextField appendInput(JPanel p, String name, char mnemonic, double value, String readOnly, CertainTrustActionFocusListener listener) {
+		JLabel l = new JLabel(name);
+		l.setBorder(new EmptyBorder(0, 0, 0, (int) (l.getFont().getSize() * 1.5)));
+		final JTextField f = new JTextField(CertainTrustHTI.formatFloat(value), 4);
+		if (readOnly.compareToIgnoreCase("true") == 0) {
+			f.setEditable(false);
+			f.setFocusable(false);
+		}
+		else if (readOnly.compareToIgnoreCase("false") != 0)
+			throw new IllegalArgumentException("Input element " + name + " has no valid readonly setting");
+		else if (listener != null) {
+			f.addActionListener(listener);
+			f.addFocusListener(listener);
+		}
+		l.setLabelFor(f);
+		if (mnemonic != '\0')
+			l.setDisplayedMnemonic(mnemonic);
+		p.add(l);
+		p.add(f);
+		return f;
+	}
+	
+	private abstract class CertainTrustActionFocusListener implements ActionListener, FocusListener {
+		@Override
+		public void focusGained(FocusEvent arg0) {}
+
+		@Override
+		public void focusLost(FocusEvent arg0) {
+			update();
+		}
+
+		@Override
+		public void actionPerformed(ActionEvent arg0) {
+			update();
+		}
+		
+		abstract void update();
+		
+		/**
+		 * parseInput tries to convert a textual input into a floating point number in [0;1]
+		 * It accepts both "." and "," as decimal delimiters.
+		 * If the conversion fails, a default value is used.
+		 * @param input	the textual input to convert into a floating point number
+		 * @param defaultValue	the default value used in case the conversion fails
+		 * @return	the floating point value generated from the textual input
+		 */
+		protected double parseInput(String input, double defaultValue) {
+			double result;
+			try {
+				// first, replace the first "," with a "." to understand German-language style floating point notation
+				String rawInput = input.replaceFirst(",", ".");
+				
+				result = Double.parseDouble(rawInput);
+				
+				// check, if the value in within our bounds of [0;1]
+				if ((1 < result) || (0 > result)) {
+					result = defaultValue;
+				}
+			}
+			catch (NumberFormatException e) {
+				result = defaultValue;
+			}
+			return result;
+		}
+	}
+	
+	private void setup(CertainTrust certainlogic, Map<String,String> config) {
+		cl = certainlogic;
+		if (config != null)
+			this.config = config;
+		else
+			this.config = new HashMap<String,String>();
+		
+		if (this.config.containsKey("label.lang") == false)
+			this.config.put("label.lang", "en");
+		if (this.config.get("label.lang") == "de") {
+			if (this.config.containsKey("label.f") == false)
+				this.config.put("label.f", "Initialwert");
+			if (this.config.containsKey("label.t") == false)
+				this.config.put("label.t", "Vertrauen");
+			if (this.config.containsKey("label.c") == false)
+				this.config.put("label.c", "Sicherheit");
+			if (this.config.containsKey("label.e") == false)
+				this.config.put("label.e", "Erwartung");
+		} else {
+			if (this.config.containsKey("label.f") == false)
+				this.config.put("label.f", "Init. value");
+			if (this.config.containsKey("label.t") == false)
+				this.config.put("label.t", "Trust");
+			if (this.config.containsKey("label.c") == false)
+				this.config.put("label.c", "Certainty");
+			if (this.config.containsKey("label.e") == false)
+				this.config.put("label.e", "Expectation");
+		}
+		
+		if (this.config.containsKey("readonly") == false) {
+			if (this.config.containsKey("readonly.f") == false)
+				this.config.put("readonly.f", "false");
+			if (this.config.containsKey("readonly.t") == false)
+				this.config.put("readonly.t", "false");
+			if (this.config.containsKey("readonly.c") == false)
+				this.config.put("readonly.c", "false");
+			if (this.config.containsKey("readonly.e") == false)
+				this.config.put("readonly.e", "true");
+		} else {
+			String readOnly = this.config.get("readonly");
+			if (this.config.containsKey("readonly.f") == false)
+				this.config.put("readonly.f", readOnly);
+			if (this.config.containsKey("readonly.t") == false)
+				this.config.put("readonly.t", readOnly);
+			if (this.config.containsKey("readonly.c") == false)
+				this.config.put("readonly.c", readOnly);
+			if (this.config.containsKey("readonly.e") == false)
+				this.config.put("readonly.e", readOnly);
+		}
+		
+		JPanel inputs = new JPanel(new GridLayout(5,2));
+		f = appendInput(inputs, this.config.get("label.f"), 'f', cl.getF(), this.config.get("readonly.f"),
+				new CertainTrustActionFocusListener() {
+					@Override
+					void update() {
+						cl.setF(this.parseInput(f.getText(), cl.getF()));
+					}
+				});
+		t = appendInput(inputs, this.config.get("label.t"), 't', cl.getT(), this.config.get("readonly.t"),
+				new CertainTrustActionFocusListener() {
+			@Override
+			void update() {
+				cl.setTC(this.parseInput(t.getText(), cl.getT()),
+						cl.getC());
+			}
+		});
+		c = appendInput(inputs, this.config.get("label.c"), 'c', cl.getC(), this.config.get("readonly.c"),
+				new CertainTrustActionFocusListener() {
+			@Override
+			void update() {
+				cl.setTC(cl.getT(),
+						this.parseInput(c.getText(), cl.getC()));
+			}
+		});
+		JLabel ignore0 = new JLabel("");
+		inputs.add(ignore0);
+		JLabel ignore1 = new JLabel("");
+		inputs.add(ignore1);
+		e = appendInput(inputs, this.config.get("label.e"),'\0', cl.getExpectation(), this.config.get("readonly.e"), null);
+		this.add(inputs);
+		
+		JPanel jp = new JPanel();
+		jp.setLayout(new BoxLayout(jp, BoxLayout.PAGE_AXIS));
+		JPanel jp1 = new JPanel();
+		JLabel certain = new JLabel(this.config.get("label.c") + "\u00a0\u2192");
+		certain.setUI(new VerticalLabelUI());
+		jp1.add(certain);
+		ctc = new CertainTrustCanvas(cl, this.config);
+		ctc.repaint();
+		jp1.add(ctc);
+		JPanel jp2 = new JPanel(new BorderLayout());
+		JLabel origin = new JLabel("0");
+		int fontsize = certain.getFont().getSize();
+		origin.setBorder(new EmptyBorder(0, fontsize, 0, fontsize));
+		jp2.add(origin, BorderLayout.LINE_START);
+		JLabel trust = new JLabel(this.config.get("label.t") + "\u00a0\u2192");
+		jp2.add(trust, BorderLayout.CENTER);
+		jp.add(jp1);
+		jp.add(jp2);
+		
+		this.add(jp);
+		this.setVisible(true);
+		cl.addObserver(this);
+	}
+
+	@Override
+	public void update(Observable ignored0, Object ignored1) {
+		f.setText(CertainTrustHTI.formatFloat(cl.getF()));
+		t.setText(CertainTrustHTI.formatFloat(cl.getT()));
+		c.setText(CertainTrustHTI.formatFloat(cl.getC()));
+		e.setText(CertainTrustHTI.formatFloat(cl.getExpectation()));
+	}
+	
+	/**
+	 * Rounds a number to at most 3 decimal places and converts it to a string
+	 * @param value	the number to round
+	 * @return	the rounded value as string
+	 */
+	static private String formatFloat(double value) {
+		// the explicit type cast from Long to double is required, otherwise rounded will always be 0
+		double rounded = ((double)Math.round(value * 1000) / 1000);
+		
+		// Use NumerFormat to omit trailing 0s as those which Double.toString() produces
+		NumberFormat formatter = new DecimalFormat("0.###");
+		String result = formatter.format(rounded);
+		
+		// for compatibility with the JS version, our decimal delimiter *always* is "."
+		result = result.replaceFirst(",", ".");
+		
+		return result;
+	}
+}

+ 650 - 0
Java/Java_SDK/src/CertainTrust/CertainTrustSimple.java

@@ -0,0 +1,650 @@
+/**
+ * CertainTrust SDK
+ * 
+ * Implements the computational trust model "CertainTrust"
+ * in Java.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ * 
+ * 
+ * Telecooperation Department, Technische Universit�t Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ * 
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ * 
+ * 
+ * @author	Maria Pelevina
+ * @author	David Kalnischkies
+ * @version	1.1
+ */
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+package CertainTrust;
+import java.util.Observable;
+
+/**
+ * 
+ * t - average rating value, [0; 1], from very negative to very positive
+ * c - certainty value, [0; 1] from low certainty (no evidence) to the maximal maximal certainty.
+ * f - initial trust value
+ * w - weight
+ * r - number of positive evidence
+ * s - number of negative evidence
+ * n - maximal number of expected evidence
+ * doc - degree of conflict
+ * 
+ */
+public class CertainTrustSimple extends Observable {
+	
+	private double c, t, f, r, s, doc;
+	private int n = 1, weight = 2;
+
+//=========== Constructors =================
+	/**
+	 * Constructs a CertainTrustSimple object with predefined n value.
+	 * @param n - maximal number of expected evidence
+	 */
+	public CertainTrustSimple(int n) {
+		if (n > 0) {
+			this.n = n;
+			c = 0;
+			t = 0.5;
+			f = 0.5;
+			r = 0;
+			s = 0;
+		}
+		else throw new IllegalArgumentException("N should be greater than 0. Entered n = " + n + "\n");
+	}
+	
+		
+	/**
+	 * Constructs a CertainTrustSimple object with predefined c, t, f, n values. 
+	 * @param c - certainty
+	 * @param t - average rating
+	 * @param f - initial trust value	 
+	 */
+	public CertainTrustSimple(double t, double c, double f) {
+		this.f = f;
+		setTC(t, c);
+	}
+	
+	/**
+	 * Constructs a CertainTrustSimple object with predefined c, t, f, n values. 
+	 * @param c - certainty
+	 * @param t - average rating
+	 * @param f - initial trust value
+	 * @param n - maximal number of expected evidence
+	 * @param doc - initial degree of conflict
+	 */
+	private CertainTrustSimple(double t, double c, double f, double doc) {
+		if (n > 0) {
+			if (f <= 1 && f >= 0) {
+				this.f = f;
+				this.doc = doc;
+				setTC(t, c);
+			}
+			else throw new IllegalArgumentException("f should lie within [0;1]. Entered f = " + f + "\n");
+		}
+		else throw new IllegalArgumentException("N should be greater than 0. Entered n = " + n + "\n");
+	}
+	
+	//=========== Setters =================
+	
+	
+	/**
+	 * Sets f value.
+	 * @param f - initial trust value.
+	 */
+	public void setF(double f) {
+		if (f >= 0 && f <= 1) {
+			this.f = f;
+			
+			setChanged();
+			notifyObservers();
+		}
+		
+		else throw new IllegalArgumentException("f should lie within [0;1]. Entered f = " + f + "\n");
+	}
+
+	/**
+	  * Sets Distance of Conflict value.
+	  * @param doc is the new value for DoC
+	  */
+	public void setDoC(double doc) {
+		if (doc > 0) {
+			this.doc = doc;
+		}
+		else throw new IllegalArgumentException("DoC should be greater than 0. Entered DoC = " + doc + "\n");
+	}
+	
+	/**
+	 * Sets c and t values. Recalculates r and s values accordingly.
+	 * @param t - new average trust value
+	 * @param c - new certainty value
+	 */
+	public void setTC(double t, double c) {
+		if (c >= 0 && c <= 1) {
+			if (t >= 0 && t <= 1) {
+				this.c = c;
+				this.t = t;
+				
+				setChanged();
+				notifyObservers();
+			}
+			else throw new IllegalArgumentException("t should be greater than 0. Entered t = " + t + "\n");
+		}
+		else throw new IllegalArgumentException("c should lie within [0;1]. Entered c = " + c + "\n");
+	}
+	
+	
+//=========== Internal Calculations ==========
+//=========== Getters =================
+	public double getC() {
+		return c;
+	}
+
+	public double getT() {
+		return t;
+	}
+
+	public double getF() {
+		return f;
+	}
+
+	
+	public double getDoC() {
+		return doc;
+	}
+	
+	public double getExpectation() {
+		return t*c + (1-c)*f;
+	}
+	
+//=========== Logic =================
+	/**
+	 * Computes OR function for this CertainTrustSimple object and the specified argument. Result is returned as a new object,
+	 * argument and this CertainTrust object remain unchanged.
+	 * N values of both objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param arg - CertainTrust object
+	 * @return - result of OR computation for this object and an argument.
+	 */
+	
+	private CertainTrustSimple OR(CertainTrustSimple arg){
+		double c1 = getC();
+		double t1 = getT();
+		double f1 = getF();
+		
+		double c2 = arg.getC();
+		double t2 = arg.getT();
+		double f2 = arg.getF();
+		
+		double resT = 0.5, resF = 0.5, resC = 0;
+		
+//		if (this.getN() != arg.getN()) 
+//			throw new IllegalStateException("Different N values. Operation not allowed. \n");
+				
+		resF = f1 + f2 - f1*f2;
+		if (almostEqual(resF, 0))
+			resC = c1 + c2 - c1*c2;
+		else 
+			resC = c1 + c2 - c1*c2 - (c1*f2*(1-c2)*(1-t1)+c2*f1*(1-c1)*(1-t2)) / resF;
+		
+		if (almostEqual(resC, 0)) 
+			resT = 0.5;	
+		else resT = (1/resC) * (c1*t1 + c2*t2 - c1*c2*t1*t2);
+		
+		resT = adjustValue(resT);
+		resC = adjustValue(resC);
+		resF = adjustValue(resF);
+		
+		CertainTrustSimple result = new CertainTrustSimple(resT, resC, resF,0); 
+			
+		return result;	
+	}
+	/**
+	 * Computes OR function for this CertainTrustSimple object and the specified arguments. 
+	 * Result is returned as a new object, arguments and this CertainTrust object remain unchanged.
+	 * Example: a.OR(b, c, d) returns new CertainTrust object that equals a OR b OR c OR d.
+	 * Multiple arguments allowed, but not less than one.
+	 * N values of all objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param args - arguments
+	 * @return - result of OR computation for this object and all arguments.
+	 */
+	public CertainTrustSimple OR(CertainTrustSimple ...args) {
+		CertainTrustSimple result = clone();
+		for (CertainTrustSimple m: args) {
+//			if (n != m.getN())
+//				throw new IllegalStateException("Different N values. Operation not allowed. \n");
+			result = result.OR(m);
+		}
+			
+		return result;
+	}
+	
+	/**
+	 * Computes AND function for this CertainTrustSimple object and the specified argument. Result is returned as a new object,
+	 * argument and this CertainTrust object remain unchanged.
+	 * N values of both objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param arg - CertainTrust object
+	 * @return - result of AND computation for this object and an argument.
+	 */
+	private CertainTrustSimple AND(CertainTrustSimple arg){
+		double c1 = getC();
+		double f1 = getF();
+		double t1 = getT();
+		
+		double c2 = arg.getC();
+		double f2 = arg.getF();
+		double t2 = arg.getT();
+		
+		double resC = 0, resT = 0.5, resF = 0.5;
+		
+//		if (n != arg.getN()) 
+//			throw new IllegalStateException("Different N values. Operation not allowed. \n");
+		
+		resF = f1*f2;
+		
+		if (almostEqual(resF, 1))		//avoid division by 0
+			resC = c1 + c2 - c1*c2;
+		else
+			resC = c1 + c2 - c1*c2 - (c2*t2*(1-c1)*(1-f1)+c1*t1*(1-c2)*(1-f2)) / (1 - resF);
+		
+		if (almostEqual(resC, 0)) 
+			resT = 0.5;
+		else if (almostEqual(resF, 1))	//avoid division by 0
+			resT = (1/resC) *  (c1*t1*c2*t2);
+		else resT = (1/resC) *  ((c1*t1*c2*t2) + (c1*f2*t1*(1-c2)*(1-f1)+c2*f1*t2*(1-c1)*(1-f2)) / (1 - resF));
+		
+		resT = adjustValue(resT);
+		resC = adjustValue(resC);
+		resF = adjustValue(resF);
+		
+		CertainTrustSimple result = new CertainTrustSimple(resT, resC, resF,0);
+			
+		return result;
+	}
+	
+	/**
+	 * Computes AND function for this CertainTrustSimple object and the specified arguments. 
+	 * Result is returned as a new object, arguments and this CertainTrust object remain unchanged.
+	 * Example: a.AND(b, c, d) returns new CertainTrust object that equals a AND b AND c AND d.
+	 * Multiple arguments allowed, but not less than one.
+	 * N values of all objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param args - arguments
+	 * @return - result of AND computation for this object and all arguments.
+	 */
+	public CertainTrustSimple AND(CertainTrustSimple ...args) {
+		CertainTrustSimple result = clone();
+		for (CertainTrustSimple m: args) {
+//			if (n != m.getN())
+//				throw new IllegalStateException("Different N values. Operation not allowed. \n");
+			result = result.AND(m);
+		}
+			
+		return result;
+	}
+	
+	/**
+	 * Returns NOT of this CertainTrustSimple object.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @return - NOT of this CertainTrustSimple object.
+	 */
+	public CertainTrustSimple NOT(){
+		return new CertainTrustSimple(getC(), adjustValue(1 - getT()), adjustValue(1 - getF()));
+	}
+	
+	/**
+	 * an internal implementation of fusion function.
+	 * Is called by wFusion and cFusion
+	 * @param args - an array of CertainTrustSimple objects
+	 * @param weights - an integer array of corresponding weights
+	 * @param doc - a degree of conflict (always 0 for wFusion)
+	 * @return - new CertainTrustSimple object
+	 */
+	private static CertainTrustSimple internalFusion(CertainTrustSimple[] args, int[] weights, double doc) {
+		double resC, resT, resF;
+		boolean allOne = true;
+		boolean allZero = true;
+		boolean allWeightsZero = true;
+		boolean atLeastOne1 = false;
+		int arrLength = args.length;
+		
+		// set the flags about C and Weight values
+		for (int i = 0; i < arrLength; i++) 
+			if (args[i].getC() != 1) {
+				allOne = false;
+				i = arrLength;
+			}
+		for (int i = 0; i < arrLength; i++) 
+			if (args[i].getC() != 0) {
+				allZero = false;
+				i = arrLength;
+			}
+		for (int i = 0; i < arrLength; i++) 
+			if (weights[i] != 0) {
+				allWeightsZero = false;
+				i = arrLength;
+			}
+		for (int i = 0; i < arrLength; i++)
+			if (args[i].getC() == 1) {
+				atLeastOne1 = true;
+				i = arrLength;
+			}
+		
+		//Calculate T and C
+		
+		// 1. all C's  = 1
+		if (allOne) {
+			// set C
+			resC = 1 * (1 - doc);
+			// set T
+			if (allWeightsZero) {// save some calculation time 
+				resT = 0;
+			}
+			else {				// or use the function
+				double numeratorT = 0, denominatorT = 0;
+				for (int i = 0; i < arrLength; i++) {
+					numeratorT += weights[i] * args[i].getT();
+					denominatorT += weights[i];
+				}
+				resT = numeratorT/denominatorT;
+			}
+		}
+		
+		else {
+			if (atLeastOne1)
+				throw new IllegalStateException("Illeagal arguments. Either all C values must equal 1 or none of them. Operation not allowed \n");
+
+			// 2. Any other combination
+			if (allWeightsZero) { // save some calculation time
+				resT = 0;
+				resC = 0;
+			}
+			else {					// or use the function
+				double numeratorT = 0, denominatorT = 0, numeratorC = 0, denominatorC = 0, mult;
+				for (int i = 0; i < arrLength; i++) {
+					mult = 1;
+					for (int j = 0; j < arrLength; j++) // Count the product for each sum element
+						if (j != i) 
+							mult *= 1 - args[j].getC();	
+					numeratorT += weights[i] * args[i].getT() * args[i].getC() * mult;
+					denominatorT += weights[i] * args[i].getC() * mult;
+					denominatorC += weights[i] * mult;
+				}
+				numeratorC = denominatorT;
+				resC = (numeratorC/denominatorC) * (1 - doc);
+				if (allZero)
+					resT = 0.5;
+				else 		
+					resT = numeratorT/denominatorT;
+			}
+			
+			// Special case for T
+			if (allZero)
+				resT = 0.5;
+		}
+		
+		// Calculate F
+		if (allWeightsZero)
+			resF = 0;
+		else {
+			double numerator = 0, denominator = 0;
+			for (int i = 0; i < arrLength; i ++) {
+				numerator += weights[i] * args[i].getF();
+				denominator += weights[i];
+			}
+			resF = numerator/denominator;
+		}
+		return new CertainTrustSimple(resT, resC, resF, doc);
+	}
+	
+	/**
+	 * Performs weighted fusion for an array of CertainTrustSimple objects in correspondence with 
+	 * an array of weights. Returns new CertainTrust object.
+	 * Requirements: N values of CertainTrust objects must be equal.
+	 * Number of weights should equal the number of CertainTrustSimple objects.
+	 * Arrays must be non-empty
+	 * Either all of CertainTrustSimple must be of certainty 1 or none of them.
+	 * @param args - an array of CertainTrustSimple objects
+	 * @param weights - an integer array of corresponding weights
+	 * @return - new CertainTrustSimple object
+	 */
+	public static CertainTrustSimple wFusion(CertainTrustSimple[] args, int[] weights) {
+		//arrays should be equal
+		if (args.length == weights.length) {
+			//and not empty
+			if (args.length != 0) {
+				boolean equalNs = true;
+//				int N = args[0].getN();
+				for (int i = 1; i < args.length; i++)
+//					if (N != args[i].getN()) {
+						equalNs = false;
+//						i = args.length;
+//					}
+				//and all N's of TC's must be equal
+				if (equalNs) {
+					return internalFusion(args, weights, 0);
+				}
+				throw new IllegalStateException("Different N values. Operation not allowed. \n");
+			}
+			throw new IllegalStateException("Arrays are empty. Operation not allowed. \n");
+		}
+		throw new IllegalStateException("Different lengths of arrays. Operation not allowed. \n");
+	}
+	
+	/**
+	 * Conflicted Fusion is a variation of weighted fusion, which additionally computes the degree of conflict 
+	 * between given opinions (CertainTrustSimple objects) and takes it into consideration while performing fusion.
+	 * The degree of conflict is then saved in the resulting CertainTrustSimple object and may be checked with getDoC() function.
+	 * @param args - an array of CertainTrustSimple objects
+	 * @param weights - an integer array of corresponding weights
+	 * @return - new CertainTrustSimple object
+	 */
+	public static CertainTrustSimple cFusion(CertainTrustSimple[] args, int[] weights) {
+		//arrays should be equal
+		if (args.length == weights.length) {
+			//and not empty
+			if (args.length != 0) {
+				boolean equalNs = true;
+//				int N = args[0].getN();
+//				for (int i = 1; i < args.length; i++)
+//					if (N != args[i].getN()) {
+						equalNs = false;
+//						i = args.length;
+//					}
+				//and all N's of TC's must be equal
+				if (equalNs) {
+					double denominator = args.length*(args.length - 1) / 2;
+					double numerator = 0;
+					for (int i = 0; i < args.length; i++) 
+						for (int j = i; j < args.length; j++)
+							numerator += Math.abs(args[i].getT() - args[j].getT()) * args[i].getC() * args[j].getC()*(1 - Math.abs((double)(weights[i] - weights[j])/(weights[i] + weights[j])));	
+					double doc = numerator/denominator;	
+					return internalFusion(args, weights, doc);
+				}
+				throw new IllegalStateException("Different N values. Operation not allowed. \n");
+			}
+			throw new IllegalStateException("Arrays are empty. Operation not allowed. \n");
+		}
+		throw new IllegalStateException("Different lengths of arrays. Operation not allowed. \n");
+	}
+	
+	/**
+	 * Computes CONSENSUS function for this CertainTrustSimple object and the specified argument. Result is returned as a new object,
+	 * argument and this CertainTrustSimple object remain unchanged.
+	 * N values of both objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param arg - CertainTrustSimple object
+	 * @return - result of CONSENSUS computation for this object and an argument.
+	 */
+	private CertainTrustSimple CONSENSUS(CertainTrustSimple arg){
+		double c1 = getC();
+		double f1 = getF();
+		double t1 = getT();
+		
+		double c2 = arg.getC();
+		double f2 = arg.getF();
+		double t2 = arg.getT();
+		
+		double resC = 0, resT = 0.5, resF = 0.5;
+		
+//		if (n != arg.getN()) 
+//			throw new IllegalStateException("Different N values. Operation not allowed. \n");
+		
+		//resF = f1*f2;
+		
+		if (almostEqual(resF, 1))		//avoid division by 0
+			resC = (c1+c2-2*c1*c2)/(1-c1*c2);
+		else
+			resC = (c1+c2-2*c1*c2)/(1-c1*c2);
+		
+		if (almostEqual(resC, 0)) 
+			resT = 0.5;
+		else if (almostEqual(resF, 1))	//avoid division by 0
+			resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1*(1-c2)+c2*(1-c1));
+		else resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1*(1-c2)+c2*(1-c1));
+		
+		resT = adjustValue(resT);
+		resC = adjustValue(resC);
+		resF = adjustValue(resF);
+		
+		CertainTrustSimple result = new CertainTrustSimple(resT, resC, resF, 0);
+			
+		return result;
+	}
+	
+	/**
+	 * Computes CONSENSUS function for this CertainTrustSimple object and the specified arguments. 
+	 * Result is returned as a new object, arguments and this CertainTrustSimple object remain unchanged.
+	 * Example: a.CONSENSUS(b, c, d) returns new CertainTrustSimple object that equals a CONSENSUS b CONSENSUS c CONSENSUS d.
+	 * Multiple arguments allowed, but not less than one.
+	 * N values of all objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param args - arguments
+	 * @return - result of CONSENSUS computation for this object and all arguments.
+	 */
+	public CertainTrustSimple CONSENSUS(CertainTrustSimple ...args) {
+		CertainTrustSimple result = clone();
+		for (CertainTrustSimple m: args) {
+//			if (n != m.getN())
+//				throw new IllegalStateException("Different N values. Operation not allowed. \n");
+			result = result.CONSENSUS(m);
+		}
+			
+		return result;
+	}
+
+	
+	
+	/**
+	 * Computes DISCOUNTING function for this CertainTrustSimple object and the specified argument. Result is returned as a new object,
+	 * argument and this CertainTrustSimple object remain unchanged.
+	 * N values of both objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param arg - CertainTrust object
+	 * @return - result of DISCOUNTING computation for this object and an argument.
+	 */
+	private CertainTrustSimple DISCOUNTING(CertainTrustSimple arg){
+		double c1 = getC();
+		double f1 = getF();
+		double t1 = getT();
+		
+		double c2 = arg.getC();
+		double f2 = arg.getF();
+		double t2 = arg.getT();
+		
+		double resC = 0, resT = 0.5, resF = 0.5;
+		
+//		if (n != arg.getN()) 
+//			throw new IllegalStateException("Different N values. Operation not allowed. \n");
+		
+		//resF = f1*f2;
+		
+		if (almostEqual(resF, 1))	
+			resC = t1*c1*c2;
+		else
+			resC = t1*c1*c2;
+		
+		if (almostEqual(resC, 0)) 
+			resT = 0.5;
+		else if (almostEqual(resF, 1))	
+			resT = t2;
+		else resT = t2;
+		
+		resT = adjustValue(resT);
+		resC = adjustValue(resC);
+		resF = adjustValue(resF);
+		
+		CertainTrustSimple result = new CertainTrustSimple(resT, resC, resF, 0);
+			
+		return result;
+	}
+	
+	/**
+	 * Computes DISCOUNTING function for this CertainTrust object and the specified arguments. 
+	 * Result is returned as a new object, arguments and this CertainTrust object remain unchanged.
+	 * Example: a.DISCOUNTING(b, c, d) returns new CertainTrust object that equals a DISCOUNTING b DISCOUNTING c DISCOUNTING d.
+	 * Multiple arguments allowed, but not less than one.
+	 * N values of all objects should be equal.
+	 * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+	 * @param args - arguments
+	 * @return - result of DISCOUNTING computation for this object and all arguments.
+	 */
+	public CertainTrustSimple DISCOUNTING(CertainTrustSimple ...args) {
+		CertainTrustSimple result = clone();
+		for (CertainTrustSimple m: args) {
+//			if (n != m.getN())
+//				throw new IllegalStateException("Different N values. Operation not allowed. \n");
+			result = result.DISCOUNTING(m);
+		}
+			
+		return result;
+	}
+	
+
+	
+	//=========== Additional Functions =================	
+	
+	@Override
+	public CertainTrustSimple clone() {
+		CertainTrustSimple copy = new CertainTrustSimple(n);
+		copy.c = this.c;
+		copy.t = this.t;
+		copy.f = this.f;
+		copy.r = this.r;
+		copy.s = this.s;
+		copy.doc = this.doc;
+		return copy;
+	}
+	
+	/**
+	 * Adjusts the value of a into the allowed range [0,1]. 
+	 * @param a - value to be adjusted
+	 */
+	private double adjustValue(double a) {
+		return Math.max(Math.min(a, 1), 0);
+	}
+	
+	/**
+	 * compares two double values using an epsilon
+	 * @param value - given value
+	 * @param target - expected value
+	 * @return
+	 */
+	private boolean almostEqual(double value, double target) {
+		return Math.abs(value - target) < 1E-10;
+	}
+
+}
+
+
+
+

+ 177 - 0
Java/Java_SDK/src/CertainTrust/CertainTrustSimpleCanvas.java

@@ -0,0 +1,177 @@
+/**
+ * CertainTrust SDK
+ * 
+ * Implements the computational trust model "CertainTrust"
+ * in Java.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ * 
+ * 
+ * Telecooperation Department, Technische Universit�t Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ * 
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ * 
+ * 
+ * @author	David Kalnischkies
+ * @version	1.0
+ */
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+package CertainTrust;
+import java.awt.Canvas;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Observable;
+import java.util.Observer;
+
+
+/**
+ * The canvas is a lovely image trying to visualize
+ * certainty and trust in an easy understandable way.
+ *
+ * @author David Kalnischkies <kalnischkies@gmail.com>
+ */
+public class CertainTrustSimpleCanvas extends Canvas implements Observer {
+	private static final long serialVersionUID = -8020598465155085223L;
+
+	private static final int CROSSHAIRLENGTH = 5;
+	private CertainTrustSimple cl;
+	private Map<String,String> config;
+
+	private Image buffer;
+	private double old_f = -1;
+
+	/**
+	 * Constructs a new Canvas to display the certainlogic element
+	 * @param certainlogic element to display
+	 */
+	public CertainTrustSimpleCanvas(CertainTrustSimple certainlogic) {
+		setup(certainlogic, null);
+	}
+	/**
+	 * Constructs a new Canvas to display the certainlogic element
+	 * 
+	 * Supported config options are:
+	 * - readonly.mouse: disables all mouse actions if set to "true"
+	 * - canvas.height and canvas.width to define the dimensions
+	 * 
+	 * @param certainlogic element to display
+	 * @param config to use for this HTI
+	 */
+	public CertainTrustSimpleCanvas(CertainTrustSimple certainlogic, Map<String,String> config) {
+		setup(certainlogic, config);
+	}
+	
+	private void setup(CertainTrustSimple certainlogic, Map<String,String> config) {
+		if (config != null)
+			this.config = config;
+		else
+			this.config = new HashMap<String,String>();
+		
+		// set the requested dimensions
+		if (this.config.containsKey("canvas.width") == false)
+			this.config.put("canvas.width", "120");
+		if (this.config.containsKey("canvas.height") == false)
+			this.config.put("canvas.height", "100");
+		final int canvasWidth = Integer.parseInt(this.config.get("canvas.width")); 
+		final int canvasHeight = Integer.parseInt(this.config.get("canvas.height"));
+		setPreferredSize(new Dimension(canvasWidth, canvasHeight));
+		
+		cl = certainlogic;
+		cl.addObserver(this);
+
+		// register for mouse events if required
+		if (this.config.containsKey("readonly") == false) {
+			if (this.config.containsKey("readonly.mouse") == false)
+				this.config.put("readonly.mouse", "false");
+		} else {
+			String readOnly = this.config.get("readonly");
+			if (this.config.containsKey("readonly.mouse") == false)
+				this.config.put("readonly.mouse", readOnly);
+		}
+		if (this.config.get("readonly.mouse").compareToIgnoreCase("false") == 0) {
+			addMouseListener(new MouseAdapter () {
+			      @Override
+				public void mousePressed(MouseEvent e) {
+				  setTCByMouseEvent(e, canvasWidth, canvasHeight);
+			    }});
+	
+			 addMouseMotionListener(new MouseMotionAdapter () {
+			      @Override
+				public void mouseDragged(MouseEvent e) {
+				  setTCByMouseEvent(e, canvasWidth, canvasHeight);
+			     }});
+		} else if (this.config.get("readonly.mouse").compareToIgnoreCase("true") != 0)
+			throw new IllegalArgumentException("Mouse has no valid readonly setting");
+
+		// call paint() indirectly the first time
+		update(null, null);
+	}
+	
+	private void setTCByMouseEvent(MouseEvent e, int canvasWidth, int canvasHeight) {
+		// mouse position to x and y coordinate 
+		double pointer_x = Math.max(Math.min(canvasWidth, e.getX()), 0);
+		double pointer_y = Math.max(Math.min(canvasHeight, canvasHeight - e.getY()), 0);
+		// ensure that the value is in the interval [0;1]
+		double t = Math.max(Math.min(pointer_x / canvasWidth, 1.0), 0.0);
+		double c = Math.max(Math.min(pointer_y / canvasHeight, 1.0), 0.0);
+		cl.setTC(t, c);
+	}
+
+	@Override
+	public void update(Observable ignored1, Object ignored2) {
+		repaint();
+	}
+
+	@Override
+	public void paint(Graphics g) {
+		final int canvasWidth = Integer.parseInt(this.config.get("canvas.width")); 
+		final int canvasHeight = Integer.parseInt(this.config.get("canvas.height"));
+		if (null == buffer) {
+			buffer = createImage(canvasWidth, canvasHeight);
+		}
+
+		// do we need to update the colorgradient?
+		double initf = cl.getF();
+		if (old_f != initf) {
+			Graphics bg = buffer.getGraphics();
+			for (int y = 0; y < canvasHeight; ++y){
+				double certainty = 1 - ((double)y / canvasHeight);
+				double resultp2 = ((1 - certainty) * initf);
+				for (int x = 0;x < canvasWidth; ++x){
+					double trust = (double)x / canvasWidth;
+					double result = (trust * certainty) + resultp2;
+
+					if (result < 0.5) {
+						bg.setColor(new Color(255, (int) Math.min(255, (255 * 2 * result)), 0));
+					} else {
+						bg.setColor(new Color((int) Math.min(255, (2 - (2 * result)) * 255), 255, 0));
+					}
+
+					bg.drawLine(x, y, x, y);
+				}
+			}
+			old_f = initf;
+		}
+		g.drawImage(buffer, 0, 0, this);
+
+		// draw the crosshair
+		g.setColor(Color.BLACK);
+		int pointer_x = (int) Math.round(cl.getT() * canvasWidth);
+		int pointer_y = (int) Math.round((1 - cl.getC()) * canvasHeight);
+		g.drawLine(pointer_x - CROSSHAIRLENGTH, pointer_y, pointer_x + CROSSHAIRLENGTH, pointer_y);
+		g.drawLine(pointer_x, pointer_y - CROSSHAIRLENGTH, pointer_x, pointer_y + CROSSHAIRLENGTH);
+	}
+}

+ 289 - 0
Java/Java_SDK/src/CertainTrust/CertainTrustSimpleHTI.java

@@ -0,0 +1,289 @@
+/**
+ * CertainTrust SDK
+ * 
+ * Implements the computational trust model "CertainTrust"
+ * in Java.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ * 
+ * 
+ * Telecooperation Department, Technische Universität Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ * 
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ * 
+ * 
+ * @author	David Kalnischkies
+ * @author	Florian Volk
+ * @version	1.0
+ */
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+package CertainTrust;
+import java.awt.BorderLayout;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Observable;
+import java.util.Observer;
+
+import javax.swing.BoxLayout;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.EmptyBorder;
+
+/**
+ * The CertainTrustHTI includes a formular to change
+ * the C, T and F values of the given CertainTrust
+ * element and a canvas displaying the expectation
+ * calculated from these values
+ */
+public class CertainTrustSimpleHTI extends JPanel implements Observer {
+	private static final long serialVersionUID = -1194437596328826222L;
+
+	/**
+	 * Creates a new HTI to display a CertainTrustSimple element
+	 * 
+	 * @param certainlogic element to display
+	 */
+	public CertainTrustSimpleHTI(CertainTrustSimple certainlogic) {
+		setup(certainlogic, null);
+	}
+	
+	/**
+	 * Creates a new HTI to display a CertainTrustSimple element
+	 * 
+	 * Supported config options are:
+	 * - label.lang: language for the text elements (available: "de" and "en" (default))
+	 * - label.f, label.c, label.t and label.e to set the text explicitly
+	 * - readonly: to effect the complete HTI (value either "true" or "false") and
+	 * - readonly.f, readonly.c, readonly.t, readonly.e to set explicitly
+	 * See also {@link CertainTrustCanvas#CertainTrustCanvas(CertainTrust, Map)} for
+	 * additional options which are accepted by the canvas element
+	 * 
+	 * @param certainlogic element to display
+	 * @param config to use for this HTI
+	 */
+	public CertainTrustSimpleHTI(CertainTrustSimple certainlogic, Map<String, String> config) {
+		setup(certainlogic, config);
+	}
+	
+	private CertainTrustSimple cl;
+	private JTextField f;
+	private JTextField c;
+	private JTextField t;
+	private JTextField e;
+	private CertainTrustSimpleCanvas ctc;
+	private Map<String,String> config;
+	
+	protected CertainTrustSimpleCanvas getCanvas() { return ctc; }
+	
+	private static JTextField appendInput(JPanel p, String name, char mnemonic, double value, String readOnly, CertainTrustActionFocusListener listener) {
+		JLabel l = new JLabel(name);
+		l.setBorder(new EmptyBorder(0, 0, 0, (int) (l.getFont().getSize() * 1.5)));
+		final JTextField f = new JTextField(CertainTrustSimpleHTI.formatFloat(value), 4);
+		if (readOnly.compareToIgnoreCase("true") == 0) {
+			f.setEditable(false);
+			f.setFocusable(false);
+		}
+		else if (readOnly.compareToIgnoreCase("false") != 0)
+			throw new IllegalArgumentException("Input element " + name + " has no valid readonly setting");
+		else if (listener != null) {
+			f.addActionListener(listener);
+			f.addFocusListener(listener);
+		}
+		l.setLabelFor(f);
+		if (mnemonic != '\0')
+			l.setDisplayedMnemonic(mnemonic);
+		p.add(l);
+		p.add(f);
+		return f;
+	}
+	
+	private abstract class CertainTrustActionFocusListener implements ActionListener, FocusListener {
+		@Override
+		public void focusGained(FocusEvent arg0) {}
+
+		@Override
+		public void focusLost(FocusEvent arg0) {
+			update();
+		}
+
+		@Override
+		public void actionPerformed(ActionEvent arg0) {
+			update();
+		}
+		
+		abstract void update();
+		
+		/**
+		 * parseInput tries to convert a textual input into a floating point number in [0;1]
+		 * It accepts both "." and "," as decimal delimiters.
+		 * If the conversion fails, a default value is used.
+		 * @param input	the textual input to convert into a floating point number
+		 * @param defaultValue	the default value used in case the conversion fails
+		 * @return	the floating point value generated from the textual input
+		 */
+		protected double parseInput(String input, double defaultValue) {
+			double result;
+			try {
+				// first, replace the first "," with a "." to understand German-language style floating point notation
+				String rawInput = input.replaceFirst(",", ".");
+				
+				result = Double.parseDouble(rawInput);
+				
+				// check, if the value in within our bounds of [0;1]
+				if ((1 < result) || (0 > result)) {
+					result = defaultValue;
+				}
+			}
+			catch (NumberFormatException e) {
+				result = defaultValue;
+			}
+			return result;
+		}
+	}
+	
+	private void setup(CertainTrustSimple certainlogic, Map<String,String> config) {
+		cl = certainlogic;
+		if (config != null)
+			this.config = config;
+		else
+			this.config = new HashMap<String,String>();
+		
+		if (this.config.containsKey("label.lang") == false)
+			this.config.put("label.lang", "en");
+		if (this.config.get("label.lang") == "de") {
+			if (this.config.containsKey("label.f") == false)
+				this.config.put("label.f", "Initialwert");
+			if (this.config.containsKey("label.t") == false)
+				this.config.put("label.t", "Vertrauen");
+			if (this.config.containsKey("label.c") == false)
+				this.config.put("label.c", "Sicherheit");
+			if (this.config.containsKey("label.e") == false)
+				this.config.put("label.e", "Erwartung");
+		} else {
+			if (this.config.containsKey("label.f") == false)
+				this.config.put("label.f", "Init. value");
+			if (this.config.containsKey("label.t") == false)
+				this.config.put("label.t", "Trust");
+			if (this.config.containsKey("label.c") == false)
+				this.config.put("label.c", "Certainty");
+			if (this.config.containsKey("label.e") == false)
+				this.config.put("label.e", "Expectation");
+		}
+		
+		if (this.config.containsKey("readonly") == false) {
+			if (this.config.containsKey("readonly.f") == false)
+				this.config.put("readonly.f", "false");
+			if (this.config.containsKey("readonly.t") == false)
+				this.config.put("readonly.t", "false");
+			if (this.config.containsKey("readonly.c") == false)
+				this.config.put("readonly.c", "false");
+			if (this.config.containsKey("readonly.e") == false)
+				this.config.put("readonly.e", "true");
+		} else {
+			String readOnly = this.config.get("readonly");
+			if (this.config.containsKey("readonly.f") == false)
+				this.config.put("readonly.f", readOnly);
+			if (this.config.containsKey("readonly.t") == false)
+				this.config.put("readonly.t", readOnly);
+			if (this.config.containsKey("readonly.c") == false)
+				this.config.put("readonly.c", readOnly);
+			if (this.config.containsKey("readonly.e") == false)
+				this.config.put("readonly.e", readOnly);
+		}
+		
+		JPanel inputs = new JPanel(new GridLayout(5,2));
+		f = appendInput(inputs, this.config.get("label.f"), 'f', cl.getF(), this.config.get("readonly.f"),
+				new CertainTrustActionFocusListener() {
+					@Override
+					void update() {
+						cl.setF(this.parseInput(f.getText(), cl.getF()));
+					}
+				});
+		t = appendInput(inputs, this.config.get("label.t"), 't', cl.getT(), this.config.get("readonly.t"),
+				new CertainTrustActionFocusListener() {
+			@Override
+			void update() {
+				cl.setTC(this.parseInput(t.getText(), cl.getT()),
+						cl.getC());
+			}
+		});
+		c = appendInput(inputs, this.config.get("label.c"), 'c', cl.getC(), this.config.get("readonly.c"),
+				new CertainTrustActionFocusListener() {
+			@Override
+			void update() {
+				cl.setTC(cl.getT(),
+						this.parseInput(c.getText(), cl.getC()));
+			}
+		});
+		JLabel ignore0 = new JLabel("");
+		inputs.add(ignore0);
+		JLabel ignore1 = new JLabel("");
+		inputs.add(ignore1);
+		e = appendInput(inputs, this.config.get("label.e"),'\0', cl.getExpectation(), this.config.get("readonly.e"), null);
+		this.add(inputs);
+		
+		JPanel jp = new JPanel();
+		jp.setLayout(new BoxLayout(jp, BoxLayout.PAGE_AXIS));
+		JPanel jp1 = new JPanel();
+		JLabel certain = new JLabel(this.config.get("label.c") + "\u00a0\u2192");
+		certain.setUI(new VerticalLabelUI());
+		jp1.add(certain);
+		ctc = new CertainTrustSimpleCanvas(cl, this.config);
+		ctc.repaint();
+		jp1.add(ctc);
+		JPanel jp2 = new JPanel(new BorderLayout());
+		JLabel origin = new JLabel("0");
+		int fontsize = certain.getFont().getSize();
+		origin.setBorder(new EmptyBorder(0, fontsize, 0, fontsize));
+		jp2.add(origin, BorderLayout.LINE_START);
+		JLabel trust = new JLabel(this.config.get("label.t") + "\u00a0\u2192");
+		jp2.add(trust, BorderLayout.CENTER);
+		jp.add(jp1);
+		jp.add(jp2);
+		
+		this.add(jp);
+		this.setVisible(true);
+		cl.addObserver(this);
+	}
+
+	@Override
+	public void update(Observable ignored0, Object ignored1) {
+		f.setText(CertainTrustSimpleHTI.formatFloat(cl.getF()));
+		t.setText(CertainTrustSimpleHTI.formatFloat(cl.getT()));
+		c.setText(CertainTrustSimpleHTI.formatFloat(cl.getC()));
+		e.setText(CertainTrustSimpleHTI.formatFloat(cl.getExpectation()));
+	}
+	
+	/**
+	 * Rounds a number to at most 3 decimal places and converts it to a string
+	 * @param value	the number to round
+	 * @return	the rounded value as string
+	 */
+	static private String formatFloat(double value) {
+		// the explicit type cast from Long to double is required, otherwise rounded will always be 0
+		double rounded = ((double)Math.round(value * 1000) / 1000);
+		
+		// Use NumerFormat to omit trailing 0s as those which Double.toString() produces
+		NumberFormat formatter = new DecimalFormat("0.###");
+		String result = formatter.format(rounded);
+		
+		// for compatibility with the JS version, our decimal delimiter *always* is "."
+		result = result.replaceFirst(",", ".");
+		
+		return result;
+	}
+}

+ 373 - 0
Java/Java_SDK/src/CertainTrust/Mozilla Public License Version 2.0.txt

@@ -0,0 +1,373 @@
+Mozilla Public License Version 2.0
+==================================
+
+1. Definitions
+--------------
+
+1.1. "Contributor"
+    means each individual or legal entity that creates, contributes to
+    the creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+    means the combination of the Contributions of others (if any) used
+    by a Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+    means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+    means Source Code Form to which the initial Contributor has attached
+    the notice in Exhibit A, the Executable Form of such Source Code
+    Form, and Modifications of such Source Code Form, in each case
+    including portions thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+    means
+
+    (a) that the initial Contributor has attached the notice described
+        in Exhibit B to the Covered Software; or
+
+    (b) that the Covered Software was made available under the terms of
+        version 1.1 or earlier of the License, but not also under the
+        terms of a Secondary License.
+
+1.6. "Executable Form"
+    means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+    means a work that combines Covered Software with other material, in 
+    a separate file or files, that is not Covered Software.
+
+1.8. "License"
+    means this document.
+
+1.9. "Licensable"
+    means having the right to grant, to the maximum extent possible,
+    whether at the time of the initial grant or subsequently, any and
+    all of the rights conveyed by this License.
+
+1.10. "Modifications"
+    means any of the following:
+
+    (a) any file in Source Code Form that results from an addition to,
+        deletion from, or modification of the contents of Covered
+        Software; or
+
+    (b) any new file in Source Code Form that contains any Covered
+        Software.
+
+1.11. "Patent Claims" of a Contributor
+    means any patent claim(s), including without limitation, method,
+    process, and apparatus claims, in any patent Licensable by such
+    Contributor that would be infringed, but for the grant of the
+    License, by the making, using, selling, offering for sale, having
+    made, import, or transfer of either its Contributions or its
+    Contributor Version.
+
+1.12. "Secondary License"
+    means either the GNU General Public License, Version 2.0, the GNU
+    Lesser General Public License, Version 2.1, the GNU Affero General
+    Public License, Version 3.0, or any later versions of those
+    licenses.
+
+1.13. "Source Code Form"
+    means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+    means an individual or a legal entity exercising rights under this
+    License. For legal entities, "You" includes any entity that
+    controls, is controlled by, or is under common control with You. For
+    purposes of this definition, "control" means (a) the power, direct
+    or indirect, to cause the direction or management of such entity,
+    whether by contract or otherwise, or (b) ownership of more than
+    fifty percent (50%) of the outstanding shares or beneficial
+    ownership of such entity.
+
+2. License Grants and Conditions
+--------------------------------
+
+2.1. Grants
+
+Each Contributor hereby grants You a world-wide, royalty-free,
+non-exclusive license:
+
+(a) under intellectual property rights (other than patent or trademark)
+    Licensable by such Contributor to use, reproduce, make available,
+    modify, display, perform, distribute, and otherwise exploit its
+    Contributions, either on an unmodified basis, with Modifications, or
+    as part of a Larger Work; and
+
+(b) under Patent Claims of such Contributor to make, use, sell, offer
+    for sale, have made, import, and otherwise transfer either its
+    Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+The licenses granted in Section 2.1 with respect to any Contribution
+become effective for each Contribution on the date the Contributor first
+distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+The licenses granted in this Section 2 are the only rights granted under
+this License. No additional rights or licenses will be implied from the
+distribution or licensing of Covered Software under this License.
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
+Contributor:
+
+(a) for any code that a Contributor has removed from Covered Software;
+    or
+
+(b) for infringements caused by: (i) Your and any other third party's
+    modifications of Covered Software, or (ii) the combination of its
+    Contributions with other software (except as part of its Contributor
+    Version); or
+
+(c) under Patent Claims infringed by Covered Software in the absence of
+    its Contributions.
+
+This License does not grant any rights in the trademarks, service marks,
+or logos of any Contributor (except as may be necessary to comply with
+the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+No Contributor makes additional grants as a result of Your choice to
+distribute the Covered Software under a subsequent version of this
+License (see Section 10.2) or under the terms of a Secondary License (if
+permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+Each Contributor represents that the Contributor believes its
+Contributions are its original creation(s) or it has sufficient rights
+to grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+This License is not intended to limit any rights You have under
+applicable copyright doctrines of fair use, fair dealing, or other
+equivalents.
+
+2.7. Conditions
+
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
+in Section 2.1.
+
+3. Responsibilities
+-------------------
+
+3.1. Distribution of Source Form
+
+All distribution of Covered Software in Source Code Form, including any
+Modifications that You create or to which You contribute, must be under
+the terms of this License. You must inform recipients that the Source
+Code Form of the Covered Software is governed by the terms of this
+License, and how they can obtain a copy of this License. You may not
+attempt to alter or restrict the recipients' rights in the Source Code
+Form.
+
+3.2. Distribution of Executable Form
+
+If You distribute Covered Software in Executable Form then:
+
+(a) such Covered Software must also be made available in Source Code
+    Form, as described in Section 3.1, and You must inform recipients of
+    the Executable Form how they can obtain a copy of such Source Code
+    Form by reasonable means in a timely manner, at a charge no more
+    than the cost of distribution to the recipient; and
+
+(b) You may distribute such Executable Form under the terms of this
+    License, or sublicense it under different terms, provided that the
+    license for the Executable Form does not attempt to limit or alter
+    the recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+You may create and distribute a Larger Work under terms of Your choice,
+provided that You also comply with the requirements of this License for
+the Covered Software. If the Larger Work is a combination of Covered
+Software with a work governed by one or more Secondary Licenses, and the
+Covered Software is not Incompatible With Secondary Licenses, this
+License permits You to additionally distribute such Covered Software
+under the terms of such Secondary License(s), so that the recipient of
+the Larger Work may, at their option, further distribute the Covered
+Software under the terms of either this License or such Secondary
+License(s).
+
+3.4. Notices
+
+You may not remove or alter the substance of any license notices
+(including copyright notices, patent notices, disclaimers of warranty,
+or limitations of liability) contained within the Source Code Form of
+the Covered Software, except that You may alter any license notices to
+the extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+You may choose to offer, and to charge a fee for, warranty, support,
+indemnity or liability obligations to one or more recipients of Covered
+Software. However, You may do so only on Your own behalf, and not on
+behalf of any Contributor. You must make it absolutely clear that any
+such warranty, support, indemnity, or liability obligation is offered by
+You alone, and You hereby agree to indemnify every Contributor for any
+liability incurred by such Contributor as a result of warranty, support,
+indemnity or liability terms You offer. You may include additional
+disclaimers of warranty and limitations of liability specific to any
+jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+---------------------------------------------------
+
+If it is impossible for You to comply with any of the terms of this
+License with respect to some or all of the Covered Software due to
+statute, judicial order, or regulation then You must: (a) comply with
+the terms of this License to the maximum extent possible; and (b)
+describe the limitations and the code they affect. Such description must
+be placed in a text file included with all distributions of the Covered
+Software under this License. Except to the extent prohibited by statute
+or regulation, such description must be sufficiently detailed for a
+recipient of ordinary skill to be able to understand it.
+
+5. Termination
+--------------
+
+5.1. The rights granted under this License will terminate automatically
+if You fail to comply with any of its terms. However, if You become
+compliant, then the rights granted under this License from a particular
+Contributor are reinstated (a) provisionally, unless and until such
+Contributor explicitly and finally terminates Your grants, and (b) on an
+ongoing basis, if such Contributor fails to notify You of the
+non-compliance by some reasonable means prior to 60 days after You have
+come back into compliance. Moreover, Your grants from a particular
+Contributor are reinstated on an ongoing basis if such Contributor
+notifies You of the non-compliance by some reasonable means, this is the
+first time You have received notice of non-compliance with this License
+from such Contributor, and You become compliant prior to 30 days after
+Your receipt of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+infringement claim (excluding declaratory judgment actions,
+counter-claims, and cross-claims) alleging that a Contributor Version
+directly or indirectly infringes any patent, then the rights granted to
+You by any and all Contributors for the Covered Software under Section
+2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
+end user license agreements (excluding distributors and resellers) which
+have been validly granted by You or Your distributors under this License
+prior to termination shall survive termination.
+
+************************************************************************
+*                                                                      *
+*  6. Disclaimer of Warranty                                           *
+*  -------------------------                                           *
+*                                                                      *
+*  Covered Software is provided under this License on an "as is"       *
+*  basis, without warranty of any kind, either expressed, implied, or  *
+*  statutory, including, without limitation, warranties that the       *
+*  Covered Software is free of defects, merchantable, fit for a        *
+*  particular purpose or non-infringing. The entire risk as to the     *
+*  quality and performance of the Covered Software is with You.        *
+*  Should any Covered Software prove defective in any respect, You     *
+*  (not any Contributor) assume the cost of any necessary servicing,   *
+*  repair, or correction. This disclaimer of warranty constitutes an   *
+*  essential part of this License. No use of any Covered Software is   *
+*  authorized under this License except under this disclaimer.         *
+*                                                                      *
+************************************************************************
+
+************************************************************************
+*                                                                      *
+*  7. Limitation of Liability                                          *
+*  --------------------------                                          *
+*                                                                      *
+*  Under no circumstances and under no legal theory, whether tort      *
+*  (including negligence), contract, or otherwise, shall any           *
+*  Contributor, or anyone who distributes Covered Software as          *
+*  permitted above, be liable to You for any direct, indirect,         *
+*  special, incidental, or consequential damages of any character      *
+*  including, without limitation, damages for lost profits, loss of    *
+*  goodwill, work stoppage, computer failure or malfunction, or any    *
+*  and all other commercial damages or losses, even if such party      *
+*  shall have been informed of the possibility of such damages. This   *
+*  limitation of liability shall not apply to liability for death or   *
+*  personal injury resulting from such party's negligence to the       *
+*  extent applicable law prohibits such limitation. Some               *
+*  jurisdictions do not allow the exclusion or limitation of           *
+*  incidental or consequential damages, so this exclusion and          *
+*  limitation may not apply to You.                                    *
+*                                                                      *
+************************************************************************
+
+8. Litigation
+-------------
+
+Any litigation relating to this License may be brought only in the
+courts of a jurisdiction where the defendant maintains its principal
+place of business and such litigation shall be governed by laws of that
+jurisdiction, without reference to its conflict-of-law provisions.
+Nothing in this Section shall prevent a party's ability to bring
+cross-claims or counter-claims.
+
+9. Miscellaneous
+----------------
+
+This License represents the complete agreement concerning the subject
+matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent
+necessary to make it enforceable. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+shall not be used to construe this License against a Contributor.
+
+10. Versions of the License
+---------------------------
+
+10.1. New Versions
+
+Mozilla Foundation is the license steward. Except as provided in Section
+10.3, no one other than the license steward has the right to modify or
+publish new versions of this License. Each version will be given a
+distinguishing version number.
+
+10.2. Effect of New Versions
+
+You may distribute the Covered Software under the terms of the version
+of the License under which You originally received the Covered Software,
+or under the terms of any subsequent version published by the license
+steward.
+
+10.3. Modified Versions
+
+If you create software not governed by this License, and you want to
+create a new license for such software, you may create and use a
+modified version of this License if you rename the license and remove
+any references to the name of the license steward (except to note that
+such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+Licenses
+
+If You choose to distribute Source Code Form that is Incompatible With
+Secondary Licenses under the terms of this version of the License, the
+notice described in Exhibit B of this License must be attached.
+
+Exhibit A - Source Code Form License Notice
+-------------------------------------------
+
+  This Source Code Form is subject to the terms of the Mozilla Public
+  License, v. 2.0. If a copy of the MPL was not distributed with this
+  file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular
+file, then You may include the notice in a location (such as a LICENSE
+file in a relevant directory) where a recipient would be likely to look
+for such a notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+---------------------------------------------------------
+
+  This Source Code Form is "Incompatible With Secondary Licenses", as
+  defined by the Mozilla Public License, v. 2.0.

+ 197 - 0
Java/Java_SDK/src/CertainTrust/VerticalLabelUI.java

@@ -0,0 +1,197 @@
+package CertainTrust;
+/**
+ * @(#)VerticalLabelUI.java	1.0 02/18/09
+ * 
+ * @see http://tips4java.wordpress.com/2009/02/21/vertical-label-ui/
+ * @author Darryl Burke
+ * 
+ * Some modifications to fix warnings shown by picky settings
+ * like "possible static methods" and co
+ * @author David Kalnischkies <kalnischkies@gmail.com>
+ */
+
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import javax.swing.Icon;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.SwingUtilities;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicLabelUI;
+
+/**
+ * A UI delegate for JLabel that rotates the label 90�
+ * <P>
+ * Extends {@link BasicLabelUI}.
+ * <P>
+ * The only difference between the appearance of labels in the Basic and Metal
+ * L&Fs is the manner in which diabled text is painted.  As VerticalLabelUI
+ * does not override the method paintDisabledText, this class can be adapted
+ * for Metal L&F by extending MetalLabelUI instead of BasicLabelUI.
+ * <P>
+ * No other changes are required.
+ * 
+ * @author Darryl
+ */
+public class VerticalLabelUI extends BasicLabelUI {
+
+   private boolean clockwise = false;
+   // see comment in BasicLabelUI
+   Rectangle verticalViewR = new Rectangle();
+   Rectangle verticalIconR = new Rectangle();
+   Rectangle verticalTextR = new Rectangle();
+   protected static VerticalLabelUI verticalLabelUI =
+         new VerticalLabelUI();
+   private final static VerticalLabelUI SAFE_VERTICAL_LABEL_UI =
+         new VerticalLabelUI();
+
+   /**
+    * Constructs a <code>VerticalLabelUI</code> with the default anticlockwise
+    * rotation
+    */
+   public VerticalLabelUI() {
+   }
+
+   /**
+    * Constructs a <code>VerticalLabelUI</code> with the desired rotation.
+    * <P>
+    * @param clockwise true to rotate clockwise, false for anticlockwise
+    */
+   public VerticalLabelUI(boolean clockwise) {
+      this.clockwise = clockwise;
+   }
+
+   /**
+    * @see ComponentUI#createUI(javax.swing.JComponent) 
+    */
+   public static ComponentUI createUI(JComponent c) {
+      if (System.getSecurityManager() != null)
+         return SAFE_VERTICAL_LABEL_UI;
+      return verticalLabelUI;
+   }
+
+   /**
+    * Overridden to always return -1, since a vertical label does not have a
+    * meaningful baseline.
+    * 
+    * @see ComponentUI#getBaseline(JComponent, int, int)
+    */
+   @Override
+   public int getBaseline(JComponent c, int width, int height) {
+      super.getBaseline(c, width, height);
+      return -1;
+   }
+
+   /**
+    * Overridden to always return Component.BaselineResizeBehavior.OTHER,
+    * since a vertical label does not have a meaningful baseline 
+    * 
+    * @see ComponentUI#getBaselineResizeBehavior(javax.swing.JComponent)
+    */
+   @Override
+   public Component.BaselineResizeBehavior getBaselineResizeBehavior(
+         JComponent c) {
+      super.getBaselineResizeBehavior(c);
+      return Component.BaselineResizeBehavior.OTHER;
+   }
+
+   /**
+    * Transposes the view rectangles as appropriate for a vertical view
+    * before invoking the super method and copies them after they have been
+    * altered by {@link SwingUtilities#layoutCompoundLabel(FontMetrics, String,
+    * Icon, int, int, int, int, Rectangle, Rectangle, Rectangle, int)}
+    */
+   @Override
+   protected String layoutCL(JLabel label, FontMetrics fontMetrics,
+         String text, Icon icon, Rectangle viewR, Rectangle iconR,
+         Rectangle textR) {
+
+      verticalViewR = transposeRectangle(viewR, verticalViewR);
+      verticalIconR = transposeRectangle(iconR, verticalIconR);
+      verticalTextR = transposeRectangle(textR, verticalTextR);
+
+      text = super.layoutCL(label, fontMetrics, text, icon,
+            verticalViewR, verticalIconR, verticalTextR);
+
+      viewR = copyRectangle(verticalViewR, viewR);
+      iconR = copyRectangle(verticalIconR, iconR);
+      textR = copyRectangle(verticalTextR, textR);
+      return text;
+   }
+
+   /**
+    * Transforms the Graphics for vertical rendering and invokes the
+    * super method.
+    */
+   @Override
+   public void paint(Graphics g, JComponent c) {
+      Graphics2D g2 = (Graphics2D) g.create();
+      if (clockwise) {
+         g2.rotate(Math.PI / 2, c.getSize().width / 2, c.getSize().width / 2);
+      } else {
+         g2.rotate(-Math.PI / 2, c.getSize().height / 2, c.getSize().height / 2);
+      }
+      super.paint(g2, c);
+   }
+
+   /**
+    * Returns a Dimension appropriate for vertical rendering
+    * 
+    * @see ComponentUI#getPreferredSize(javax.swing.JComponent)
+    */
+   @Override
+   public Dimension getPreferredSize(JComponent c) {
+      return transposeDimension(super.getPreferredSize(c));
+   }
+
+   /**
+    * Returns a Dimension appropriate for vertical rendering
+    * 
+    * @see ComponentUI#getMaximumSize(javax.swing.JComponent)
+    */
+   @Override
+   public Dimension getMaximumSize(JComponent c) {
+      return transposeDimension(super.getMaximumSize(c));
+   }
+
+   /**
+    * Returns a Dimension appropriate for vertical rendering
+    * 
+    * @see ComponentUI#getMinimumSize(javax.swing.JComponent)
+    */
+   @Override
+   public Dimension getMinimumSize(JComponent c) {
+      return transposeDimension(super.getMinimumSize(c));
+   }
+
+   private static Dimension transposeDimension(Dimension from) {
+      return new Dimension(from.height, from.width + 2);
+   }
+
+   private static Rectangle transposeRectangle(Rectangle from, Rectangle to) {
+      if (to == null) {
+         to = new Rectangle();
+      }
+      to.x = from.y;
+      to.y = from.x;
+      to.width = from.height;
+      to.height = from.width;
+      return to;
+   }
+
+   private static Rectangle copyRectangle(Rectangle from, Rectangle to) {
+      if (to == null) {
+         to = new Rectangle();
+      }
+      to.x = from.x;
+      to.y = from.y;
+      to.width = from.width;
+      to.height = from.height;
+      return to;
+   }
+}

+ 984 - 0
JavaScript/JavaScript_Examples/CertainTrust.js

@@ -0,0 +1,984 @@
+/**
+ * CertainTrust SDK
+ *
+ * Implements the computational trust model "CertainTrust"
+ * in JavaScript.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ *
+ *
+ * Telecooperation Department, Technische Universität Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ *
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ *
+ *
+ * @author	Maria Pelevina
+ * @author	David Kalnischkies
+ * @version	1.1
+ */
+ 
+ /* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+ 
+
+/**
+ * Available Constructors:
+ * - CertainTrust(t, c, f, n)
+ * - CertainTrust(r, s, n)
+ * - CertainTrust(n)
+ * optionally arguments can be preceded by name, e.g. CertainTrust(name, r, s, n)
+ *
+ * t - average rating value, [0; 1], from very negative to very positive
+ * c - certainty value, [0; 1] from low certainty (no evidence) to the maximal maximal certainty.
+ * f - initial trust value
+ * w - weight
+ * r - number of positive evidence
+ * s - number of negative evidence
+ * n - maximal number of expected evidence
+ */
+
+var CertainTrust = function() {
+	this.weight = 2;
+	this.observers = [];
+
+	var offset = 0;
+	this.name = "";
+
+	if (this._isString(arguments[0])) {
+		this.name = arguments[0];
+		offset = 1;
+	}
+	if (arguments.length == 4 + offset || arguments.length == 5 + offset) {
+		// CertainTrust(t, c, f, n, doc)
+		// doc is a 'private' parameter
+		this.t = arguments[0 + offset];
+		this.c = arguments[1 + offset];
+		this.f = arguments[2 + offset];
+		this.n = arguments[3 + offset];
+		this.doc = (arguments.length == 4 + offset) ? 0 : arguments[4 + offset];
+		this.r = 0;
+		this.s = 0;
+
+		if (this.n <= 0)
+			throw "N should be greater than 0. Entered n = " + this.n + "\n";
+		if (this.f < 0 && this.f > 1)
+			throw "f should lie within [0;1]. Entered f = " + this.f + "\n";
+		if (this.c < 0 && this.c > 1)
+			throw "c should lie within [0;1]. Entered c = " + this.c + "\n";
+		if (this.t < 0 && this.t > 1)
+			throw "t should lie within [0;1]. Entered t = " + this.t + "\n";
+
+		this._calculateTCtoRS();
+	} else if (arguments.length == 3 + offset) {
+		// CertainTrust(r, s, n)
+		this.n = arguments[2 + offset];
+		this.c = 0;
+		this.t = 0.5;
+		this.f = 0.5;
+		this.r = arguments[0 + offset];
+		this.s = arguments[1 + offset];
+		this.doc = 0;
+
+		if (this.n <= 0)
+			throw "N should be greater than 0. Entered n = " + this.n + "\n";
+		if (this.r < 0)
+			throw "r should be positive. Entered r = " + this.r + "\n";
+		if (this.s < 0)
+			throw "s should be positive. Entered s = " + this.s + "\n";
+
+		this._normaliseRS();
+		this._calculateRStoTC();
+	} else {
+		if (arguments.length == 1 + offset) {
+			// CertainTrust(n)
+			this.n = arguments[0 + offset];
+			if (this.n <= 0)
+				throw "N should be greater than 0. Entered n = " + this.n + "\n";
+			this.c = 0;
+			this.t = 0.5;
+			this.f = 0.5;
+			this.r = 0;
+			this.s = 0;
+			this.doc = 0;
+		}
+		else throw "Illegal number of arguments: " + arguments.length + "\n";
+	}
+};
+
+//=========== Getters =================
+CertainTrust.prototype.getName = function() {
+	return this.name;
+};
+
+CertainTrust.prototype.getC = function() {
+	return this.c;
+};
+
+CertainTrust.prototype.getT = function() {
+	return this.t;
+};
+
+CertainTrust.prototype.getF = function() {
+	return this.f;
+};
+
+CertainTrust.prototype.getR = function() {
+	return this.r;
+};
+
+CertainTrust.prototype.getS = function() {
+	return this.s;
+};
+
+CertainTrust.prototype.getN = function() {
+	return this.n;
+};
+
+CertainTrust.prototype.getDoC = function() {
+	return this.doc;
+};
+
+CertainTrust.prototype.getExpectation = function() {
+	return (this.t * this.c) + ((1 - this.c) * this.f);
+};
+
+//=========== Setters =================
+/**
+ * Resets N value. Renormalises r and s values, recalculates c and t accordingly.
+ * @param n - new maximal number of expected evidence
+ */
+CertainTrust.prototype.setN = function(n) {
+	if (n > 0) {
+		this.n = n;
+		this._normaliseRS();
+		this._calculateRStoTC();
+
+		this.notifyObservers();
+	}
+	else throw "N should be greater than 0. Entered n = " + n + "\n";
+};
+
+/**
+ * Sets f value.
+ * @param f - initial trust value.
+ */
+CertainTrust.prototype.setF = function(f) {
+	if (f >= 0 && f <= 1) {
+		this.f = f;
+
+		this.notifyObservers();
+	}
+	else throw "f should lie within [0;1]. Entered f = " + f + "\n";
+};
+
+/**
+ * Sets Degree of Conflict value.
+ * @param doc is the new value for DoC
+ */
+CertainTrust.prototype.setDoC = function(doc) {
+	if (doc >= 0)
+		this.doc = doc;
+	else throw "DoC should be greater than 0. Entered DoC = " + doc + "\n";
+};
+
+/**
+ * Sets c and t values. Recalculates r and s values accordingly.
+ * @param t - new average trust value
+ * @param c - new certainty value
+ */
+CertainTrust.prototype.setTC = function(t, c) {
+	if (c >= 0 && c <= 1) {
+		if (t >= 0 && t <= 1) {
+			this.c = c;
+			this.t = t;
+			this._calculateTCtoRS();
+
+			this.notifyObservers();
+		}
+		else throw "t should be greater than 0. Entered t = " + t + "\n";
+	}
+	else throw "c should lie within [0;1]. Entered c = " + c + "\n";
+};
+
+/**
+ * Sets r and s values. Recalculates c and t values accordingly.
+ * @param r - new number of positive evidence
+ * @param s - new number of negative evidence
+ */
+CertainTrust.prototype.setRS = function(r, s) {
+	if (r >= 0) {
+		if (s >= 0) {
+			this.r = r;
+			this.s = s;
+			this._normaliseRS();
+			this._calculateRStoTC();
+
+			this.notifyObservers();
+		}
+		else throw "s should be positive. Entered s = " + s + "\n";
+	}
+	else throw "r should be positive. Entered r = " + r + "\n";
+};
+
+/**
+ * Add some positive evidence to r.
+ * @param posEvidence - number of new positive evidences
+ */
+CertainTrust.prototype.addR = function(posEvidence) {
+	if (posEvidence >= 0) {
+		this.r += posEvidence;
+		this._normaliseRS();
+		this._calculateRStoTC();
+
+		this.notifyObservers();
+	}
+	else throw "Number of positive evidences should be positive. Entered " + posEvidence + "\n";
+};
+
+/**
+ * Add some negative evidence to s.
+ * @param negEvidence - number of new negative evidences
+ */
+CertainTrust.prototype.addS = function(negEvidence) {
+	if (negEvidence >= 0) {
+		this.s += negEvidence;
+		this._normaliseRS();
+		this._calculateRStoTC();
+
+		this.notifyObservers();
+	}
+	else throw "Number of negative evidences should be positive. Entered " + negEvidence + "\n";
+};
+
+//=========== Logic =================
+/**
+ * Computes OR function for this CertainTrust object and the specified argument. Result is returned as a new object,
+ * argument and this CertainTrust object remain unchanged.
+ * N values of both objects should be equal.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @param arg - CertainTrust object
+ * @return - result of OR computation for this object and an argument.
+ */
+CertainTrust.prototype._singleOR = function(arg) {
+	var c1 = this.getC();
+	var t1 = this.getT();
+	var f1 = this.getF();
+
+	var c2 = arg.getC();
+	var t2 = arg.getT();
+	var f2 = arg.getF();
+
+	var resT = 0.5, resF = 0.5, resC = 0;
+
+	if (!this._operationAllowed(this, arg))
+		return undefined;
+
+	resF = f1 + f2 - f1*f2;
+
+	if (this._almostEqual(resF, 0))
+		resC = c1 + c2 - c1*c2;
+	else
+		resC = c1 + c2 - c1*c2 - (c1*f2*(1-c2)*(1-t1)+c2*f1*(1-c1)*(1-t2)) / resF;
+
+	if (this._almostEqual(resC, 0))
+		resT = 0.5;
+	else resT = (1/resC) * (c1*t1 + c2*t2 - c1*c2*t1*t2);
+
+	resT = this._adjustValue(resT);
+	resC = this._adjustValue(resC);
+	resF = this._adjustValue(resF);
+
+	var result = new CertainTrust(resT, resC, resF, this.n, 0);
+
+	return result;
+};
+
+/**
+ * Computes OR function for this CertainTrust object and the specified arguments.
+ * Result is returned as a new object, arguments and this CertainTrust object remain unchanged.
+ * Example: a.OR(b, c, d) returns new CertainTrust object that equals a OR b OR c OR d.
+ * Multiple arguments allowed, but not less than one.
+ * N values of all objects should be equal.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @param args - arguments
+ * @return - result of OR computation for this object and all arguments.
+ */
+CertainTrust.prototype.OR = function() {
+	var result = this.clone();
+	for (var i = 0; i < arguments.length; ++i) {
+		var m = arguments[i];
+		if (!this._operationAllowed(this, m))
+			continue;
+		result = result._singleOR(m);
+	}
+	return result;
+};
+
+/**
+ * Computes AND function for this CertainTrust object and the specified argument. Result is returned as a new object,
+ * argument and this CertainTrust object remain unchanged.
+ * N values of both objects should be equal.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @param arg - CertainTrust object
+ * @return - result of AND computation for this object and an argument.
+ */
+CertainTrust.prototype._singleAND = function(arg){
+	var c1 = this.getC();
+	var f1 = this.getF();
+	var t1 = this.getT();
+
+	var c2 = arg.getC();
+	var f2 = arg.getF();
+	var t2 = arg.getT();
+
+	var resC = 0, resT = 0.5, resF = 0.5;
+
+	if (!this._operationAllowed(this, arg))
+		return undefined;
+
+	resF = f1*f2;
+	if (this._almostEqual(resF, 1))		//avoid division by 0
+		resC = c1 + c2 - c1*c2;
+	else
+		resC = c1 + c2 - c1*c2 - (c2*t2*(1-c1)*(1-f1)+c1*t1*(1-c2)*(1-f2)) / (1 - resF);
+
+	if (this._almostEqual(resC, 0))
+		resT = 0.5;
+	else if (this._almostEqual(resF, 1))	//avoid division by 0
+		resT = (1/resC) *  (c1*t1*c2*t2);
+	else resT = (1/resC) *  ((c1*t1*c2*t2) + (c1*f2*t1*(1-c2)*(1-f1)+c2*f1*t2*(1-c1)*(1-f2)) / (1 - resF));
+
+	resT = this._adjustValue(resT);
+	resC = this._adjustValue(resC);
+	resF = this._adjustValue(resF);
+
+	return new CertainTrust(resT, resC, resF, this.n, 0);
+};
+
+CertainTrust.prototype._adjustValue = function(arg) {
+	return Math.max(Math.min(arg, 1), 0);
+};
+
+CertainTrust.prototype._almostEqual = function(value, target) {
+	return Math.abs(value - target) < 1E-10;
+};
+
+CertainTrust.prototype._operationAllowed = function(arg1, arg2) {
+	//and all N's of TC's must be equal
+	/*if (arg1.getN() != arg2.getN())							//Disabled by Debashis C. Ray for AND calculation
+		throw "Different N values. Operation not allowed. \n"; */
+	return true;
+}
+
+/**
+ * Computes AND function for this CertainTrust object and the specified arguments.
+ * Result is returned as a new object, arguments and this CertainTrust object remain unchanged.
+ * Example: a.AND(b, c, d) returns new CertainTrust object that equals a AND b AND c AND d.
+ * Multiple arguments allowed, but not less than one.
+ * N values of all objects should be equal.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @param args - arguments
+ * @return - result of AND computation for this object and all arguments.
+ */
+CertainTrust.prototype.AND = function() {
+	var result = this.clone();
+	for (var i = 0; i < arguments.length; i++) {
+		var m = arguments[i];
+		if (!this._operationAllowed(this, m))
+			continue;
+		result = result._singleAND(m);
+	}
+	return result;
+};
+
+/**
+ * Returns NOT of this CertainTrust object.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @return - NOT of this CertainTrust object.
+ */
+CertainTrust.prototype.NOT = function() {
+	var result = this.clone();
+	result.setTC(1 - this.getT(), this.getC());
+	result.setF(1 - this.getF());
+	result.setDoC(0);
+	return result;
+};
+
+/**
+ * an internal implementation of fusion function.
+ * Is called by wFusion and cFusion
+ * @param args - an array of CertainTrust objects
+ * @param weights - an integer array of corresponding weights
+ * @param doc - a degree of conflict (always 0 for wFusion)
+ * @return - new CertainTrust object
+ */
+CertainTrust.prototype._internalFusion = function(args, weights, doc) {
+	var resC, resT, resF;
+	var allOne = true;
+	var allZero = true;
+	var allWeightsZero = true;
+	var atLeastOne1 = false;
+	var arrLength = args.length;
+
+	// set the flags about C and Weight values
+	for (var i = 0; i < arrLength; ++i)
+		if (args[i].getC() !== 1) {
+			allOne = false;
+			i = arrLength;
+		}
+	for (i = 0; i < arrLength; ++i)
+		if (args[i].getC() !== 0) {
+			allZero = false;
+			i = arrLength;
+		}
+	for (i = 0; i < arrLength; ++i)
+		if (weights[i] !== 0) {
+			allWeightsZero = false;
+			i = arrLength;
+		}
+	for (i = 0; i < arrLength; ++i)
+		if (args[i].getC() === 1) {
+			atLeastOne1 = true;
+			i = arrLength;
+		}
+
+	//Calculate T and C
+
+	// 1. all C's  = 1
+	var numeratorT = 0, denominatorT = 0;
+	if (allOne) {
+		// set C
+		resC = 1 * (1 - doc);
+		// set T
+		if (allWeightsZero) {// save some calculation time
+			resT = 0;
+		}
+		else {				// or use the function
+			for (i = 0; i < arrLength; ++i) {
+				numeratorT += weights[i] * args[i].getT();
+				denominatorT += weights[i];
+			}
+			resT = numeratorT/denominatorT;
+		}
+	} else {
+		if (atLeastOne1)
+			throw "Illegal arguments. Either all C values must equal 1 or none of them. Operation not allowed\n";
+		else {
+			// 2. Any other combination
+			if (allWeightsZero) { // save some calculation time
+				resT = 0;
+				resC = 0;
+			}
+			else {					// or use the function
+				var numeratorC = 0, denominatorC = 0, mult;
+				for (i = 0; i < arrLength; ++i) {
+					mult = 1;
+					for (var j = 0; j < arrLength; ++j) // Count the product for each sum element
+						if (j !== i)
+							mult *= 1 - args[j].getC();
+					numeratorT += weights[i] * args[i].getT() * args[i].getC() * mult;
+					denominatorT += weights[i] * args[i].getC() * mult;
+					denominatorC += weights[i] * mult;
+				}
+				numeratorC = denominatorT;
+				resC = (numeratorC/denominatorC) * (1 - doc);
+				if (allZero)
+					resT = 0.5;
+				else
+					resT = numeratorT/denominatorT;
+			}
+			// Special case for T
+			if (allZero)
+				resT = 0.5;
+		}
+	}
+
+	// Calculate F
+	if (allWeightsZero)
+		resF = 0;
+	else {
+		var numerator = 0, denominator = 0;
+		for (i = 0; i < arrLength; ++i) {
+			numerator += weights[i] * args[i].getF();
+			denominator += weights[i];
+		}
+		resF = numerator/denominator;
+	}
+
+	var result = args[0].clone();
+	result.setTC(resT, resC);
+	result.setF(resF);
+	result.setDoC(doc);
+	return result;
+};
+
+/**
+ * Performs weighted fusion for an array of CertainTrust objects in correspondence with
+ * an array of weights. Returns new CertainTrust object.
+ * Requirements: N values of CertainTrust objects must be equal.
+ * Number of weights should equal the number of CertainTrust objects.
+ * Arrays must be non-empty
+ * Either all of CertainTrust must be of certainty 1 or none of them.
+ * @param args - an array of CertainTrust objects
+ * @param weights - an integer array of corresponding weights
+ * @return - new CertainTrust object
+ */
+CertainTrust.prototype.wFusion = function(args, weights) {
+	//arrays should be equal
+	if (args.length == weights.length) {
+		//and not empty
+		if (args.length !== 0) {
+			for (var i = 1; i < args.length; ++i)
+				if (!this._operationAllowed(args[0], args[i]))
+					return undefined;
+
+			return this._internalFusion(args, weights, 0);
+		}
+		else throw "Arrays are empty. Operation not allowed. \n";
+	}
+	else throw "Different lengths of arrays. Operation not allowed. \n";
+};
+
+/**
+ * Conflicted Fusion is a variation of weighted fusion, which additionally computes the degree of conflict 
+ * between given opinions (CertainTrust objects) and takes it into consideration while performing fusion.
+ * The degree of conflict is then saved in the resulting CertainTrust object and may be checked with getDoC() function.
+ * @param args - an array of CertainTrust objects
+ * @param weights - an integer array of corresponding weights
+ * @return - new CertainTrust object
+ */
+CertainTrust.prototype.cFusion = function(args, weights) {
+	//arrays should be equal
+	if (args.length == weights.length) {
+		//and not empty
+		if (args.length !== 0) {
+			for (var i = 1; i < args.length; ++i)
+				if (!this._operationAllowed(args[0], args[i]))
+					return undefined;
+			var denominator = args.length*(args.length - 1) / 2;
+			var numerator = 0;
+			for (i = 0; i < args.length; ++i)
+				for (var j = i; j < args.length; ++j)
+					numerator += Math.abs(args[i].getT() - args[j].getT()) *
+						args[i].getC() * args[j].getC() *
+						(1 - Math.abs((weights[i] - weights[j]) /
+							      (weights[i] + weights[j])));
+			var doc = numerator/denominator;
+			return this._internalFusion(args, weights, doc);
+		}
+		else throw "Arrays are empty. Operation not allowed. \n";
+	}
+	else throw "Different lengths of arrays. Operation not allowed. \n";
+};
+
+//=========== Internal Calculations ==========
+/**
+ * Normalises r and s values according to n - maximal number of expected evidence
+ * Important! Doesn't notify observers.
+ */
+CertainTrust.prototype._normaliseRS = function() {
+	if ((this.r + this.s) > this.n) {
+		var initR = this.r;
+		this.r = (this.r * this.n) / (initR + this.s);
+		this.s = (this.s * this.n) / (initR + this.s);
+	}
+};
+
+/**
+ * Calculates t and c values based on existing r and s values
+ * Important! Doesn't notify observers.
+ */
+CertainTrust.prototype._calculateRStoTC = function() {
+	var rs = this.r + this.s;
+	var nrs = this.n * rs;
+	this.c = nrs / ((2 * this.weight * (this.n - this.r - this.s)) + nrs);
+	if (this._almostEqual(this.c, 0))
+		this.t = 0.5;
+	else
+		this.t = this.r / rs;
+};
+
+/**
+ * Calculates r and s values based on existing c and t values
+ * Important! Doesn't notify observers.
+ */
+CertainTrust.prototype._calculateTCtoRS = function() {
+	if (this._almostEqual(this.c, 0)) {
+		this.r = 0;
+		this.s = 0;
+		this.t = 0.5;
+	}
+	else {
+		var c2w = this.c * 2 * this.weight;
+		var c2wn = c2w * this.n;
+		var cn = this.c * this.n;
+		this.r = (c2wn * this.t) / (c2w + this.n - cn);
+		this.s = (c2wn - (c2wn * this.t)) / (c2w + this.n - cn);
+	}
+};
+
+CertainTrust.prototype.clone = function() {
+	var copy = new CertainTrust(this.getN());
+	copy.c = this.c;
+	copy.t = this.t;
+	copy.f = this.f;
+	copy.r = this.r;
+	copy.s = this.s;
+	copy.doc = this.doc;
+	return copy;
+};
+
+CertainTrust.prototype._isString = function (obj) {
+  return typeof(obj) === 'string';
+};
+
+//=========== Observer =================
+CertainTrust.prototype.notifyObservers = function(message) {
+	for (var i = 0; i < this.observers.length; ++i)
+		this.observers[i].update(this.observers[i], message);
+};
+CertainTrust.prototype.addObserver = function(observer) {
+	this.observers.push(observer);
+};
+CertainTrust.prototype.deleteObserver = function(observer) {
+	var idx = this.observers.indexOf(observer);
+	if(idx !== -1)
+		this.observers.splice(idx, 1);
+};
+
+//=== shared functions for frontends ===
+CertainTrust.prototype._insertElement = function(config, element) {
+	var dom;
+	if (config.domReturn === true) {
+		return element;
+	} else if (config.domParent !== undefined) {
+		if (this._isString(config.domParent))
+			document.getElementById(config.domParent).appendChild(element);
+		else
+			config.domParent.appendChild(element);
+	} else if (config.domBefore !== undefined) {
+		if (this._isString(config.domBefore))
+			dom = document.getElementById(config.domBefore);
+		else
+			dom = config.domBefore;
+		dom.parentNode.insertBefore(element, dom);
+	} else {
+		if (config.domAfter === undefined) {
+			// the last script tag in DOM tree is the one creating this widget
+			var scripts = document.getElementsByTagName('script');
+			dom = scripts[scripts.length - 1];
+		} else if (this._isString(config.domAfter))
+			dom = document.getElementById(config.domAfter);
+		else
+			dom = config.domAfter;
+		dom.parentNode.insertBefore(element, dom.nextSibling);
+	}
+	return undefined;
+};
+CertainTrust.prototype._getColor = function(certainty, trust, initf) {
+	var resultp2 = ((1 - certainty) * initf);
+	var result = (trust * certainty) + resultp2;
+	var color;
+	if (result < 0.5) {
+		color = [
+			255,
+			Math.min(255, (255 * 2 * result)),
+			0
+		];
+	} else {
+		color = [
+			Math.min(255, ((2 - (2 * result)) * 255)),
+			255,
+			0
+		];
+	}
+	return color;
+};
+CertainTrust.prototype._pointOnCircle = function(centerx, centery, pointgrade, radius) {
+	var pointrad = ((360 + pointgrade) % 360) * ((2 * Math.PI) / 360);
+	var chord = 2 * radius * Math.sin((pointrad / 2));
+	// height of our new point above the base-edge
+	var y = Math.sqrt(2
+			* (Math.pow(chord, 2) * Math.pow(radius, 2)
+				+ Math.pow(radius, 4) + Math.pow(radius, 2)
+				* Math.pow(chord, 2))
+			- (Math.pow(chord, 4) + 2 * Math.pow(radius, 4)))
+		/ (2 * radius);
+	// distance to the cross-point of base-edge and height
+	var a = Math.pow(radius, 2);
+	var c = Math.pow(y, 2);
+	// we do this to protect us from NaN cause by 1 - 1.00000004
+	var x = (a < c) ? 0 : Math.sqrt(a - c);
+
+	var directions = new Array("NE", "SE", "SW", "NW");
+	var direction = 0;
+	var alpharad = pointrad;
+	while (alpharad > (0.5 * Math.PI)) {
+		++direction;
+		alpharad -= (0.5 * Math.PI);
+	}
+	if (directions[direction] == "NE" || directions[direction] == "NW")
+		x *= -1;
+	if (directions[direction] == "SW" || directions[direction] == "NW")
+		y *= -1;
+	return new Array((centerx + x), (centery + y));
+};
+
+/* optional implementation of CertainTrust without R and S calculations */
+var CertainTrustSimple = function() {
+	this.weight = 2;
+	this.observers = [];
+
+	var offset = 0;
+	this.name = "";
+
+	if (this._isString(arguments[0])) {
+		this.name = arguments[0];
+		offset = 1;
+	}
+	if (arguments.length == 3 + offset || arguments.length == 4 + offset) {
+		// CertainTrustSimple(t, c, f, doc)
+		// doc is a 'private' parameter
+		this.t = arguments[0 + offset];
+		this.c = arguments[1 + offset];
+		this.f = arguments[2 + offset];
+		this.doc = (arguments.length == 3 + offset) ? 0 : arguments[3 + offset];
+
+		if (this.f < 0 && this.f > 1)
+			throw "f should lie within [0;1]. Entered f = " + this.f + "\n";
+		if (this.c < 0 && this.c > 1)
+			throw "c should lie within [0;1]. Entered c = " + this.c + "\n";
+		if (this.t < 0 && this.t > 1)
+			throw "t should lie within [0;1]. Entered t = " + this.t + "\n";
+	} else {
+		this.c = 0;
+		this.t = 0.5;
+		this.f = 0.5;
+		this.doc = 0;
+	}
+};
+CertainTrustSimple.prototype = new CertainTrust(1);
+CertainTrustSimple.prototype.constructor = CertainTrustSimple;
+CertainTrustSimple.prototype._operationAllowed = function() { return true; }
+CertainTrustSimple.prototype._calculateTCtoRS = function() { }
+CertainTrustSimple.prototype._calculateRStoTC = function() { }
+CertainTrustSimple.prototype._normaliseRS = function() { }
+CertainTrustSimple.prototype.setRS = undefined;
+CertainTrustSimple.prototype.addR = undefined;
+CertainTrustSimple.prototype.addS = undefined;
+CertainTrustSimple.prototype.setN = undefined;
+CertainTrustSimple.prototype.getR = undefined;
+CertainTrustSimple.prototype.getS = undefined;
+CertainTrustSimple.prototype.getN = undefined;
+CertainTrustSimple.prototype.clone = function() {
+	var copy = new CertainTrustSimple();
+	copy.c = this.c;
+	copy.t = this.t;
+	copy.f = this.f;
+	copy.doc = this.doc;
+	return copy;
+};
+
+/* From this point codes were added or modified by Debashis Chandra Ray */
+
+/* OR function for CertainTrustSimple objects*/
+CertainTrustSimple.prototype._singleOR = function(arg) {
+	var c1 = this.getC();
+	var t1 = this.getT();
+	var f1 = this.getF();
+
+	var c2 = arg.getC();
+	var t2 = arg.getT();
+	var f2 = arg.getF();
+
+	var resT = 0.5, resF = 0.5, resC = 0;
+
+	if (!this._operationAllowed(this, arg))
+		return undefined;
+
+	resF = f1 + f2 - f1*f2;
+
+	if (this._almostEqual(resF, 0))
+		resC = c1 + c2 - c1*c2;
+	else
+		resC = c1 + c2 - c1*c2 - (c1*f2*(1-c2)*(1-t1)+c2*f1*(1-c1)*(1-t2)) / resF;
+
+	if (this._almostEqual(resC, 0))
+		resT = 0.5;
+	else resT = (1/resC) * (c1*t1 + c2*t2 - c1*c2*t1*t2);
+
+	resT = this._adjustValue(resT);
+	resC = this._adjustValue(resC);
+	resF = this._adjustValue(resF);
+
+	var result = new CertainTrustSimple(resT, resC, resF, this.n, 0);
+
+	return result;
+};
+
+CertainTrustSimple.prototype.OR = function() {
+	var result = this.clone();
+	for (var i = 0; i < arguments.length; ++i) {
+		var m = arguments[i];
+		if (!this._operationAllowed(this, m))
+			continue;
+		result = result._singleOR(m);
+	}
+	return result;
+};
+
+
+/* AND function for CertainTrustSimple objects*/
+CertainTrustSimple.prototype._singlesimpleAND = function(arg){
+	var c1 = this.getC();
+	var f1 = this.getF();
+	var t1 = this.getT();
+
+	var c2 = arg.getC();
+	var f2 = arg.getF();
+	var t2 = arg.getT();
+
+	var resC = 0, resT = 0.5, resF = 0.5;
+
+	if (!this._operationAllowed(this, arg))
+		return undefined;
+
+	resF = f1*f2;
+	if (this._almostEqual(resF, 1))		//avoid division by 0
+		resC = c1 + c2 - c1*c2;
+	else
+		resC = c1 + c2 - c1*c2 - (c2*t2*(1-c1)*(1-f1)+c1*t1*(1-c2)*(1-f2)) / (1 - resF);
+
+	if (this._almostEqual(resC, 0))
+		resT = 0.5;
+	else if (this._almostEqual(resF, 1))	//avoid division by 0
+		resT = (1/resC) *  (c1*t1*c2*t2);
+	else resT = (1/resC) *  ((c1*t1*c2*t2) + (c1*f2*t1*(1-c2)*(1-f1)+c2*f1*t2*(1-c1)*(1-f2)) / (1 - resF));
+
+	resT = this._adjustValue(resT);
+	resC = this._adjustValue(resC);
+	resF = this._adjustValue(resF);
+
+	return new CertainTrustSimple(resT, resC, resF);
+};
+
+CertainTrustSimple.prototype.simpleAND = function() {
+	var result = this.clone();
+	for (var i = 0; i < arguments.length; i++) {
+		var m = arguments[i];
+		if (!this._operationAllowed(this, m))
+			continue;
+		result = result._singlesimpleAND(m);
+	}
+	return result;
+};
+
+CertainTrust.prototype.setName = function(newname) {
+	this.name = newname;
+};
+
+/**
+ * Computes CONSENSUS function for this CertainTrust object and the specified argument. Result is returned as a new object,
+ * argument and this CertainTrust object remain unchanged.
+ * N values of both objects should be equal.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @param arg - CertainTrust object
+ * @return - result of CONSENSUS computation for this object and an argument.
+ */
+CertainTrust.prototype._singleCONSENSUS = function(arg){
+	var c1 = this.getC();
+	var f1 = this.getF();
+	var t1 = this.getT();
+
+	var c2 = arg.getC();
+	var f2 = arg.getF();
+	var t2 = arg.getT();
+
+	var resC = 0, resT = 0.5, resF = 0.5;
+
+	if (!this._operationAllowed(this, arg))
+		return undefined;
+
+	//resF = f1*f2;
+	if (this._almostEqual(resF, 1))		//avoid division by 0
+		resC = (c1+c2-2*c1*c2)/(1-c1*c2);
+	else
+		resC = (c1+c2-2*c1*c2)/(1-c1*c2);
+
+	if (this._almostEqual(resC, 0))
+		resT = 0.5;
+	else if (this._almostEqual(resF, 1))	//avoid division by 0
+		resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1*(1-c2)+c2*(1-c1));
+	else resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1*(1-c2)+c2*(1-c1));
+
+	resT = this._adjustValue(resT);
+	resC = this._adjustValue(resC);
+	resF = this._adjustValue(resF);
+
+	return new CertainTrust(resT, resC, resF, this.n, 0);
+};
+
+CertainTrust.prototype.CONSENSUS = function() {
+	var result = this.clone();
+	for (var i = 0; i < arguments.length; i++) {
+		var m = arguments[i];
+		if (!this._operationAllowed(this, m))
+			continue;
+		result = result._singleCONSENSUS(m);
+	}
+	return result;
+};
+
+/**
+ * Computes DISCOUNTING function for this CertainTrust object and the specified argument. Result is returned as a new object,
+ * argument and this CertainTrust object remain unchanged.
+ * N values of both objects should be equal.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @param arg - CertainTrust object
+ * @return - result of DISCOUNTING computation for this object and an argument.
+ */
+CertainTrust.prototype._singleDISCOUNTING = function(arg){
+	var c1 = this.getC();
+	var f1 = this.getF();
+	var t1 = this.getT();
+
+	var c2 = arg.getC();
+	var f2 = arg.getF();
+	var t2 = arg.getT();
+
+	var resC = 0, resT = 0.5, resF = 0.5;
+
+	if (!this._operationAllowed(this, arg))
+		return undefined;
+
+	//resF = f1*f2;
+	if (this._almostEqual(resF, 1))		//avoid division by 0
+		resC = t1*c1*c2;
+	else
+		resC = t1*c1*c2;
+
+	if (this._almostEqual(resC, 0))
+		resT = t2;
+	else if (this._almostEqual(resF, 1))	//avoid division by 0
+		resT = t2;
+	else resT = t2;
+
+	resT = this._adjustValue(resT);
+	resC = this._adjustValue(resC);
+	resF = this._adjustValue(resF);
+
+	return new CertainTrust(resT, resC, resF, this.n, 0);
+};
+
+CertainTrust.prototype.DISCOUNTING = function() {
+	var result = this.clone();
+	for (var i = 0; i < arguments.length; i++) {
+		var m = arguments[i];
+		if (!this._operationAllowed(this, m))
+			continue;
+		result = result._singleDISCOUNTING(m);
+	}
+	return result;
+};

+ 373 - 0
JavaScript/JavaScript_Examples/Mozilla Public License Version 2.0.txt

@@ -0,0 +1,373 @@
+Mozilla Public License Version 2.0
+==================================
+
+1. Definitions
+--------------
+
+1.1. "Contributor"
+    means each individual or legal entity that creates, contributes to
+    the creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+    means the combination of the Contributions of others (if any) used
+    by a Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+    means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+    means Source Code Form to which the initial Contributor has attached
+    the notice in Exhibit A, the Executable Form of such Source Code
+    Form, and Modifications of such Source Code Form, in each case
+    including portions thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+    means
+
+    (a) that the initial Contributor has attached the notice described
+        in Exhibit B to the Covered Software; or
+
+    (b) that the Covered Software was made available under the terms of
+        version 1.1 or earlier of the License, but not also under the
+        terms of a Secondary License.
+
+1.6. "Executable Form"
+    means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+    means a work that combines Covered Software with other material, in 
+    a separate file or files, that is not Covered Software.
+
+1.8. "License"
+    means this document.
+
+1.9. "Licensable"
+    means having the right to grant, to the maximum extent possible,
+    whether at the time of the initial grant or subsequently, any and
+    all of the rights conveyed by this License.
+
+1.10. "Modifications"
+    means any of the following:
+
+    (a) any file in Source Code Form that results from an addition to,
+        deletion from, or modification of the contents of Covered
+        Software; or
+
+    (b) any new file in Source Code Form that contains any Covered
+        Software.
+
+1.11. "Patent Claims" of a Contributor
+    means any patent claim(s), including without limitation, method,
+    process, and apparatus claims, in any patent Licensable by such
+    Contributor that would be infringed, but for the grant of the
+    License, by the making, using, selling, offering for sale, having
+    made, import, or transfer of either its Contributions or its
+    Contributor Version.
+
+1.12. "Secondary License"
+    means either the GNU General Public License, Version 2.0, the GNU
+    Lesser General Public License, Version 2.1, the GNU Affero General
+    Public License, Version 3.0, or any later versions of those
+    licenses.
+
+1.13. "Source Code Form"
+    means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+    means an individual or a legal entity exercising rights under this
+    License. For legal entities, "You" includes any entity that
+    controls, is controlled by, or is under common control with You. For
+    purposes of this definition, "control" means (a) the power, direct
+    or indirect, to cause the direction or management of such entity,
+    whether by contract or otherwise, or (b) ownership of more than
+    fifty percent (50%) of the outstanding shares or beneficial
+    ownership of such entity.
+
+2. License Grants and Conditions
+--------------------------------
+
+2.1. Grants
+
+Each Contributor hereby grants You a world-wide, royalty-free,
+non-exclusive license:
+
+(a) under intellectual property rights (other than patent or trademark)
+    Licensable by such Contributor to use, reproduce, make available,
+    modify, display, perform, distribute, and otherwise exploit its
+    Contributions, either on an unmodified basis, with Modifications, or
+    as part of a Larger Work; and
+
+(b) under Patent Claims of such Contributor to make, use, sell, offer
+    for sale, have made, import, and otherwise transfer either its
+    Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+The licenses granted in Section 2.1 with respect to any Contribution
+become effective for each Contribution on the date the Contributor first
+distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+The licenses granted in this Section 2 are the only rights granted under
+this License. No additional rights or licenses will be implied from the
+distribution or licensing of Covered Software under this License.
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
+Contributor:
+
+(a) for any code that a Contributor has removed from Covered Software;
+    or
+
+(b) for infringements caused by: (i) Your and any other third party's
+    modifications of Covered Software, or (ii) the combination of its
+    Contributions with other software (except as part of its Contributor
+    Version); or
+
+(c) under Patent Claims infringed by Covered Software in the absence of
+    its Contributions.
+
+This License does not grant any rights in the trademarks, service marks,
+or logos of any Contributor (except as may be necessary to comply with
+the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+No Contributor makes additional grants as a result of Your choice to
+distribute the Covered Software under a subsequent version of this
+License (see Section 10.2) or under the terms of a Secondary License (if
+permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+Each Contributor represents that the Contributor believes its
+Contributions are its original creation(s) or it has sufficient rights
+to grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+This License is not intended to limit any rights You have under
+applicable copyright doctrines of fair use, fair dealing, or other
+equivalents.
+
+2.7. Conditions
+
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
+in Section 2.1.
+
+3. Responsibilities
+-------------------
+
+3.1. Distribution of Source Form
+
+All distribution of Covered Software in Source Code Form, including any
+Modifications that You create or to which You contribute, must be under
+the terms of this License. You must inform recipients that the Source
+Code Form of the Covered Software is governed by the terms of this
+License, and how they can obtain a copy of this License. You may not
+attempt to alter or restrict the recipients' rights in the Source Code
+Form.
+
+3.2. Distribution of Executable Form
+
+If You distribute Covered Software in Executable Form then:
+
+(a) such Covered Software must also be made available in Source Code
+    Form, as described in Section 3.1, and You must inform recipients of
+    the Executable Form how they can obtain a copy of such Source Code
+    Form by reasonable means in a timely manner, at a charge no more
+    than the cost of distribution to the recipient; and
+
+(b) You may distribute such Executable Form under the terms of this
+    License, or sublicense it under different terms, provided that the
+    license for the Executable Form does not attempt to limit or alter
+    the recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+You may create and distribute a Larger Work under terms of Your choice,
+provided that You also comply with the requirements of this License for
+the Covered Software. If the Larger Work is a combination of Covered
+Software with a work governed by one or more Secondary Licenses, and the
+Covered Software is not Incompatible With Secondary Licenses, this
+License permits You to additionally distribute such Covered Software
+under the terms of such Secondary License(s), so that the recipient of
+the Larger Work may, at their option, further distribute the Covered
+Software under the terms of either this License or such Secondary
+License(s).
+
+3.4. Notices
+
+You may not remove or alter the substance of any license notices
+(including copyright notices, patent notices, disclaimers of warranty,
+or limitations of liability) contained within the Source Code Form of
+the Covered Software, except that You may alter any license notices to
+the extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+You may choose to offer, and to charge a fee for, warranty, support,
+indemnity or liability obligations to one or more recipients of Covered
+Software. However, You may do so only on Your own behalf, and not on
+behalf of any Contributor. You must make it absolutely clear that any
+such warranty, support, indemnity, or liability obligation is offered by
+You alone, and You hereby agree to indemnify every Contributor for any
+liability incurred by such Contributor as a result of warranty, support,
+indemnity or liability terms You offer. You may include additional
+disclaimers of warranty and limitations of liability specific to any
+jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+---------------------------------------------------
+
+If it is impossible for You to comply with any of the terms of this
+License with respect to some or all of the Covered Software due to
+statute, judicial order, or regulation then You must: (a) comply with
+the terms of this License to the maximum extent possible; and (b)
+describe the limitations and the code they affect. Such description must
+be placed in a text file included with all distributions of the Covered
+Software under this License. Except to the extent prohibited by statute
+or regulation, such description must be sufficiently detailed for a
+recipient of ordinary skill to be able to understand it.
+
+5. Termination
+--------------
+
+5.1. The rights granted under this License will terminate automatically
+if You fail to comply with any of its terms. However, if You become
+compliant, then the rights granted under this License from a particular
+Contributor are reinstated (a) provisionally, unless and until such
+Contributor explicitly and finally terminates Your grants, and (b) on an
+ongoing basis, if such Contributor fails to notify You of the
+non-compliance by some reasonable means prior to 60 days after You have
+come back into compliance. Moreover, Your grants from a particular
+Contributor are reinstated on an ongoing basis if such Contributor
+notifies You of the non-compliance by some reasonable means, this is the
+first time You have received notice of non-compliance with this License
+from such Contributor, and You become compliant prior to 30 days after
+Your receipt of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+infringement claim (excluding declaratory judgment actions,
+counter-claims, and cross-claims) alleging that a Contributor Version
+directly or indirectly infringes any patent, then the rights granted to
+You by any and all Contributors for the Covered Software under Section
+2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
+end user license agreements (excluding distributors and resellers) which
+have been validly granted by You or Your distributors under this License
+prior to termination shall survive termination.
+
+************************************************************************
+*                                                                      *
+*  6. Disclaimer of Warranty                                           *
+*  -------------------------                                           *
+*                                                                      *
+*  Covered Software is provided under this License on an "as is"       *
+*  basis, without warranty of any kind, either expressed, implied, or  *
+*  statutory, including, without limitation, warranties that the       *
+*  Covered Software is free of defects, merchantable, fit for a        *
+*  particular purpose or non-infringing. The entire risk as to the     *
+*  quality and performance of the Covered Software is with You.        *
+*  Should any Covered Software prove defective in any respect, You     *
+*  (not any Contributor) assume the cost of any necessary servicing,   *
+*  repair, or correction. This disclaimer of warranty constitutes an   *
+*  essential part of this License. No use of any Covered Software is   *
+*  authorized under this License except under this disclaimer.         *
+*                                                                      *
+************************************************************************
+
+************************************************************************
+*                                                                      *
+*  7. Limitation of Liability                                          *
+*  --------------------------                                          *
+*                                                                      *
+*  Under no circumstances and under no legal theory, whether tort      *
+*  (including negligence), contract, or otherwise, shall any           *
+*  Contributor, or anyone who distributes Covered Software as          *
+*  permitted above, be liable to You for any direct, indirect,         *
+*  special, incidental, or consequential damages of any character      *
+*  including, without limitation, damages for lost profits, loss of    *
+*  goodwill, work stoppage, computer failure or malfunction, or any    *
+*  and all other commercial damages or losses, even if such party      *
+*  shall have been informed of the possibility of such damages. This   *
+*  limitation of liability shall not apply to liability for death or   *
+*  personal injury resulting from such party's negligence to the       *
+*  extent applicable law prohibits such limitation. Some               *
+*  jurisdictions do not allow the exclusion or limitation of           *
+*  incidental or consequential damages, so this exclusion and          *
+*  limitation may not apply to You.                                    *
+*                                                                      *
+************************************************************************
+
+8. Litigation
+-------------
+
+Any litigation relating to this License may be brought only in the
+courts of a jurisdiction where the defendant maintains its principal
+place of business and such litigation shall be governed by laws of that
+jurisdiction, without reference to its conflict-of-law provisions.
+Nothing in this Section shall prevent a party's ability to bring
+cross-claims or counter-claims.
+
+9. Miscellaneous
+----------------
+
+This License represents the complete agreement concerning the subject
+matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent
+necessary to make it enforceable. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+shall not be used to construe this License against a Contributor.
+
+10. Versions of the License
+---------------------------
+
+10.1. New Versions
+
+Mozilla Foundation is the license steward. Except as provided in Section
+10.3, no one other than the license steward has the right to modify or
+publish new versions of this License. Each version will be given a
+distinguishing version number.
+
+10.2. Effect of New Versions
+
+You may distribute the Covered Software under the terms of the version
+of the License under which You originally received the Covered Software,
+or under the terms of any subsequent version published by the license
+steward.
+
+10.3. Modified Versions
+
+If you create software not governed by this License, and you want to
+create a new license for such software, you may create and use a
+modified version of this License if you rename the license and remove
+any references to the name of the license steward (except to note that
+such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+Licenses
+
+If You choose to distribute Source Code Form that is Incompatible With
+Secondary Licenses under the terms of this version of the License, the
+notice described in Exhibit B of this License must be attached.
+
+Exhibit A - Source Code Form License Notice
+-------------------------------------------
+
+  This Source Code Form is subject to the terms of the Mozilla Public
+  License, v. 2.0. If a copy of the MPL was not distributed with this
+  file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular
+file, then You may include the notice in a location (such as a LICENSE
+file in a relevant directory) where a recipient would be likely to look
+for such a notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+---------------------------------------------------------
+
+  This Source Code Form is "Incompatible With Secondary Licenses", as
+  defined by the Mozilla Public License, v. 2.0.

+ 34 - 0
JavaScript/JavaScript_Examples/certainTrustHTI.css

@@ -0,0 +1,34 @@
+/**
+ * CertainTrust SDK
+ * 
+ * Implements the computational trust model "CertainTrust"
+ * in JavaScript.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ * 
+ * 
+ * Telecooperation Department, Technische Universität Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ * 
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ * 
+ * 
+ * @author	David Kalnischkies
+ * @author	Florian Volk
+ * @version	1.0
+ */
+ 
+ /* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+  
+ 
+
+.certaintrust-hti { border: 1px solid black; padding: 1em; white-space: nowrap; display: inline-block; }
+.certaintrust-hti > h1 { text-align: center; margin:0; margin-bottom: 1em; }
+.certaintrust-hti > .certaintrust-hti { border: 0; padding: 0; margin: 0; }
+.certaintrust-hti-e { margin-top: 1em; }
+.certaintrust-hti canvas { border: 1px solid black; }
+.certaintrust-hti form { float: left; margin-right: 1.5em; }
+.certaintrust-hti label { display: block; float: left; width: 7em; font-size: 1em; }
+.certaintrust-hti input { width: 4em; margin-bottom: 0.5em; }

+ 461 - 0
JavaScript/JavaScript_Examples/certainTrustHTI.js

@@ -0,0 +1,461 @@
+/**
+ * CertainTrust SDK
+ * 
+ * Implements the computational trust model "CertainTrust"
+ * in JavaScript.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ * 
+ * 
+ * Telecooperation Department, Technische Universität Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ * 
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ * 
+ * 
+ * @author	David Kalnischkies
+ * @author	Florian Volk
+ * @version	1.0
+ */
+ 
+ /* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+ 
+
+/** Certain Trust Widget
+ *
+ * Creates a color-coded graph created from an initial trust value
+ * in which the user can pick certainty (y-axis) and trust (x-axis)
+ * with the mouse in the graph.
+ *
+ * The values are displayed and can be modified inside a form
+ * while the graph in the canvas will be updated from those values.
+ *
+ * Options can be given in an object as parameter to the constructor
+ * The following keys are understood:
+ *  id is the id the top-div of the widget will get. Its used as basename for all element ids in it, too
+ *  label is an object for various messages which are shown to the user
+ *   lang is the language to use. Available are 'de' and 'en' (default)
+ *   Alternatively f, t, c and e can be used to set the text explicitly
+ *  canvas is an object containing subkeys 'width' and 'height' defining dimensions of the canvas element
+ *  line is an object defining the style of the lines building the cross to mark the chosen trust/certainty
+ *   cap is the canvas.lineCap defining the style used to smooth the end of the lines
+ *   height is the length of the line from start to the crosspoint
+ *   width is the thickness of the line
+ *   style is the color of the line
+ *  readonly can be used to disable input in the HTI as a whole,
+ *   Alternatively f, t, c, e, inputs for all of the previous and mouse can be used to disable specific elements.
+ *  show can be used to disable display of certain inputs refered to as
+ *   f, t, c, e, inputs for all of the previous, title and axes.
+ *
+ * One of the following keys can be used to specify the position of the widget in the DOM,
+ * the first defined will be used. If none is provided domAfter will be set to the <script>-tag calling
+ * the creation of the widget (= the last <script>-tag currently in the DOM)
+ * Either the DOM element itself can be given or the ID of the element as a string.
+ *  domReturn is set to true to get the DOM subtree as return value of the constructor instead [update() is NOT called]
+ *  domParent is (the id of) the parent for the widget
+ *  domBefore is (the id of) the element which the widget will be in front of
+ *  domAfter is (the id of) the element after which the widget will be inserted
+ */
+
+
+
+var CertainTrustHTI = function(certainlogic, config) {
+	if (certainlogic === undefined)
+		this.certainTrust = new CertainTrust(5);
+	else
+		this.certainTrust = certainlogic;
+
+	this.NR = CertainTrustHTIElement.length();
+	CertainTrustHTIElement.push(this);
+	this.certainTrust.addObserver(this);
+
+	// set sane defaults for config if nothing is set
+	if (config === undefined) config = {};
+	if (config.id === undefined) config.id = 'certaintrust-hti-' + this.NR;
+	// design your widget
+	if (config.canvas === undefined) config.canvas = {};
+	if (config.canvas.height === undefined) config.canvas.height = 100;
+	if (config.canvas.width === undefined) config.canvas.width = 120;
+	if (config.line === undefined) config.line = {};
+	if (config.line.cap === undefined) config.line.cap = 'round';
+	if (config.line.height === undefined) config.line.height = 5;
+	if (config.line.width === undefined) config.line.width = 1;
+	if (config.line.style === undefined) config.line.style = 'black';
+	if (config.line.baserad === undefined) config.line.baserad = 45;
+	else config.line.baserad %= 90;
+	if (config.confidence === undefined) config.confidence = {};
+	if (config.confidence.cap === undefined) config.confidence.cap = 'round';
+	if (config.confidence.height === undefined) config.confidence.height = 5;
+	if (config.confidence.width === undefined) config.confidence.width = 0;
+	if (config.confidence.style === undefined) config.confidence.style = 'gray';
+	if (config.confidence.quantil === undefined) config.confidence.quantil = 1.96;
+
+	// language settings
+	if (config.label === undefined) config.label = {};
+	if (config.label.lang === undefined) config.label.lang = 'en';
+	if (config.label.lang === 'de') {
+		if (config.label.f === undefined) config.label.f = 'Initialwert';
+		if (config.label.t === undefined) config.label.t = 'Vertrauen';
+		if (config.label.c === undefined) config.label.c = 'Sicherheit';
+		if (config.label.e === undefined) config.label.e = 'Erwartung';
+	} else {
+		if (config.label.f === undefined) config.label.f = 'Init. value';
+		if (config.label.t === undefined) config.label.t = 'Trust';
+		if (config.label.c === undefined) config.label.c = 'Certainty';
+		if (config.label.e === undefined) config.label.e = 'Expectation';
+	}
+	// readonly forms maybe?
+	var readonlyflag = false;
+	if (config.readonly === undefined) {
+		config.readonly = {};
+		config.readonly.e = true;
+	} else {
+		readonlyflag = config.readonly;
+		config.readonly = {};
+	}
+	if (config.readonly.inputs === undefined) config.readonly.inputs = readonlyflag;
+	if (config.readonly.f === undefined) config.readonly.f = config.readonly.inputs;
+	if (config.readonly.t === undefined) config.readonly.t = config.readonly.inputs;
+	if (config.readonly.c === undefined) config.readonly.c = config.readonly.inputs;
+	if (config.readonly.e === undefined) config.readonly.e = config.readonly.inputs;
+	if (config.readonly.mouse === undefined) config.readonly.mouse = readonlyflag;
+
+	// show/disable elements
+	var showflag = true;
+	if (config.show === undefined) config.show = {};
+	else {
+		showflag = config.show;
+		config.show = {};
+	}
+	if (config.show.inputs === undefined) config.show.inputs = showflag;
+	if (config.show.f === undefined) config.show.f = config.show.inputs;
+	if (config.show.t === undefined) config.show.t = config.show.inputs;
+	if (config.show.c === undefined) config.show.c = config.show.inputs;
+	if (config.show.e === undefined) config.show.e = config.show.inputs;
+	if (config.show.title === undefined) config.show.title = showflag;
+	if (config.show.axes === undefined) config.show.axes = showflag;
+
+	this.ID = config.id;
+	this.config = config;
+	var element = document.createElement('div');
+	element.setAttribute('id', this.ID);
+	element.setAttribute('class', 'certaintrust-hti');
+	if (config.show.title === true && this.certainTrust.getName().length !== 0)
+	{
+		var title = document.createElement('h1');
+		var msg = document.createTextNode(this.certainTrust.getName());
+		title.appendChild(msg);
+		element.appendChild(title);
+	}
+	var form = document.createElement('form');
+	form.setAttribute('id', this.ID + '-form');
+	var appendInput = function (form, id, nr, type, value, text, readonly, show) {
+		if (show === false)
+			return;
+		var div = document.createElement('div');
+		div.setAttribute('class', 'certaintrust-hti-' + type);
+		var label = document.createElement('label');
+		label.setAttribute('for', id + '-' + type);
+		div.appendChild(label);
+		var labeltext = document.createTextNode(text);
+		label.appendChild(labeltext);
+		var input = document.createElement('input');
+		input.setAttribute('type', 'text');
+		input.setAttribute('id', id + '-' + type);
+		var cte = CertainTrustHTIElement.ByNr(nr);
+		input.setAttribute('value', value);
+		if (readonly === true) {
+			input.setAttribute('readonly', 'readonly');
+			input.setAttribute('tabindex', '-1');
+		} else {
+			input.addEventListener('keypress', cte._onKeyPress, false);
+			input.addEventListener('blur', cte._onBlur, false);
+		}
+		div.appendChild(input);
+		form.appendChild(div);
+	};
+	appendInput(form, this.ID, this.NR, 'f', this.certainTrust.getF(), config.label.f, config.readonly.f, config.show.f);
+	appendInput(form, this.ID, this.NR, 't', this.certainTrust.getT(), config.label.t, config.readonly.t, config.show.t);
+	appendInput(form, this.ID, this.NR, 'c', this.certainTrust.getC(), config.label.c, config.readonly.c, config.show.c);
+	appendInput(form, this.ID, this.NR, 'e', this.certainTrust.getExpectation(), config.label.e, config.readonly.e, config.show.e);
+	if (form.hasChildNodes())
+		element.appendChild(form);
+
+	var hti = document.createElement('div');
+	hti.style.cssFloat=hti.style.styleFloat='left';
+	if (config.show.axes === true)
+	{
+		var yaxis = document.createElement('span');
+		yaxis.setAttribute('class', 'certaintrust-hti-yaxis');
+		yaxis.style.cssFloat=yaxis.style.styleFloat='left';
+		// width still defines the width of the box even if the
+		// element in it is rotated, so we need to set this to 1em
+		// even if the text will overflow it to have the canvas close
+		yaxis.style.width='1em';
+		// transform in theory:
+		yaxis.style.transform='rotate(270deg) translate(-4em,0em)';
+		yaxis.style.transformOrigin='100% 100%';
+		// transform in practice:
+		yaxis.style.MozTransform='rotate(270deg) translate(-4em,0em)';
+		yaxis.style.MozTransformOrigin='100% 100%';
+		yaxis.style.webkitTransform='rotate(270deg) translate(-4em,0em)';
+		yaxis.style.webkitTransformOrigin='100% 100%';
+		yaxis.style.msTransform='rotate(270deg) translate(-4em,0em)';
+		yaxis.style.msTransformOrigin='100% 100%';
+		yaxis.style.OTransform='rotate(270deg) translate(-4em,0em)';
+		yaxis.style.OTransformOrigin='100% 100%';
+		// \u00a0 is a non-breaking space, \u2192 is a right arrow
+		var yaxislabel = document.createTextNode(config.label.c + '\u00a0\u2192');
+		yaxis.appendChild(yaxislabel);
+		hti.appendChild(yaxis);
+	}
+	this.canvas = document.createElement('canvas');
+	this.canvas.style.cssFloat=this.canvas.style.styleFloat='left';
+	this.canvas.setAttribute('id', this.ID + '-canvas');
+	this.canvas.setAttribute('width', config.canvas.width);
+	this.canvas.setAttribute('height', config.canvas.height);
+//	this.canvas.setAttribute('title', this.ID); // useful to identify which widget is which
+	this.canvas.addEventListener("mousedown", this._onClick, false);
+	this.canvas.addEventListener("mousemove", this._onMove, false);
+	hti.appendChild(this.canvas);
+	if (config.show.axes === true)
+	{
+		var origin = document.createElement('span');
+		origin.style.textAlign='center';
+		origin.style.width='1em';
+		origin.style.clear='both';
+		origin.style.cssFloat=origin.style.styleFloat='left';
+		var originlabel = document.createTextNode('0');
+		origin.appendChild(originlabel);
+		hti.appendChild(origin);
+		var xaxis = document.createElement('span');
+		xaxis.style.cssFloat=xaxis.style.styleFloat='left';
+		var xaxislabel = document.createTextNode(config.label.t + '\u00a0\u2192');
+		xaxis.appendChild(xaxislabel);
+		hti.appendChild(xaxis);
+	}
+	element.appendChild(hti);
+
+	var dom = this.certainTrust._insertElement(config, element);
+	if (dom !== undefined)
+		return dom;
+
+	this.update();
+};
+
+/** (re)draws the canvas
+ *  The widget must be in the DOM tree to be able to be drawn */
+CertainTrustHTI.prototype.update = function() {
+	var ctx = this.canvas.getContext('2d');
+	var width = parseInt(this.canvas.getAttribute('width'), 10);
+	var height = parseInt(this.canvas.getAttribute('height'), 10);
+
+	var initf = this.certainTrust.getF();
+	var imageData = ctx.createImageData(width, height);
+	var d = 0;
+	for (var y = 0; y < height; ++y) {
+		var certainty = 1 - (y / height);
+		for (var x = 0; x < width; ++x) {
+			var trust = x / width;
+			var color = this.certainTrust._getColor(certainty, trust, initf);
+			// each pixel consists of four numbers: red, green, blue and alpha ranging from 0 to 255
+			imageData.data[d++] = color[0];
+			imageData.data[d++] = color[1];
+			imageData.data[d++] = color[2];
+			imageData.data[d++] = 255; // set no alpha-transparency
+		}
+	}
+	ctx.putImageData(imageData, 0, 0);
+
+	// put a 'cross' on the 'pixel' representing certainty/trust
+	var dotmiddle = Math.floor(this.config.line.width / 2);
+	var doty = Math.round(((1 - this.certainTrust.getC()) * height) - dotmiddle);
+	var dotx = Math.round((this.certainTrust.getT() * width) - dotmiddle);
+
+	// confidence interval
+	if (this.config.confidence.width !== 0) {
+		// if the line has an odd-size we have to place it on half-pixels or it looks odd
+		var middle = (this.config.confidence.width % 2 === 0) ? 0 : 0.5;
+		// calculate upper/lower bound of Wilson confidence interval
+		var K = this.config.confidence.quantil;
+		var x = this.certainTrust.getR();
+		var n = this.certainTrust.getR() + this.certainTrust.getS();
+		var p = this.certainTrust.getT();
+		var wilson = this.intervalCertainty(K, x, n, p, width);
+
+		ctx.beginPath();
+		ctx.moveTo(Math.floor(wilson.upper - dotmiddle), doty + middle - this.config.confidence.height);
+		ctx.lineTo(Math.floor(wilson.upper - dotmiddle), doty + middle + this.config.confidence.height);
+		ctx.moveTo(Math.floor(wilson.upper - dotmiddle), doty + middle);
+		ctx.lineTo(Math.floor(wilson.lower - dotmiddle), doty + middle);
+		ctx.moveTo(Math.floor(wilson.lower - dotmiddle), doty + middle - this.config.confidence.height);
+		ctx.lineTo(Math.floor(wilson.lower - dotmiddle), doty + middle + this.config.confidence.height);
+		ctx.lineWidth = this.config.confidence.width;
+		ctx.lineCap = this.config.confidence.cap;
+		ctx.strokeStyle = this.config.confidence.style;
+		ctx.stroke();
+		ctx.closePath();
+	}
+
+	// if the line has an odd-size we have to place it on half-pixels or it looks odd
+	var middle = (this.config.line.width % 2 === 0) ? 0 : 0.5;
+	var line1 = new Array(
+		this.certainTrust._pointOnCircle(dotx, doty + middle, (this.config.line.baserad + 0), this.config.line.height),
+		this.certainTrust._pointOnCircle(dotx, doty + middle, (this.config.line.baserad + 180), this.config.line.height)
+	);
+	var line2 = new Array(
+		this.certainTrust._pointOnCircle(dotx, doty + middle, (this.config.line.baserad + 90), this.config.line.height),
+		this.certainTrust._pointOnCircle(dotx, doty + middle, (this.config.line.baserad + 270), this.config.line.height)
+	);
+
+	ctx.beginPath();
+	ctx.moveTo(Math.round(line1[0][0]) + middle, Math.round(line1[0][1]) + middle);
+	ctx.lineTo(Math.round(line1[1][0]) + middle, Math.round(line1[1][1]) + middle);
+	ctx.moveTo(Math.round(line2[0][0]) + middle, Math.round(line2[0][1]) + middle);
+	ctx.lineTo(Math.round(line2[1][0]) + middle, Math.round(line2[1][1]) + middle);
+	ctx.lineWidth = this.config.line.width;
+	ctx.lineCap = this.config.line.cap;
+	ctx.strokeStyle = this.config.line.style;
+	ctx.stroke();
+	ctx.closePath();
+
+	// display the certainTrust values in a user-friendly way without modifying their internal state
+	this._setElementValue(this.ID + '-f', this.certainTrust.getF());
+	this._setElementValue(this.ID + '-c', this.certainTrust.getC());
+	this._setElementValue(this.ID + '-t', this.certainTrust.getT());
+	this._setElementValue(this.ID + '-e', this.certainTrust.getExpectation());
+};
+CertainTrustHTI.prototype._setElementValue = function(id, value) {
+	var element = document.getElementById(id);
+	if (element === null)
+		return;
+	element.value = this._formatNumber(value);
+};
+
+/** calculating Wilson/Goldman interval boundaries */
+CertainTrustHTI.prototype.intervalCertainty = function(K, x, n, p, width) {
+	var K2 = Math.pow(K, 2);
+	var nK2 = n + K2;
+	var part1 = (x + (K2 / 2)) / nK2;
+	var part2 = (K * Math.sqrt(n)) / nK2;
+	var part3 = Math.sqrt(p * (1 - p) + (K2 / (4 * n)));
+	var uwx = (part1 + part2 * part3) * width;
+	var lwx = (part1 - part2 * part3) * width;
+	return { upper: uwx, lower: lwx };
+};
+
+CertainTrustHTI.prototype._onMove = function(e) {
+	if (CertainTrustHTIElement._isMouseDown !== true)
+		return;
+	var cte = CertainTrustHTIElement.ByCanvas(this);
+	if (cte.config.readonly.mouse === true)
+		return;
+	cte._onClick(e, this);
+};
+
+CertainTrustHTI.prototype._onClick = function(e, clkcanvas) {
+	// if it's called by onMove this is not the clicked canvas but the element, so we have to pass it on
+	if (clkcanvas === undefined)
+		clkcanvas = this;
+
+	var cte = CertainTrustHTIElement.ByCanvas(clkcanvas);
+	if (cte.config.readonly.mouse === true)
+		return;
+	// this could be the start of a drag across the canvas
+	CertainTrustHTIElement._isMouseDown = true;
+
+	// convert screen-relative coordinates to canvas-relatives to trust/certainty and limit these values to [0;1]
+	var x = e.clientX;
+	var y = e.clientY;
+	// https://developer.mozilla.org/en-US/docs/Web/API/element.getBoundingClientRect
+	var ctBounding = clkcanvas.getBoundingClientRect();
+	var cx = ctBounding.left;
+	var cy = ctBounding.top;
+	var newT = Math.max(0, Math.min(1, (x - cx) / clkcanvas.width));
+	var newC = Math.max(0, Math.min(1, 1 - ((y - cy) / clkcanvas.height)));
+	cte.certainTrust.setTC(newT, newC);
+};
+
+CertainTrustHTI.prototype._onKeyPress = function(e) {
+	if (e.keyCode != 13)
+		return;
+
+	// update values only in case the user pressed the return key
+	var cid = this.id.substring(0, this.id.lastIndexOf('-'));
+	var cte = CertainTrustHTIElement.ById(cid);
+	cte._updateInput(this.id);
+};
+
+CertainTrustHTI.prototype._onBlur = function(e) {
+	// update values if focus left the input field
+	var cid = this.id.substring(0, this.id.lastIndexOf('-'));
+	var cte = CertainTrustHTIElement.ById(cid);
+	cte._updateInput(this.id);
+};
+
+CertainTrustHTI.prototype._updateInput = function(id) {
+	// this is the input-element the key was pressed in - thankfully the id for
+	// these input fields are autogenerated from the id of the widget
+	var cid = id.substring(0, id.lastIndexOf('-'));
+	if (id.substring(id.lastIndexOf('-')) === '-f') {
+		var newF = this._normalizeInput(document.getElementById(cid + '-f').value);
+		this.certainTrust.setF((isNaN(newF)) ? this.certainTrust.getF() : newF);
+	} else { // if ( == '-c' || == '-t')
+		var newT = this._normalizeInput(document.getElementById(cid + '-t').value);
+		var newC = this._normalizeInput(document.getElementById(cid + '-c').value);
+		this.certainTrust.setTC(
+			(isNaN(newT)) ? this.certainTrust.getT() : newT,
+			(isNaN(newC)) ? this.certainTrust.getC() : newC
+		);
+	}
+};
+
+// parse the user-input to a number (best attempt approach)
+CertainTrustHTI.prototype._normalizeInput = function(input) {
+	// first, replace the first "," with "." to enable German-language style floating point input
+	var rawInput = (input+"").replace(/,/, ".");
+	// now, strip out all leading 0s to prevent parseFloat from treating the input as octal
+	rawInput = rawInput.replace(/^0+\./, ".");
+
+	// convert to a number
+	var floatInput = parseFloat(rawInput); // attention, this may be NaN -> _updateInput handles this
+	if ((1 < floatInput) || (0 > floatInput)) {
+		return NaN;
+	} else {
+		return floatInput;
+	}
+};
+
+// rounds numbers to at most 3 decimal places
+CertainTrustHTI.prototype._formatNumber = function(number) {
+	// return number.toFixed(3);
+	return Math.round(number * 1000) / 1000;
+};
+
+// global var for storing and accessing all the widgets
+var CertainTrustHTIElement = { _elements: [],
+	_isMouseDown: false,
+	ByCanvas: function(canvas) {
+		for (var i = 0; i < CertainTrustHTIElement._elements.length; ++i) {
+			if (CertainTrustHTIElement._elements[i].canvas === canvas)
+				return CertainTrustHTIElement._elements[i];
+		}
+		return null;
+	},
+	ById: function(id) {
+		for (var i = 0; i < CertainTrustHTIElement._elements.length; ++i) {
+			if (CertainTrustHTIElement._elements[i].ID === id)
+				return CertainTrustHTIElement._elements[i];
+		}
+		return null;
+	},
+	ByNr: function(nr) { return CertainTrustHTIElement._elements[nr]; },
+	push: function(cte) { CertainTrustHTIElement._elements.push(cte); },
+	length: function() { return CertainTrustHTIElement._elements.length; }
+
+};
+
+// react on every mouseup - even outside of a canvas
+document.addEventListener("mouseup", function() { CertainTrustHTIElement._isMouseDown = false; }, false);

+ 38 - 0
JavaScript/JavaScript_Examples/certainTrustTViz.css

@@ -0,0 +1,38 @@
+/**
+ * CertainTrust SDK
+ *
+ * Implements the computational trust model "CertainTrust"
+ * in JavaScript.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ *
+ *
+ * Telecooperation Department, Technische Universität Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ *
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ *
+ *
+ * @author	David Kalnischkies
+ * @version	1.0
+ */
+
+ /* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+.certaintrust-tviz-axes line {
+	shape-rendering: crispedges;
+}
+.certaintrust-tviz-axis-right text {
+	text-anchor: start;
+	stroke-width: 0;
+}
+.certaintrust-tviz-axis-left text {
+	text-anchor: end;
+	stroke-width: 0;
+}
+.certaintrust-tviz-arcs path:hover {
+	stroke: skyblue;
+	stroke-width: 3;
+}

+ 328 - 0
JavaScript/JavaScript_Examples/certainTrustTViz.js

@@ -0,0 +1,328 @@
+/**
+ * CertainTrust SDK
+ *
+ * Implements the computational trust model "CertainTrust"
+ * in JavaScript.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ *
+ *
+ * Telecooperation Department, Technische Universität Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ *
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ *
+ *
+ * @author	Daniel Dieth
+ * @author	David Kalnischkies
+ * @author	Maria Pelevina
+ * @version	1.0
+ */
+
+ /* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+//##########################################################################################
+// CertainTrustTViz constructor
+//##########################################################################################
+var CertainTrustTViz = function(data, config) {
+	this.NR = CertainTrustTVizElement.length();
+	CertainTrustTVizElement.push(this);
+	this.certainTrusts = [];
+	this.add(data);
+
+	// set sane defaults for config if nothing is set
+	if (config === undefined) config = {};
+	if (config.id === undefined) config.id = 'certaintrust-tviz-' + this.NR;
+	// design your widget
+	if (config.canvas === undefined) config.canvas = {};
+	if (config.canvas.height === undefined) config.canvas.height = 440;
+	if (config.canvas.width === undefined) config.canvas.width = 440;
+	if (config.canvas.inner === undefined) config.canvas.inner = 30;
+	if (config.middle === undefined) config.middle = 'AVERAGE';
+	if (config.onClick === undefined) config.onClick = undefined;
+
+	this.ID = config.id;
+	this.config = config;
+
+	var element = document.createElement('div');
+	element.setAttribute('id', this.ID);
+	var dom = this.certainTrusts[0]._insertElement(config, element);
+
+	this.update();
+
+	if (dom !== undefined)
+		return dom;
+};
+CertainTrustTViz.prototype.update = function() {
+	var xmlns = 'http://www.w3.org/2000/svg';
+	var dotx = this.config.canvas.height / 2;
+	var doty = this.config.canvas.width / 2;
+	var rotate = 360 - 45;
+	var circle_y = this.config.canvas.inner;
+	var circle_height = dotx - (2 * circle_y);
+	var rotationstep = 360 / this.certainTrusts.length;
+
+	var element = document.getElementById(this.ID);
+
+	// see if we have to redraw thanks to an added/removed CertainTrust element
+	if (element.hasChildNodes() === true) {
+		var old_arcs = document.getElementById(this.ID + '-arcs');
+		if (old_arcs.childNodes.length !== this.certainTrusts.length)
+			element.removeChild(element.firstChild);
+	}
+
+	var arcs = document.createElementNS(xmlns, 'g');
+	arcs.setAttribute('stroke', 'none');
+	arcs.setAttribute('class', 'certaintrust-tviz-arcs');
+	arcs.setAttribute('id', this.ID + '-arcs');
+
+	// first time run or removed by the if above: full build
+	if (element.hasChildNodes() === false)
+	{
+		// prepare the various elements we need
+		var axes = document.createElementNS(xmlns, 'g');
+		axes.setAttribute('fill', 'none');
+		axes.setAttribute('stroke', 'grey');
+		axes.setAttribute('class', 'certaintrust-tviz-axes');
+		var desc = document.createElementNS(xmlns, 'g');
+		for (var a = 0; a < this.certainTrusts.length; ++a) {
+			var rotation = (rotate + (rotationstep * a)) % 360;
+			// an axis for each arc to show of how big each arc could be
+			var axis = this._generateAxis(xmlns, dotx, doty, circle_height, circle_y, rotation);
+			axes.appendChild(axis);
+			// the arc representing the CertainTrust element
+			var arc = this._generateArc(xmlns, this.certainTrusts[a], dotx, doty, circle_height, circle_y, rotation, rotationstep);
+			arcs.appendChild(arc);
+			// label for each arc
+			var label = this._generateArcLabel(xmlns, this.certainTrusts[a], dotx, doty, circle_height, circle_y, rotation, rotationstep);
+			desc.appendChild(label);
+		}
+		if (this.config.middle !== 'NONE') {
+			var total = this._generateTotalInTheMiddle(xmlns, dotx, doty);
+			desc.appendChild(total);
+		}
+		// draw circles to indicate how large the arcs could be
+		var circles = this._generateCircles(xmlns, circle_y, circle_height);
+		// our new tviz
+		var svg = document.createElementNS(xmlns, 'svg');
+		svg.setAttribute('height', this.config.canvas.height);
+		svg.setAttribute('width', this.config.canvas.width);
+		svg.appendChild(circles);
+		svg.appendChild(arcs);
+		svg.appendChild(axes);
+		svg.appendChild(desc);
+		// finally, insert tviz
+		element.appendChild(svg);
+	} else {
+		// we have most of the image, so just change what has changed
+		element = element.firstChild;
+		// get the new arcs set
+		for (var a = 0; a < this.certainTrusts.length; ++a) {
+			var rotation = (rotate + (rotationstep * a)) % 360;
+			var arc = this._generateArc(xmlns, this.certainTrusts[a], dotx, doty, circle_height, circle_y, rotation, rotationstep);
+			arcs.appendChild(arc);
+		}
+		// find the old arcs set and exchange it with the new set
+		var old_arcs = document.getElementById(this.ID + '-arcs');
+		element.insertBefore(arcs, old_arcs);
+		element.removeChild(old_arcs);
+		if (this.config.middle !== 'NONE') {
+			// and now change the text of label in the middle
+			var total = document.getElementById(this.ID + '-middle');
+			total.firstChild.nodeValue = this._calcMiddleLabel(this.certainTrusts);
+		}
+	}
+};
+CertainTrustTViz.prototype.add = function() {
+	for (var i = 0; i < arguments.length; ++i) {
+		var ct = arguments[i];
+		if (ct instanceof Array) {
+			for (var j = 0; j < ct.length; ++j) {
+				var c = ct[j];
+				this.certainTrusts.push(c);
+				c.addObserver(this);
+			}
+		} else {
+			this.certainTrusts.push(ct);
+			ct.addObserver(this);
+		}
+	}
+	// don't trigger on first call from constructor
+	if (this.ID !== undefined)
+		this.update();
+};
+CertainTrustTViz.prototype.remove = function() {
+	for (var i = 0; i < arguments.length; ++i) {
+		var ct = arguments[i];
+		if (ct instanceof CertainTrust) {
+			for (var j = 0; j < ct.length; ++j) {
+				for (var k = 0; k < this.certainTrusts.length; ++k) {
+					if (this.certainTrusts[k] !== ct[j])
+						continue;
+					ct[j].deleteObserver(this);
+					this.certainTrusts.splice(k, 1);
+					break;
+				}
+			}
+		} else {
+			for (var k = 0; k < this.certainTrusts.length; ++k) {
+				if (this.certainTrusts[k].getName() !== ct)
+					continue;
+				this.certainTrusts[k].deleteObserver(this);
+				this.certainTrusts.splice(k, 1);
+				break;
+			}
+		}
+	}
+	this.update();
+};
+CertainTrustTViz.prototype._generateAxis = function(xmlns, dotx, doty, circle_height, circle_y, rotation) {
+		var point = this.certainTrusts[0]._pointOnCircle(dotx, doty, rotation, circle_y);
+		var axis = document.createElementNS(xmlns, 'g');
+		axis.setAttribute('fill', 'none');
+		axis.setAttribute('stroke', 'grey');
+		var placement;
+		if (rotation >= 270 && rotation < 360 || rotation >= 0 && rotation < 90) {
+			axis.setAttribute('transform', 'translate(' + point[1] + ',' + point[0] + ') rotate(' + (rotation) + ')');
+			axis.setAttribute('class', 'certaintrust-tviz-axis-left');
+			placement = -1;
+		} else {
+			axis.setAttribute('transform', 'translate(' + point[1] + ',' + point[0] + ') rotate(' + (rotation - 180) + ')');
+			axis.setAttribute('class', 'certaintrust-tviz-axis-right');
+			placement = 1;
+		}
+		var axis_line = document.createElementNS(xmlns, 'line');
+		axis_line.setAttribute('fill', 'inherit');
+		axis_line.setAttribute('stroke', 'inherit');
+		axis_line.setAttribute('x1', 0);
+		axis_line.setAttribute('y1', 0);
+		axis_line.setAttribute('x2', 0);
+		axis_line.setAttribute('y2', placement * circle_height);
+		axis.appendChild(axis_line);
+		for (var t = 0; t < 6; ++t) {
+			var y = placement * (circle_height * (t / 5));
+			var tick_line = document.createElementNS(xmlns, 'line');
+			tick_line.setAttribute('fill', 'inherit');
+			tick_line.setAttribute('stroke', 'inherit');
+			tick_line.setAttribute('x1', 0);
+			tick_line.setAttribute('y1', y);
+			tick_line.setAttribute('x2', placement * 6);
+			tick_line.setAttribute('y2', y);
+			var tick_text = document.createElementNS(xmlns, 'text');
+			tick_text.setAttribute('fill', 'grey');
+			tick_text.setAttribute('x', placement * 9);
+			tick_text.setAttribute('y', y);
+			tick_text.setAttribute('dy', '.5em');
+			tick_text.setAttribute('font-size', '.5em');
+			var msg = document.createTextNode(t * 20);
+			tick_text.appendChild(msg);
+			var tick = document.createElementNS(xmlns, 'g');
+			tick.setAttribute('fill', 'inherit');
+			tick.setAttribute('stroke', 'inherit');
+			tick.appendChild(tick_line);
+			tick.appendChild(tick_text);
+			axis.appendChild(tick);
+		}
+	return axis;
+};
+CertainTrustTViz.prototype._generateArc = function(xmlns, certainTrust, dotx, doty, circle_height, circle_y, rotation, rotationstep) {
+	var arc_width = rotationstep * certainTrust.getC();
+	var arc_free = (rotationstep - arc_width) / 2;
+	var arc_low_left = certainTrust._pointOnCircle(dotx, doty, (rotation + arc_free), circle_y);
+	var arc_low_right = certainTrust._pointOnCircle(dotx, doty, (rotation + rotationstep - arc_free), circle_y);
+	var arc_height = (circle_height * certainTrust.getT()) + circle_y;
+	var arc_high_left = certainTrust._pointOnCircle(dotx, doty, (rotation + arc_free), arc_height);
+	var arc_high_right = certainTrust._pointOnCircle(dotx, doty, (rotation + rotationstep - arc_free), arc_height);
+	var color = certainTrust._getColor(certainTrust.getC(), certainTrust.getT(), certainTrust.getF());
+	var arc = document.createElementNS(xmlns, 'path');
+	arc.setAttribute('fill', 'rgb(' + Math.round(color[0]) + ',' + Math.round(color[1]) + ',' + Math.round(color[2]) + ')');
+	arc.setAttribute('stroke', 'inherit');
+	arc.setAttribute('d', 'M' + arc_low_left[1] + ' ' + arc_low_left[0] +
+		'A' + circle_y + ',' + circle_y + ' 0 0,1 ' + arc_low_right[1] + ',' + arc_low_right[0] +
+		'L' + arc_high_right[1] + ' ' + arc_high_right[0] +
+		'A' + arc_height + ',' + arc_height + ' 0 0,0 ' + arc_high_left[1] + ',' + arc_high_left[0] +
+		'z');
+	arc.setAttribute('title', 'Trust: ' + certainTrust.getT() + '\nCertainty: ' + certainTrust.getC());
+
+	if (this.config.onClick !== undefined)
+	{
+		var onClick = this.config.onClick;
+		arc.addEventListener("click", function(e) { onClick(certainTrust); }, false);
+	}
+	return arc;
+};
+CertainTrustTViz.prototype._generateArcLabel = function(xmlns, certainTrust, dotx, doty, circle_height, circle_y, rotation, rotationstep) {
+	var label = document.createElementNS(xmlns, 'text');
+	label.setAttribute('fill', 'black');
+	var outerpoint = this.certainTrusts[0]._pointOnCircle(dotx, doty, (rotation + (rotationstep / 2)), (circle_height + circle_y));
+	label.setAttribute('x', outerpoint[1]);
+	label.setAttribute('y', outerpoint[0]);
+	label.setAttribute('dy', '.5em');
+	label.setAttribute('text-anchor', 'middle');
+	var msg = document.createTextNode(certainTrust.getName());
+	label.appendChild(msg);
+	return label;
+};
+CertainTrustTViz.prototype._generateTotalInTheMiddle = function(xmlns, dotx, doty) {
+	var total = document.createElementNS(xmlns, 'text');
+	total.setAttribute('fill', 'grey');
+	total.setAttribute('x', dotx);
+	total.setAttribute('y', doty);
+	total.setAttribute('dy', '.5em');
+	total.setAttribute('text-anchor', 'middle');
+	total.setAttribute('id', this.ID + '-middle');
+	var msg = document.createTextNode(this._calcMiddleLabel(this.certainTrusts));
+	total.appendChild(msg);
+	return total;
+};
+CertainTrustTViz.prototype._generateCircles = function(xmlns, circle_y, circle_height) {
+	var circles = document.createElementNS(xmlns, 'g');
+	circles.setAttribute('fill', 'none');
+	circles.setAttribute('stroke', 'lightgrey');
+	circles.setAttribute('class', 'certaintrust-tviz-circles');
+	for (var i = 0; i < 11; ++i) {
+		var circle = document.createElementNS(xmlns, 'circle');
+		circle.setAttribute('cx', '50%');
+		circle.setAttribute('cy', '50%');
+		var r = circle_y + (circle_height * (i / 10));
+		circle.setAttribute('r', r);
+		circle.setAttribute('fill', 'inherit');
+		circle.setAttribute('stroke', 'inherit');
+		circles.appendChild(circle);
+	}
+	return circles;
+};
+// Calculate the average over all included CertainTrusts
+CertainTrustTViz.prototype._calcMiddleLabel = function(indata) {
+	if (this.config.middle === "NONE")
+		return "";
+	else if (this.config.middle === "AVERAGE") {
+		var avg = 0.0;
+		for (var i = 0; i < indata.length; i++) {
+			avg += indata[i].getExpectation();
+		}
+		return (Math.round(avg/indata.length*1000)/10) + "%";
+	} else if (this.config.middle === "AND") {
+		var result = indata[0];
+		for (var i = 1; i < indata.length; i++) {
+			result = result.AND(indata[i]);
+		}
+		return (Math.round(result.getExpectation()*1000)/10) + "%";
+	} else
+		return this.config.middle(indata);
+};
+// global var for storing and accessing all the widgets
+var CertainTrustTVizElement = { _elements: [],
+	ById: function(id) {
+		for (var i = 0; i < CertainTrustTVizElement._elements.length; ++i) {
+			if (CertainTrustTVizElement._elements[i].ID === id)
+				return CertainTrustTVizElement._elements[i];
+		}
+		return null;
+	},
+	ByNr: function(nr) { return CertainTrustTVizElement._elements[nr]; },
+	push: function(cte) { CertainTrustTVizElement._elements.push(cte); },
+	length: function() { return CertainTrustTVizElement._elements.length; }
+};

+ 59 - 0
JavaScript/JavaScript_Examples/consensus_operator.html

@@ -0,0 +1,59 @@
+<html>
+<head>
+	<title>Consensus Operator</title>
+	<script type="text/javascript" src="CertainTrust.js"></script>
+	<script type="text/javascript" src="certainTrustHTI.js"></script>
+	<link rel="stylesheet" type="text/css" href="certainTrustHTI.css"/>
+	<script type="text/javascript" src="certainTrustTViz.js"></script>
+	<link rel="stylesheet" type="text/css" href="certainTrustTViz.css" />
+</head>
+<body>
+	Operand 1 : <br>
+	<label for="">t1: </label><input type="textbox" name="t1"></input>
+	<label for="">c1: </label><input type="textbox" name="c1"></input>
+	<label for="">f1: </label><input type="textbox" name="f1"></input><br><br>
+	Operand 2 : <br>
+	<label for="">t2: </label><input type="textbox" name="t2"></input>
+	<label for="">c2: </label><input type="textbox" name="c2"></input>
+	<label for="">f2: </label><input type="textbox" name="f2"></input><br><br>
+	
+	<button onClick="calculateConsensus()">Execute</button><br><br><br>
+	
+	<div id = "obj1">
+	</div>
+	<div id = "obj2">
+	</div>
+	<div id = "con">
+	</div>
+	<div id = "dis">
+	</div>
+	
+	<script type="text/javascript">
+		function calculateConsensus() {
+			var t1 = parseFloat(document.getElementsByName('t1')[0].value);
+			var c1 = parseFloat(document.getElementsByName('c1')[0].value);
+			var f1 = parseFloat(document.getElementsByName('f1')[0].value);
+			
+			var t2 = parseFloat(document.getElementsByName('t2')[0].value);
+			var c2 = parseFloat(document.getElementsByName('c2')[0].value);
+			var f2 = parseFloat(document.getElementsByName('f2')[0].value);
+			
+			var ctObject1 = new CertainTrust(t1,c1,f1,50);
+			var ctObject2 = new CertainTrust(t2,c2,f2,50);
+			
+			var ctResult1 = ctObject1.CONSENSUS(ctObject2);
+			var ctResult2 = ctObject1.DISCOUNTING(ctObject2);
+			
+			document.getElementById("obj1").innerHTML="Operand 1 : ";
+			var HTI1 = new CertainTrustHTI(ctObject1,{domParent: obj1, canvas:{height: 100, width: 125}, readonly:true});
+			document.getElementById("obj2").innerHTML="Operand 2 : ";
+			var HTI2 = new CertainTrustHTI(ctObject2,{domParent: obj2, canvas:{height: 100, width: 125}, readonly:true});
+			document.getElementById("con").innerHTML="Consensus : ";
+			var HTI3 = new CertainTrustHTI(ctResult1,{domParent: con, canvas:{height: 100, width: 125}, readonly:true});
+			document.getElementById("dis").innerHTML="Discounting : ";
+			var HTI4 = new CertainTrustHTI(ctResult2,{domParent: dis, canvas:{height: 100, width: 125}, readonly:true});
+			
+		}
+	</script>
+</body>
+</html>

+ 78 - 0
JavaScript/JavaScript_Examples/demoTViz.html

@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+	<head>
+		<title>T-Viz (Trust Visualisation)</title>
+		<script type="text/javascript" src="CertainTrust.js"></script>
+		<script type="text/javascript" src="certainTrustTViz.js"></script>
+		<link rel="stylesheet" type="text/css" href="certainTrustTViz.css" />
+
+		<script type="text/javascript" src="certainTrustHTI.js"></script>
+		<link rel="stylesheet" type="text/css" href="certainTrustHTI.css" />
+
+		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+		<style>
+#certaintrust-tviz-2, #certaintrust-tviz-3  {
+	float: left;
+}
+		</style>
+	</head>
+	<body>
+		<h1>T-Viz (Trust Visualisation)</h1>
+		<div id="mytest"></div>
+		<script type="text/javascript">
+var allcts = [
+	[
+		new CertainTrustSimple("Lage", 0.139, 0.943, 0.1),
+		new CertainTrustSimple("Essen", 0.8, 0.4, 0.75)
+	], [
+		new CertainTrust("A", 0.7, 0.5, 0.1, 5),
+		new CertainTrust("B", 0.4, 0.8, 0.75, 5),
+		new CertainTrust("C", 0.1, 0.1, 0.55, 5),
+		new CertainTrust("D", 0.6, 0.4, 0.25, 5),
+		new CertainTrust("E", 0.9, 0.1, 0.50, 5),
+		new CertainTrust("F", 0.1, 0.9, 0.10, 5),
+/*
+		new CertainTrust("G", 0.7, 0.5, 0.1, 5),
+		new CertainTrust("H", 0.4, 0.8, 0.75, 5),
+		new CertainTrust("I", 0.1, 0.1, 0.95, 5),
+		new CertainTrust("J", 0.6, 0.4, 0.25, 5),
+		new CertainTrust("K", 0.9, 0.1, 0.50, 5),
+		new CertainTrust("L", 0.5, 0.9, 0.10, 5),
+		new CertainTrust("M", 0.7, 0.5, 0.1, 5),
+		new CertainTrust("N", 0.4, 0.8, 0.75, 5),
+		new CertainTrust("O", 0.9, 0.9, 0.95, 5),
+		new CertainTrust("P", 0.6, 0.4, 0.25, 5),
+		new CertainTrust("Q", 0.9, 0.7, 0.50, 5),
+		new CertainTrust("R", 0.3, 0.6, 0.10, 5),
+		new CertainTrust("S", 0.7, 0.5, 0.1, 5),
+		new CertainTrust("T", 0.4, 0.8, 0.75, 5),
+		new CertainTrust("U", 0.1, 0.1, 0.55, 5),
+		new CertainTrust("V", 0.6, 0.6, 0.25, 5),
+		new CertainTrust("W", 0.9, 0.3, 0.50, 5),
+		new CertainTrust("X", 0.6, 0.9, 0.70, 5),
+		new CertainTrust("Y", 0.7, 0.5, 0.1, 5),
+		new CertainTrust("Z", 0.4, 0.8, 0.75, 5),
+//*/
+	]
+];
+// beware, reversed order!
+new CertainTrustTViz(allcts[1], { canvas: { height: 200, width: 200 }, middle: 'AND' });
+new CertainTrustTViz(allcts[0], { canvas: { height: 200, width: 200 }, middle: 'NONE' });
+new CertainTrustTViz(allcts[1]);
+new CertainTrustTViz(allcts[0], { middle: function(indata) { return (indata[0].getExpectation() < 0.5) ? ":(" : ":)"; },
+	onClick: function(certainTrust) {
+		if (certainTrust.getName() === "Lage") document.location = 'https://en.wikipedia.org/wiki/Location_%28geography%29';
+		else if (certainTrust.getName() === "Essen") alert("Anything is good if it's made of chocolate.");
+	} });
+		</script>
+		<div style="clear:both;"></div>
+		<script type="text/javascript">
+new CertainTrustHTI(allcts[1][5]);
+new CertainTrustHTI(allcts[0][1]);
+new CertainTrustHTI(allcts[0][0]);
+		</script>
+<a href="javascript:CertainTrustTVizElement.ByNr(3).add(new CertainTrust('Trinken', 0.5, 0.8, 0.6, 10));">ADD Trinken</a>
+<a href="javascript:CertainTrustTVizElement.ByNr(3).remove('Trinken');">DEL Trinken</a>
+	</body>
+</html>

+ 110 - 0
JavaScript/JavaScript_Examples/demonstrator.html

@@ -0,0 +1,110 @@
+<!DOCTYPE html>
+<html>
+<!--
+CertainTrust Demonstrator in JavaScript
+
+Demonstrates some capabilities of the CertainTrust SDK
+using a Java applet that interactively calculates
+AND and OR of two CertainTrust data objects and
+visually displays both the input objects and the output.
+
+@author	Florian Volk <florian.volk@cased.de>
+-->
+<head>
+	<meta charset="utf-8" />
+	<title>CertainTrust Demonstrator in JavaScript</title>
+	<style type="text/css">
+		h1, p, td:nth-child(2n) { text-align: center; }
+		table { margin: 50px 0; }
+	</style>
+
+	<!-- include these two scripts and the CSS to enable both CertainTrust and the HTI -->
+	<script type="text/javascript" src="CertainTrust.js"></script>
+	<script type="text/javascript" src="certainTrustHTI.js"></script>
+	<link rel="stylesheet" type="text/css" href="certainTrustHTI.css"/>
+
+</head>
+<body>
+	<h1>Demonstrator for CertainTrust</h1>
+	<p>CertainTrust provides a means for the evaluation of propositional logic terms under uncertainty.</p>
+
+	<table>
+		<!-- Demonstrator for CertainTrust.AND -->
+		<tr>
+			<td id="and-operand1"></td>
+			<td>AND</td>
+			<td id="and-operand2"></td>
+			<td>=</td>
+			<td id="and-result"></td>
+		</tr>
+		<!-- Demonstrator for CertainTrust.OR -->
+		<tr>
+			<td id="or-operand1"></td>
+			<td>OR</td>
+			<td id="or-operand2"></td>
+			<td>=</td>
+			<td id="or-result"></td>
+		</tr>
+	</table>
+
+	<script type="text/javascript">
+		// create an Array to hold the CertainTrust objects
+		var CT_objects = [];
+		var N = 10;
+
+		var CT_names = ['and-operand1', 'and-operand2', 'and-result',
+										'or-operand1', 'or-operand2', 'or-result'];
+
+		// ANDObserver is used for the AND calculation
+		var ANDObserver = {
+			update: function() {
+				// calculate the CertainTrust.AND for both values
+				var CT_result = CT_objects['and-operand1'].AND(CT_objects['and-operand2']);
+
+				// update the HTI which displays the result
+				CT_objects['and-result'].setF(CT_result.getF());
+				CT_objects['and-result'].setTC(CT_result.getT(), CT_result.getC());
+			}
+		};
+
+		// ORObserver is used for the OR calculation
+		var ORObserver = {
+			update: function() {
+				// calculate the CertainTrust.OR for both values
+				var CT_result = CT_objects['or-operand1'].OR(CT_objects['or-operand2']);
+
+				// update the HTI which displays the result
+				CT_objects['or-result'].setF(CT_result.getF());
+				CT_objects['or-result'].setTC(CT_result.getT(), CT_result.getC());
+			}
+		};
+
+		// create the CertainTrust objects and the associated HTIs
+		for (var i = 0, element; element = CT_names[i]; ++i) {
+			var CT_object = new CertainTrust(N);
+
+			// the result HTIs should be read-only
+			var isResultHTI = (-1 !== element.indexOf('-result'));
+			var HTI = new CertainTrustHTI(CT_object, {domParent: element, readonly: isResultHTI});
+
+			// register our observers for the calculation
+			if (!isResultHTI) {
+				var isOR = (0 === element.indexOf('or-'));
+				CT_object.addObserver((isOR) ? ORObserver : ANDObserver);
+			}
+
+			// store the created objects for easy access in the Arrays
+			CT_objects[element] = CT_object;
+		}
+
+		// trigger initial update to the result HTIs
+		ANDObserver.update();
+		ORObserver.update();
+	</script>
+
+	<p>
+		<img src="logo_tudarmstadt.png" alt="Technische Universität Darmstadt" width="176" height="73" />
+		<img src="logo_softwarecluster.png" alt="Software-Cluster" width="212" height="73" />
+	</p>
+</body>
+</html>

+ 100 - 0
JavaScript/JavaScript_Examples/demonstrator_cfusion.html

@@ -0,0 +1,100 @@
+<!DOCTYPE html>
+<html>
+<!--
+CertainTrust Demonstrator in JavaScript
+
+Demonstrates some capabilities of the CertainTrust SDK
+using a Java applet that interactively calculates
+AND and OR of two CertainTrust data objects and
+visually displays both the input objects and the output.
+
+@author	Florian Volk <florian.volk@cased.de>
+-->
+<head>
+	<meta charset="utf-8" />
+	<title>CertainTrust Demonstrator in JavaScript</title>
+	<style type="text/css">
+		h1, p, td:nth-child(2n) { text-align: center; }
+		table { margin: 50px 0; }
+	</style>
+
+	<!-- include these two scripts and the CSS to enable both CertainTrust and the HTI -->
+	<script type="text/javascript" src="CertainTrust.js"></script>
+	<script type="text/javascript" src="certainTrustHTI.js"></script>
+	<link rel="stylesheet" type="text/css" href="certainTrustHTI.css"/>
+
+</head>
+<body>
+	<h1>Demonstrator for CertainTrust</h1>
+	<p>CertainTrust provides a means for the evaluation of propositional logic terms under uncertainty.</p>
+
+	<table>
+		<!-- Demonstrator for CertainTrust.cFusion -->
+		<tr>
+			<td id="cf-operand1"></td>
+			<td>cFusion</td>
+			<td id="cf-operand2"></td>
+			<td>=</td>
+			<td id="cf-result"></td>
+		</tr>
+		
+	</table>
+
+	<script type="text/javascript">
+		// create an Array to hold the CertainTrust objects
+		var CT_objects = [];
+		var N = 10;
+
+		var CT_names = ['cf-operand1','cf-operand2','cf-result'];
+
+			
+		// CFObserver is used for the conflicted fusion (cFusion) calculation
+		var CFObserver = {
+			update: function() {
+				var fusTmp = new CertainTrust(5);
+				var weight = [1,1];
+				var fusArray = [];
+				fusArray.push(CT_objects['cf-operand1']);
+				fusArray.push(CT_objects['cf-operand2']);
+				
+				//cFusion operation
+				var CT_result = fusTmp.cFusion(fusArray,weight);
+				
+				// update the HTI which displays the result
+				CT_objects['cf-result'].setF(CT_result.getF());
+				CT_objects['cf-result'].setTC(CT_result.getT(), CT_result.getC());
+			}
+		};
+		
+		
+		// create the CertainTrust objects and the associated HTIs
+		for (var i = 0, element; element = CT_names[i]; ++i) {
+			var CT_object = new CertainTrust(N);
+
+			// the result HTIs should be read-only
+			var isResultHTI = (-1 !== element.indexOf('-result'));
+			var HTI = new CertainTrustHTI(CT_object, {domParent: element, readonly: isResultHTI});
+
+			// register our observers for the calculation
+			if (!isResultHTI) {
+				var isCF = (0 === element.indexOf('cf-'));
+				if(isCF){
+					CT_object.addObserver(CFObserver);
+				}
+				
+			}
+
+			// store the created objects for easy access in the Arrays
+			CT_objects[element] = CT_object;
+		}
+
+		// trigger initial update to the result HTIs
+		CFObserver.update();
+	</script>
+
+	<p>
+		<img src="logo_tudarmstadt.png" alt="Technische Universität Darmstadt" width="176" height="73" />
+		<img src="logo_softwarecluster.png" alt="Software-Cluster" width="212" height="73" />
+	</p>
+</body>
+</html>

+ 185 - 0
JavaScript/JavaScript_Examples/demonstrator_updated.html

@@ -0,0 +1,185 @@
+<!DOCTYPE html>
+<html>
+<!--
+CertainTrust Demonstrator in JavaScript
+
+Demonstrates some capabilities of the CertainTrust SDK
+using a Java applet that interactively calculates
+AND and OR of two CertainTrust data objects and
+visually displays both the input objects and the output.
+
+@author	Florian Volk <florian.volk@cased.de>
+-->
+<head>
+	<meta charset="utf-8" />
+	<title>CertainTrust Demonstrator in JavaScript</title>
+	<style type="text/css">
+		h1, p, td:nth-child(2n) { text-align: center; }
+		table { margin: 50px 0; }
+	</style>
+
+	<!-- include these two scripts and the CSS to enable both CertainTrust and the HTI -->
+	<script type="text/javascript" src="CertainTrust.js"></script>
+	<script type="text/javascript" src="certainTrustHTI.js"></script>
+	<link rel="stylesheet" type="text/css" href="certainTrustHTI.css"/>
+
+</head>
+<body>
+	<h1>Demonstrator for CertainTrust</h1>
+	<p>CertainTrust provides a means for the evaluation of propositional logic terms under uncertainty.</p>
+
+	<table>
+		<!-- Demonstrator for CertainTrust.AND -->
+		<tr>
+			<td id="and-operand1"></td>
+			<td>AND</td>
+			<td id="and-operand2"></td>
+			<td>=</td>
+			<td id="and-result"></td>
+		</tr>
+		<!-- Demonstrator for CertainTrust.OR -->
+		<tr>
+			<td id="or-operand1"></td>
+			<td>OR</td>
+			<td id="or-operand2"></td>
+			<td>=</td>
+			<td id="or-result"></td>
+		</tr>
+		<!-- Demonstrator for CertainTrust.cFusion -->
+		<tr>
+			<td id="cf-operand1"></td>
+			<td>cFusion</td>
+			<td id="cf-operand2"></td>
+			<td>=</td>
+			<td id="cf-result"></td>
+		</tr>
+		<!-- Demonstrator for CertainTrust.wFusion -->
+		<tr>
+			<td id="wf-operand1"></td>
+			<td>wFusion</td>
+			<td id="wf-operand2"></td>
+			<td>=</td>
+			<td id="wf-result"></td>
+		</tr>
+	</table>
+
+	<script type="text/javascript">
+		// create an Array to hold the CertainTrust objects
+		var CT_objects = [];
+		var N = 10;
+		var cweight = [1,1]; 
+        var wweight = [1,1];
+		var doc = 0.2;
+		var CT_names = ['and-operand1', 'and-operand2', 'and-result',
+										'or-operand1', 'or-operand2', 'or-result',
+										'cf-operand1','cf-operand2','cf-result',
+										'wf-operand1','wf-operand2','wf-result'];
+
+		// ANDObserver is used for the AND calculation
+		var ANDObserver = {
+			update: function() {
+				// calculate the CertainTrust.AND for both values
+				var CT_result = CT_objects['and-operand1'].AND(CT_objects['and-operand2']);
+
+				// update the HTI which displays the result
+				CT_objects['and-result'].setF(CT_result.getF());
+				CT_objects['and-result'].setTC(CT_result.getT(), CT_result.getC());
+			}
+		};
+
+		// ORObserver is used for the OR calculation
+		var ORObserver = {
+			update: function() {
+				// calculate the CertainTrust.OR for both values
+				var CT_result = CT_objects['or-operand1'].OR(CT_objects['or-operand2']);
+
+				// update the HTI which displays the result
+				CT_objects['or-result'].setF(CT_result.getF());
+				CT_objects['or-result'].setTC(CT_result.getT(), CT_result.getC());
+			}
+		};
+		
+		// CFObserver is used for the conflicted fusion (cFusion) calculation
+		var CFObserver = {
+			update: function() {
+				var fusTmp = new CertainTrust(5);
+				
+				var fusArray = [];
+				fusArray.push(CT_objects['cf-operand1']);
+				fusArray.push(CT_objects['cf-operand2']);
+				
+				//cFusion operation
+				var CT_result = fusTmp.cFusion(fusArray,cweight);
+				doc = CT_result.getDoC();
+				
+				// update the HTI which displays the result
+				CT_objects['cf-result'].setF(CT_result.getF());
+				CT_objects['cf-result'].setTC(CT_result.getT(), CT_result.getC());
+			}
+		};
+		
+		// WFObserver is used for the weighted fusion (wFusion) calculation
+		var WFObserver = {
+			update: function() {
+				var fusTmp = new CertainTrust(5);
+				
+				var fusArray = [];
+				fusArray.push(CT_objects['wf-operand1']);
+				fusArray.push(CT_objects['wf-operand2']);
+				
+				//cFusion operation
+				var CT_result = fusTmp.wFusion(fusArray,wweight);
+				
+				// update the HTI which displays the result
+				CT_objects['wf-result'].setF(CT_result.getF());
+				CT_objects['wf-result'].setTC(CT_result.getT(), CT_result.getC());
+			}
+		};
+
+		// create the CertainTrust objects and the associated HTIs
+		for (var i = 0, element; element = CT_names[i]; ++i) {
+			var CT_object = new CertainTrust(N);
+
+			// the result HTIs should be read-only
+			var isResultHTI = (-1 !== element.indexOf('-result'));
+			var HTI = new CertainTrustHTI(CT_object, {domParent: element, readonly: isResultHTI});
+
+			// register our observers for the calculation
+			if (!isResultHTI) {
+				var isOR = (0 === element.indexOf('or-'));
+				var isAND = (0 === element.indexOf('and-'));
+				var isCF = (0 === element.indexOf('cf-'));
+				var isWF = (0 === element.indexOf('wf-'));
+				
+				if(isOR){
+					CT_object.addObserver(ORObserver);
+				}
+				else if(isAND){
+					CT_object.addObserver(ANDObserver);
+				}
+				else if(isCF){
+					CT_object.addObserver(CFObserver);
+				}
+				else{
+					CT_object.addObserver(WFObserver);
+				}
+			}
+
+			// store the created objects for easy access in the Arrays
+			CT_objects[element] = CT_object;
+		}
+
+		// trigger initial update to the result HTIs
+		ANDObserver.update();
+		ORObserver.update();
+		CFObserver.update();
+		WFObserver.update();
+		document.write("Degree of Conflict (Doc) for cFusion = " + doc );
+	</script>
+
+	<p>
+		<img src="logo_tudarmstadt.png" alt="Technische Universität Darmstadt" width="176" height="73" />
+		<img src="logo_softwarecluster.png" alt="Software-Cluster" width="212" height="73" />
+	</p>
+</body>
+</html>

+ 142 - 0
JavaScript/JavaScript_Examples/demonstrator_updated_test.html

@@ -0,0 +1,142 @@
+<!DOCTYPE html>
+<html>
+<!--
+CertainTrust Demonstrator in JavaScript
+
+Demonstrates some capabilities of the CertainTrust SDK
+using a Java applet that interactively calculates
+AND and OR of two CertainTrust data objects and
+visually displays both the input objects and the output.
+
+@author	Florian Volk <florian.volk@cased.de>
+-->
+<head>
+	<meta charset="utf-8" />
+	<title>CertainTrust Demonstrator in JavaScript</title>
+	<style type="text/css">
+		h1, p, td:nth-child(2n) { text-align: center; }
+		table { margin: 50px 0; }
+	</style>
+
+	<!-- include these two scripts and the CSS to enable both CertainTrust and the HTI -->
+	<script type="text/javascript" src="CertainTrust.js"></script>
+	<script type="text/javascript" src="certainTrustHTI.js"></script>
+	<link rel="stylesheet" type="text/css" href="certainTrustHTI.css"/>
+
+</head>
+<body>
+	<h1>Demonstrator for CertainTrust</h1>
+	<p>CertainTrust provides a means for the evaluation of propositional logic terms under uncertainty.</p>
+
+	<table>
+		<!-- Demonstrator for CertainTrust.AND -->
+		<tr>
+			<td id="and-operand1"></td>
+			<td>AND</td>
+			<td id="and-operand2"></td>
+			<td>=</td>
+			<td id="and-result"></td>
+		</tr>
+		<!-- Demonstrator for CertainTrust.OR -->
+		<tr>
+			<td id="or-operand1"></td>
+			<td>OR</td>
+			<td id="or-operand2"></td>
+			<td>=</td>
+			<td id="or-result"></td>
+		</tr>
+		<!-- Demonstrator for CertainTrust.cFusion -->
+		<tr>
+			<td id="cf-operand1"></td>
+			<td>cFusion</td>
+			<td id="cf-operand2"></td>
+			<td>=</td>
+			<td id="cf-result"></td>
+		</tr>
+		<!-- Demonstrator for CertainTrust.wFusion -->
+		<tr>
+			<td id="wf-operand1"></td>
+			<td>wFusion</td>
+			<td id="wf-operand2"></td>
+			<td>=</td>
+			<td id="wf-result"></td>
+		</tr>
+	</table>
+
+	<script type="text/javascript">
+		// create an Array to hold the CertainTrust objects
+		var CT_objects = [];
+		var N = 10;
+		var cweight = [1,1]; 
+        var wweight = [1,1];
+		var doc = 0.2;
+		var CT_names = ['and-operand1', 'and-operand2', 'and-result',
+										'or-operand1', 'or-operand2', 'or-result',
+										'cf-operand1','cf-operand2','cf-result',
+										'wf-operand1','wf-operand2','wf-result'];
+
+		// ANDObserver is used for the AND calculation
+		var ANDObserver = {
+			update: function() {
+				// calculate the CertainTrust.AND for both values
+				var CT_result = CT_objects['and-operand1'].AND(CT_objects['and-operand2']);
+
+				// update the HTI which displays the result
+				CT_objects['and-result'].setF(CT_result.getF());
+				CT_objects['and-result'].setTC(CT_result.getT(), CT_result.getC());
+			}
+		};
+
+		// ORObserver is used for the OR calculation
+		var ORObserver = {
+			update: function() {
+				// calculate the CertainTrust.OR for both values
+				var CT_result = CT_objects['or-operand1'].OR(CT_objects['or-operand2']);
+
+				// update the HTI which displays the result
+				CT_objects['or-result'].setF(CT_result.getF());
+				CT_objects['or-result'].setTC(CT_result.getT(), CT_result.getC());
+			}
+		};
+		
+
+		// create the CertainTrust objects and the associated HTIs
+		for (var i = 0, element; element = CT_names[i]; ++i) {
+			var CT_object = new CertainTrustSimple(N);
+
+			// the result HTIs should be read-only
+			var isResultHTI = (-1 !== element.indexOf('-result'));
+			var HTI = new CertainTrustHTI(CT_object, {domParent: element, readonly: isResultHTI});
+
+			// register our observers for the calculation
+			if (!isResultHTI) {
+				var isOR = (0 === element.indexOf('or-'));
+				var isAND = (0 === element.indexOf('and-'));
+				var isCF = (0 === element.indexOf('cf-'));
+				var isWF = (0 === element.indexOf('wf-'));
+				
+				if(isOR){
+					CT_object.addObserver(ORObserver);
+				}
+				else {
+					CT_object.addObserver(ANDObserver);
+				}
+			}
+
+			// store the created objects for easy access in the Arrays
+			CT_objects[element] = CT_object;
+		}
+
+		// trigger initial update to the result HTIs
+		ANDObserver.update();
+		ORObserver.update();
+		
+		
+	</script>
+
+	<p>
+		<img src="logo_tudarmstadt.png" alt="Technische Universität Darmstadt" width="176" height="73" />
+		<img src="logo_softwarecluster.png" alt="Software-Cluster" width="212" height="73" />
+	</p>
+</body>
+</html>

+ 110 - 0
JavaScript/JavaScript_Examples/evidences.html

@@ -0,0 +1,110 @@
+<!DOCTYPE html>
+<html>
+<!--
+CertainTrust Demonstrator in JavaScript
+
+Demonstrates Trust Evidences in CertainTrust with a Visualization using the HTI.
+
+@author	Florian Volk <florian.volk@cased.de>
+-->
+<head>
+	<meta charset="utf-8" />
+	<title>CertainTrust Demonstrator in JavaScript</title>
+	<style type="text/css">
+		h1, p { text-align: center; }
+		button#AddR_Button, button#AddS_Button, button#SetN_Button { float: right; margin-left: 1em; }
+		div#userControls { float:left; margin-right: 2em; }
+	</style>
+
+	<!-- include these two scripts and the CSS to enable both CertainTrust and the HTI -->
+	<script type="text/javascript" src="CertainTrust.js"></script>
+	<script type="text/javascript" src="certainTrustHTI.js"></script>
+	<link rel="stylesheet" type="text/css" href="certainTrustHTI.css"/>
+
+</head>
+<body>
+	<h1>Trust Visualization with the HTI</h1>
+	<p>Visualization of Trust Updates with CertainTrust and the Human Trust Interface</p>
+
+	<div style="margin:0 auto;width:800px;">
+		<!-- user controls -->
+		<div id="userControls">
+			<div>
+				Positive&nbsp;experiences:&nbsp;<span id="R_Label">0</span>
+				<button id="AddR_Button" onclick="AddR_ButtonClick();">Add</button>
+			</div>
+			<div style="clear:both">
+				Negative&nbsp;experiences:&nbsp;<span id="S_Label">0</span>
+				<button id="AddS_Button" onclick="AddS_ButtonClick();">Add</button>
+			</div>
+			<div style="margin-top: 1em;">
+				<label for="N_Input">Expected amount of evidence:</label>
+				<input id="N_Input" style="width: 4em;" />
+				<button id="SetN_Button" onclick="SetN_ButtonClick();">Set</button>
+			</div>
+			<div style="clear:both">
+				<button id="Reset_Button" onclick="Reset_ButtonClick();">Reset</button>
+			</div>
+		</div>
+		<!-- HTI -->
+		<script type="text/javascript">
+			// initialize expected amount of evidence with 100
+			var N = 100;
+
+			// instanciate the CertainTrust and Human Trust Interface objects
+			var ctObject = new CertainTrust(N);
+			var hti = new CertainTrustHTI(ctObject);
+		</script>
+		<!-- connect controls with HTI -->
+		<script type="text/javascript">
+			document.getElementById("N_Input").value = "" + N;
+
+			// LocalObserver is used to update information on the amount of experiences
+			// after the user modified the HTI manually
+			var LocalObserver = {
+				update: function() {
+					_updateLabel("R_Label", ctObject.getR());
+					_updateLabel("S_Label", ctObject.getS());
+				}
+			}
+			ctObject.addObserver(LocalObserver);
+
+			function Reset_ButtonClick() {
+				// reset all internal state of the opinion, set N to last known number
+				ctObject.setN(N);
+				ctObject.setRS(0,0);
+			}
+
+			function SetN_ButtonClick() {
+				// change amount of expected evidence
+				var newN = parseInt(document.getElementById("N_Input").value);
+				if (!isNaN(newN)) {
+					N = newN;
+					ctObject.setN(N);
+				}
+			}
+
+			function AddR_ButtonClick() {
+				// add a positive experience
+				ctObject.addR(1);
+			}
+
+			function AddS_ButtonClick() {
+				// add a negative experience
+				ctObject.addS(1);
+			}
+
+			function _updateLabel(id, value) {
+				// helper function to nicely format amount of experiences that were made
+				document.getElementById(id).innerHTML = "" + Math.round(value * 100) / 100;
+			}
+		</script>
+	</div>
+
+	<br/>
+	<p>
+		<img src="logo_tudarmstadt.png" alt="Technische Universität Darmstadt" width="176" height="73" />
+		<img src="logo_softwarecluster.png" alt="Software-Cluster" width="212" height="73" />
+	</p>
+</body>
+</html>

+ 58 - 0
JavaScript/JavaScript_Examples/index.html

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+	<head>
+		<title>Certain Trust</title>
+		<script type="text/javascript" src="CertainTrust.js"></script>
+		<script type="text/javascript" src="certainTrustHTI.js"></script>
+		<link rel="stylesheet" type="text/css" href="certainTrustHTI.css" />
+		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+	</head>
+	<body style="border: 5px solid grey;">
+<script type="text/javascript">new CertainTrustHTI(new CertainTrust(0.5, 0.5, 0.5, 10), {
+	line: {
+		height: 5,
+		width: 1,
+		style: 'black',
+		baserad: 45
+	},
+	confidence: {
+		width: 1,
+		style: 'gray',
+		quantil: 1.96
+	}
+});</script>
+		<div id="dom-parent" >
+		<script type="text/javascript">var ct = new CertainTrustHTI(new CertainTrust("DOM Parent", 0.1, 0, 0.9, 5), { domParent: 'dom-parent', label: { lang: 'de' } , readonly: true });</script>
+			<table style="clear: both;" id="dom-before">
+				<tr><td id='parent-td'></td><td><script type="text/javascript">new CertainTrustHTI();</script></td></tr>
+				<tr><td><script type="text/javascript">new CertainTrustHTI();</script></td><td><script type="text/javascript">new CertainTrustHTI();</script></td></tr>
+			</table>
+			<script type="text/javascript">new CertainTrustHTI(new CertainTrust("Deutsch", 0.5, 0, 0.1, 5), { label: { lang: 'de' } });</script>
+			<script type="text/javascript">new CertainTrustHTI(new CertainTrust("No Fields", 0.8, 0, 0.75, 5), { show: { c: false, e: false, f: false, t: false, axes: false } });</script>
+			<script type="text/javascript">new CertainTrustHTI(new CertainTrustSimple("Bigger is better", 0.5, 0.5, 0.4), { canvas: { width: 400, height: 400 } });</script>
+			<script type="text/javascript">new CertainTrustHTI(undefined, { line: { height: 10, width: 3 } });</script>
+			<script type="text/javascript">new CertainTrustHTI(new CertainTrust(0.0, 0.0, 10));</script>
+			<div class="certaintrust"><h2>Default HTI</h2><script type="text/javascript">new CertainTrustHTI();</script></div>
+		</div>
+		<script type="text/javascript">new CertainTrustHTI(new CertainTrust(0.5, 0.5, 0.5, 5), { id: 'ct-parent', domParent: 'parent-td', line: { baserad: 45 }, confidence: { width: 1 } });</script>
+		<script type="text/javascript">new CertainTrustHTI(undefined, { id: 'ct-after', domAfter: 'dom-before', line: { baserad: 45, width: 2 } });</script>
+		<script type="text/javascript">new CertainTrustHTI(undefined, { id: 'ct-before', domBefore: 'dom-before' });</script>
+		<script type="text/javascript">document.getElementById('dom-parent').appendChild(new CertainTrustHTI(undefined, { id: 'ct-return', domReturn: true }));CertainTrustHTIElement.ById('ct-return').update()</script>
+		<script type="text/javascript">new CertainTrustHTI(undefined, { id: 'ct-element', domBefore: document.getElementById('dom-parent') });</script>
+
+
+		<p>Adding the neutral element changes nothing:<br/>
+		<script type="text/javascript">
+			var ct = new CertainTrustSimple(0.5, 0.5, 0);
+			var nct = ct.AND(new CertainTrustSimple(0.5, 0.5, 1));
+			document.write(ct.getF() + " " + ct.getC() + " " + ct.getT() + "<br/>");
+			document.write(nct.getF() + " " + nct.getC() + " " + nct.getT() + "<br/>");
+			var fct = ct.cFusion([ ct, nct ], [ 1, 1 ]);
+			document.write(fct.getF() + " " + fct.getC() + " " + fct.getT() + "<br/>");
+			var nct = ct.NOT();
+			document.write(nct.getF() + " " + nct.getC() + " " + nct.getT() + "<br/>");
+		</script>
+		</p>
+	</body>
+</html>

BIN
JavaScript/JavaScript_Examples/logo_softwarecluster.png


BIN
JavaScript/JavaScript_Examples/logo_tudarmstadt.png


+ 41 - 0
JavaScript/JavaScript_Examples/minimal.html

@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<!--
+Minimal CertainTrust Demonstrator in JavaScript
+
+Demonstrates the basic usage of the CertainTrust SDK.
+
+@author	Florian Volk <florian.volk@cased.de>
+-->
+<head>
+	<meta charset="utf-8" />
+	<title>CertainTrust Demonstrator in JavaScript</title>
+
+	<!-- include these two scripts and the CSS to enable both CertainTrust and the HTI -->
+	<script type="text/javascript" src="CertainTrust.js"></script>
+	<script type="text/javascript" src="certainTrustHTI.js"></script>
+	<link rel="stylesheet" type="text/css" href="certainTrustHTI.css"/>
+
+</head>
+<body>
+	<script type="text/javascript">
+		var ctObject = new CertainTrust(10);
+		var hti = new CertainTrustHTI(ctObject);
+
+		function showValues() {
+			alert("Values of the CertainTrust object:\n"
+				+ "\nInit. value:\t"	+ ctObject.getF()
+				+ "\nTrust:\t"				+ ctObject.getT()
+				+ "\nCertainty:\t"		+ ctObject.getC()
+				+ "\nExpectation:\t"	+ ctObject.getExpectation());
+		}
+	</script>
+	<br />
+	<button type="button" onclick="showValues();">Read CertainTrust values</button>
+
+	<p>
+		<img src="logo_tudarmstadt.png" alt="Technische Universität Darmstadt" width="176" height="73" />
+		<img src="logo_softwarecluster.png" alt="Software-Cluster" width="212" height="73" />
+	</p>
+</body>
+</html>

+ 217 - 0
JavaScript/JavaScript_Examples/multinomial.html

@@ -0,0 +1,217 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="utf-8" />
+	<title>CertainTrust with Multinomial Opinion Representation</title>
+
+	<script type="text/javascript" src="CertainTrust.js"></script>
+	<script type="text/javascript" src="certainTrustHTI.js"></script>
+	<link rel="stylesheet" type="text/css" href="certainTrustHTI.css"/>
+	<style type="text/css">
+body {
+	text-align: center;
+}
+table {
+	margin-left:auto;
+	margin-right:auto;
+}
+th:after {
+	content: ":";
+}
+tr#splitpoints > th:after {
+	content: "";
+}
+tr#frequentist-mles > td:after, tr#posterior-mles > td:after {
+	content: " %";
+}
+input {
+	width: 5em;
+}
+
+ul#graph {
+	position: relative;
+	margin-left: auto;
+	margin-right: auto;
+	padding: 0;
+}
+
+ul#graph li {
+	border: 1px solid #000;
+	bottom: 0;
+	list-style:none;
+	margin: 0;
+	padding: 0;
+	position: absolute;
+	text-align: center;
+}
+
+	</style>
+</head>
+<body>
+<script type="text/javascript">
+var ctObject = new CertainTrust(50);
+var hti = new CertainTrustHTI(ctObject, { readonly: true, confidence: { width: 1 }  } );
+
+var CATEGORIES = new Array(1, 5, 14, 8, 4);
+var PRIORS = new Array(1, 1, 1, 1, 1);
+var DEFAULT_CATEGORY = 4;
+var GRAPH_HEIGHT = 300;
+var GRAPH_BAR_WIDTH = 60;
+
+if (CATEGORIES.length !== PRIORS.length)
+	alert("Count of Categories and Prior do not match! Expect bogus output…");
+
+function _experiencesChangedKeyPress(e) {
+	if (e.keyCode != 13)
+		return;
+	_experiencesChangedBlur();
+}
+function _experiencesChangedBlur() {
+	var split = _findSplitPoint();
+	_betaAlphaRangeChanged(split);
+}
+
+function _findSplitPoint() {
+	var splits = document.getElementsByName('splitpoints');
+	for (var i = 0; i < splits.length; ++i)
+		if (splits[i].checked == true)
+			return i;
+	return DEFAULT_CATEGORY - 1;
+}
+
+// rounds numbers to at most 3 decimal places
+function _formatNumber(number) {
+	return Math.round(number * 1000) / 1000;
+}
+
+function _betaAlphaRangeChanged(split) {
+	// calculate amount of positive and negative experiences and a maximum
+	var alpha = 0, beta = 0, maxv = 0;
+	for (var i = 0; i < split; ++i) {
+		var v = parseInt(document.getElementById('experience-' + i).value);
+		var p = parseFloat(document.getElementById('prior-' + i).value);
+		beta += v;
+		maxv = Math.max(v + p, maxv);
+	}
+	for (var i = split; i < CATEGORIES.length; ++i) {
+		var v = parseInt(document.getElementById('experience-' + i).value);
+		var p = parseFloat(document.getElementById('prior-' + i).value);
+		alpha += v;
+		maxv = Math.max(v + p, maxv);
+	}
+	// update HTI
+	ctObject.setRS(alpha, beta);
+	// delete the current bar chart
+	var graph = document.getElementById('graph');
+	graph.setAttribute('style', 'height: ' + GRAPH_HEIGHT + 'px;width: ' + (GRAPH_BAR_WIDTH * CATEGORIES.length) + 'px;');
+	while (graph.lastChild !== null)
+		graph.removeChild(graph.lastChild);
+
+	var all = alpha + beta;
+	++maxv;
+	var scale = GRAPH_HEIGHT / maxv;
+
+	// add up all priors
+	var postall = all;
+	for (var i = 0; i < PRIORS.length; ++i)
+		postall += PRIORS[i];
+
+	for (var i = 0; i < CATEGORIES.length; ++i) {
+		var a = parseInt(document.getElementById('experience-' + i).value);
+		var prior = parseFloat(document.getElementById('prior-' + i).value);
+		// calculate and set the three table fields
+		var freq = (100 * a) / all;
+		document.getElementById('frequentist-mle-' + i).firstChild.nodeValue = _formatNumber(freq);
+		var post = (100 * (a + prior)) / postall;
+		document.getElementById('posterior-mle-' + i).firstChild.nodeValue = _formatNumber(post);
+		var K = 7.87; // FIXME: Magic number
+		var n = all;
+		var p = a/n;
+		var goodman = hti.intervalCertainty(K, a, n, p, 1);
+		var estimate = 1 - (goodman.upper - goodman.lower);
+		document.getElementById('certainty-' + i).firstChild.nodeValue = _formatNumber(estimate);
+
+		// draw the bar chart
+		var element = document.createTextNode(_formatNumber(estimate));
+		var bar = document.createElement('li');
+		bar.appendChild(element);
+		var grey = document.createElement('li');
+		var styling = 'left: ' + (i * GRAPH_BAR_WIDTH) + 'px;';
+		styling += 'width: ' + (GRAPH_BAR_WIDTH - 1) + 'px;';
+		grey.setAttribute('style', styling + 'background-color: grey;height: ' + Math.round(scale * prior) + 'px;');
+		styling += 'height: ' + Math.round(scale * (a + prior)) + 'px;';
+		// gradient is from red → yellow → green (adding green → substracting red)
+		var colorpos = Math.round(((255 * 2) / (CATEGORIES.length - 1)) * i);
+		if (colorpos < 255)
+			styling += 'background-color: rgb(255, ' + colorpos + ', 0);';
+		else
+			styling += 'background-color: rgb(' + (510 - colorpos) + ', 255, 0);';
+		bar.setAttribute('style', styling);
+		graph.appendChild(bar);
+		graph.appendChild(grey);
+	}
+}
+
+function _categorySplitClicked() {
+	_betaAlphaRangeChanged(parseInt(this.value));
+}
+</script>
+<div><ul id="graph"></ul></div>
+<table>
+<tr id="frequentist-mles"><th>Frequentist MLE</th></tr>
+<tr id="posterior-mles"><th>Posterior MLE</th></tr>
+<tr id="certainties"><th>Certainty</th></tr>
+<tr id="experiences"><th>Experience</th></tr>
+<tr id="priors"><th>Prior</th></tr>
+<tr id="splitpoints"><th>&gt;=</th></tr>
+</table>
+
+<script>
+function _addCell(id, element) {
+	var cell = document.createElement('td');
+	cell.appendChild(element);
+	document.getElementById(id).appendChild(cell);
+}
+
+function _addTextCell(id, textid, value) {
+	var element = document.createTextNode(value);
+	var cell = document.createElement('td');
+	cell.setAttribute('id', textid);
+	cell.appendChild(element);
+	document.getElementById(id).appendChild(cell);
+}
+
+function _addInput(parentid, base, nr, value) {
+	var input = document.createElement('input');
+	input.setAttribute('type', 'text');
+	input.setAttribute('id', base + '-' + nr);
+	input.setAttribute('value', value);
+	input.addEventListener('keypress', _experiencesChangedKeyPress, false);
+	input.addEventListener('blur', _experiencesChangedBlur, false);
+	_addCell(parentid, input);
+}
+
+for (var i = 0; i < CATEGORIES.length; ++i) {
+	_addTextCell('frequentist-mles', 'frequentist-mle-' + i, '0');
+	_addTextCell('posterior-mles', 'posterior-mle-' + i, '0');
+	_addTextCell('certainties', 'certainty-' + i, '0.0');
+
+	_addInput('experiences', 'experience', i, CATEGORIES[i]);
+	_addInput('priors', 'prior', i, PRIORS[i]);
+
+	var splitpoint = document.createElement('input');
+	splitpoint.setAttribute('type', 'radio');
+	splitpoint.setAttribute('id', 'splitpoint-' + i);
+	splitpoint.setAttribute('name', 'splitpoints');
+	splitpoint.setAttribute('value', i);
+	splitpoint.addEventListener('click', _categorySplitClicked, false);
+	_addCell('splitpoints', splitpoint);
+}
+document.getElementById('splitpoint-' + (DEFAULT_CATEGORY - 1)).setAttribute('checked', 'checked');
+</script>
+<div>
+
+</div>
+<script>_betaAlphaRangeChanged(_findSplitPoint());</script>
+</body>
+</html>

+ 935 - 0
JavaScript/JavaScript_SDK/CertainTrust.js

@@ -0,0 +1,935 @@
+/**
+ * CertainTrust SDK
+ *
+ * Implements the computational trust model "CertainTrust"
+ * in JavaScript.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ *
+ *
+ * Telecooperation Department, Technische Universität Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ *
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ *
+ *
+ * @author	Maria Pelevina
+ * @author	David Kalnischkies
+ * @version	1.1
+ */
+ 
+ /* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+ 
+
+/**
+ * Available Constructors:
+ * - CertainTrust(t, c, f, n)
+ * - CertainTrust(r, s, n)
+ * - CertainTrust(n)
+ * optionally arguments can be preceded by name, e.g. CertainTrust(name, r, s, n)
+ *
+ * t - average rating value, [0; 1], from very negative to very positive
+ * c - certainty value, [0; 1] from low certainty (no evidence) to the maximal maximal certainty.
+ * f - initial trust value
+ * w - weight
+ * r - number of positive evidence
+ * s - number of negative evidence
+ * n - maximal number of expected evidence
+ */
+
+var CertainTrust = function() {
+	this.weight = 2;
+	this.observers = [];
+
+	var offset = 0;
+	this.name = "";
+
+	if (this._isString(arguments[0])) {
+		this.name = arguments[0];
+		offset = 1;
+	}
+	if (arguments.length == 4 + offset || arguments.length == 5 + offset) {
+		// CertainTrust(t, c, f, n, doc)
+		// doc is a 'private' parameter
+		this.t = arguments[0 + offset];
+		this.c = arguments[1 + offset];
+		this.f = arguments[2 + offset];
+		this.n = arguments[3 + offset];
+		this.doc = (arguments.length == 4 + offset) ? 0 : arguments[4 + offset];
+		this.r = 0;
+		this.s = 0;
+
+		if (this.n <= 0)
+			throw "N should be greater than 0. Entered n = " + this.n + "\n";
+		if (this.f < 0 && this.f > 1)
+			throw "f should lie within [0;1]. Entered f = " + this.f + "\n";
+		if (this.c < 0 && this.c > 1)
+			throw "c should lie within [0;1]. Entered c = " + this.c + "\n";
+		if (this.t < 0 && this.t > 1)
+			throw "t should lie within [0;1]. Entered t = " + this.t + "\n";
+
+		this._calculateTCtoRS();
+	} else if (arguments.length == 3 + offset) {
+		// CertainTrust(r, s, n)
+		this.n = arguments[2 + offset];
+		this.c = 0;
+		this.t = 0.5;
+		this.f = 0.5;
+		this.r = arguments[0 + offset];
+		this.s = arguments[1 + offset];
+		this.doc = 0;
+
+		if (this.n <= 0)
+			throw "N should be greater than 0. Entered n = " + this.n + "\n";
+		if (this.r < 0)
+			throw "r should be positive. Entered r = " + this.r + "\n";
+		if (this.s < 0)
+			throw "s should be positive. Entered s = " + this.s + "\n";
+
+		this._normaliseRS();
+		this._calculateRStoTC();
+	} else {
+		if (arguments.length == 1 + offset) {
+			// CertainTrust(n)
+			this.n = arguments[0 + offset];
+			if (this.n <= 0)
+				throw "N should be greater than 0. Entered n = " + this.n + "\n";
+			this.c = 0;
+			this.t = 0.5;
+			this.f = 0.5;
+			this.r = 0;
+			this.s = 0;
+			this.doc = 0;
+		}
+		else throw "Illegal number of arguments: " + arguments.length + "\n";
+	}
+};
+
+//=========== Getters =================
+CertainTrust.prototype.getName = function() {
+	return this.name;
+};
+
+CertainTrust.prototype.getC = function() {
+	return this.c;
+};
+
+CertainTrust.prototype.getT = function() {
+	return this.t;
+};
+
+CertainTrust.prototype.getF = function() {
+	return this.f;
+};
+
+CertainTrust.prototype.getR = function() {
+	return this.r;
+};
+
+CertainTrust.prototype.getS = function() {
+	return this.s;
+};
+
+CertainTrust.prototype.getN = function() {
+	return this.n;
+};
+
+CertainTrust.prototype.getDoC = function() {
+	return this.doc;
+};
+
+CertainTrust.prototype.getExpectation = function() {
+	return (this.t * this.c) + ((1 - this.c) * this.f);
+};
+
+//=========== Setters =================
+/**
+ * Resets N value. Renormalises r and s values, recalculates c and t accordingly.
+ * @param n - new maximal number of expected evidence
+ */
+CertainTrust.prototype.setN = function(n) {
+	if (n > 0) {
+		this.n = n;
+		this._normaliseRS();
+		this._calculateRStoTC();
+
+		this.notifyObservers();
+	}
+	else throw "N should be greater than 0. Entered n = " + n + "\n";
+};
+
+/**
+ * Sets f value.
+ * @param f - initial trust value.
+ */
+CertainTrust.prototype.setF = function(f) {
+	if (f >= 0 && f <= 1) {
+		this.f = f;
+
+		this.notifyObservers();
+	}
+	else throw "f should lie within [0;1]. Entered f = " + f + "\n";
+};
+
+/**
+ * Sets Degree of Conflict value.
+ * @param doc is the new value for DoC
+ */
+CertainTrust.prototype.setDoC = function(doc) {
+	if (doc >= 0)
+		this.doc = doc;
+	else throw "DoC should be greater than 0. Entered DoC = " + doc + "\n";
+};
+
+/**
+ * Sets c and t values. Recalculates r and s values accordingly.
+ * @param t - new average trust value
+ * @param c - new certainty value
+ */
+CertainTrust.prototype.setTC = function(t, c) {
+	if (c >= 0 && c <= 1) {
+		if (t >= 0 && t <= 1) {
+			this.c = c;
+			this.t = t;
+			this._calculateTCtoRS();
+
+			this.notifyObservers();
+		}
+		else throw "t should be greater than 0. Entered t = " + t + "\n";
+	}
+	else throw "c should lie within [0;1]. Entered c = " + c + "\n";
+};
+
+/**
+ * Sets r and s values. Recalculates c and t values accordingly.
+ * @param r - new number of positive evidence
+ * @param s - new number of negative evidence
+ */
+CertainTrust.prototype.setRS = function(r, s) {
+	if (r >= 0) {
+		if (s >= 0) {
+			this.r = r;
+			this.s = s;
+			this._normaliseRS();
+			this._calculateRStoTC();
+
+			this.notifyObservers();
+		}
+		else throw "s should be positive. Entered s = " + s + "\n";
+	}
+	else throw "r should be positive. Entered r = " + r + "\n";
+};
+
+/**
+ * Add some positive evidence to r.
+ * @param posEvidence - number of new positive evidences
+ */
+CertainTrust.prototype.addR = function(posEvidence) {
+	if (posEvidence >= 0) {
+		this.r += posEvidence;
+		this._normaliseRS();
+		this._calculateRStoTC();
+
+		this.notifyObservers();
+	}
+	else throw "Number of positive evidences should be positive. Entered " + posEvidence + "\n";
+};
+
+/**
+ * Add some negative evidence to s.
+ * @param negEvidence - number of new negative evidences
+ */
+CertainTrust.prototype.addS = function(negEvidence) {
+	if (negEvidence >= 0) {
+		this.s += negEvidence;
+		this._normaliseRS();
+		this._calculateRStoTC();
+
+		this.notifyObservers();
+	}
+	else throw "Number of negative evidences should be positive. Entered " + negEvidence + "\n";
+};
+
+//=========== Logic =================
+/**
+ * Computes OR function for this CertainTrust object and the specified argument. Result is returned as a new object,
+ * argument and this CertainTrust object remain unchanged.
+ * N values of both objects should be equal.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @param arg - CertainTrust object
+ * @return - result of OR computation for this object and an argument.
+ */
+CertainTrust.prototype._singleOR = function(arg) {
+	var c1 = this.getC();
+	var t1 = this.getT();
+	var f1 = this.getF();
+
+	var c2 = arg.getC();
+	var t2 = arg.getT();
+	var f2 = arg.getF();
+
+	var resT = 0.5, resF = 0.5, resC = 0;
+
+	if (!this._operationAllowed(this, arg))
+		return undefined;
+
+	resF = f1 + f2 - f1*f2;
+
+	if (this._almostEqual(resF, 0))
+		resC = c1 + c2 - c1*c2;
+	else
+		resC = c1 + c2 - c1*c2 - (c1*f2*(1-c2)*(1-t1)+c2*f1*(1-c1)*(1-t2)) / resF;
+
+	if (this._almostEqual(resC, 0))
+		resT = 0.5;
+	else resT = (1/resC) * (c1*t1 + c2*t2 - c1*c2*t1*t2);
+
+	resT = this._adjustValue(resT);
+	resC = this._adjustValue(resC);
+	resF = this._adjustValue(resF);
+
+	var result = new CertainTrust(resT, resC, resF, this.n, 0);
+
+	return result;
+};
+
+/**
+ * Computes OR function for this CertainTrust object and the specified arguments.
+ * Result is returned as a new object, arguments and this CertainTrust object remain unchanged.
+ * Example: a.OR(b, c, d) returns new CertainTrust object that equals a OR b OR c OR d.
+ * Multiple arguments allowed, but not less than one.
+ * N values of all objects should be equal.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @param args - arguments
+ * @return - result of OR computation for this object and all arguments.
+ */
+CertainTrust.prototype.OR = function() {
+	var result = this.clone();
+	for (var i = 0; i < arguments.length; ++i) {
+		var m = arguments[i];
+		if (!this._operationAllowed(this, m))
+			continue;
+		result = result._singleOR(m);
+	}
+	return result;
+};
+
+/**
+ * Computes AND function for this CertainTrust object and the specified argument. Result is returned as a new object,
+ * argument and this CertainTrust object remain unchanged.
+ * N values of both objects should be equal.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @param arg - CertainTrust object
+ * @return - result of AND computation for this object and an argument.
+ */
+CertainTrust.prototype._singleAND = function(arg){
+	var c1 = this.getC();
+	var f1 = this.getF();
+	var t1 = this.getT();
+
+	var c2 = arg.getC();
+	var f2 = arg.getF();
+	var t2 = arg.getT();
+
+	var resC = 0, resT = 0.5, resF = 0.5;
+
+	if (!this._operationAllowed(this, arg))
+		return undefined;
+
+	resF = f1*f2;
+	if (this._almostEqual(resF, 1))		//avoid division by 0
+		resC = c1 + c2 - c1*c2;
+	else
+		resC = c1 + c2 - c1*c2 - (c2*t2*(1-c1)*(1-f1)+c1*t1*(1-c2)*(1-f2)) / (1 - resF);
+
+	if (this._almostEqual(resC, 0))
+		resT = 0.5;
+	else if (this._almostEqual(resF, 1))	//avoid division by 0
+		resT = (1/resC) *  (c1*t1*c2*t2);
+	else resT = (1/resC) *  ((c1*t1*c2*t2) + (c1*f2*t1*(1-c2)*(1-f1)+c2*f1*t2*(1-c1)*(1-f2)) / (1 - resF));
+
+	resT = this._adjustValue(resT);
+	resC = this._adjustValue(resC);
+	resF = this._adjustValue(resF);
+
+	return new CertainTrust(resT, resC, resF, this.n, 0);
+};
+
+CertainTrust.prototype._adjustValue = function(arg) {
+	return Math.max(Math.min(arg, 1), 0);
+};
+
+CertainTrust.prototype._almostEqual = function(value, target) {
+	return Math.abs(value - target) < 1E-10;
+};
+
+CertainTrust.prototype._operationAllowed = function(arg1, arg2) {
+	//and all N's of TC's must be equal
+	/*if (arg1.getN() != arg2.getN())							//Disabled by Debashis C. Ray for AND calculation
+		throw "Different N values. Operation not allowed. \n"; */
+	return true;
+}
+
+/**
+ * Computes AND function for this CertainTrust object and the specified arguments.
+ * Result is returned as a new object, arguments and this CertainTrust object remain unchanged.
+ * Example: a.AND(b, c, d) returns new CertainTrust object that equals a AND b AND c AND d.
+ * Multiple arguments allowed, but not less than one.
+ * N values of all objects should be equal.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @param args - arguments
+ * @return - result of AND computation for this object and all arguments.
+ */
+CertainTrust.prototype.AND = function() {
+	var result = this.clone();
+	for (var i = 0; i < arguments.length; i++) {
+		var m = arguments[i];
+		if (!this._operationAllowed(this, m))
+			continue;
+		result = result._singleAND(m);
+	}
+	return result;
+};
+
+/**
+ * Returns NOT of this CertainTrust object.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @return - NOT of this CertainTrust object.
+ */
+CertainTrust.prototype.NOT = function() {
+	var result = this.clone();
+	result.setTC(1 - this.getT(), this.getC());
+	result.setF(1 - this.getF());
+	result.setDoC(0);
+	return result;
+};
+
+/**
+ * an internal implementation of fusion function.
+ * Is called by wFusion and cFusion
+ * @param args - an array of CertainTrust objects
+ * @param weights - an integer array of corresponding weights
+ * @param doc - a degree of conflict (always 0 for wFusion)
+ * @return - new CertainTrust object
+ */
+CertainTrust.prototype._internalFusion = function(args, weights, doc) {
+	var resC, resT, resF;
+	var allOne = true;
+	var allZero = true;
+	var allWeightsZero = true;
+	var atLeastOne1 = false;
+	var arrLength = args.length;
+
+	// set the flags about C and Weight values
+	for (var i = 0; i < arrLength; ++i)
+		if (args[i].getC() !== 1) {
+			allOne = false;
+			i = arrLength;
+		}
+	for (i = 0; i < arrLength; ++i)
+		if (args[i].getC() !== 0) {
+			allZero = false;
+			i = arrLength;
+		}
+	for (i = 0; i < arrLength; ++i)
+		if (weights[i] !== 0) {
+			allWeightsZero = false;
+			i = arrLength;
+		}
+	for (i = 0; i < arrLength; ++i)
+		if (args[i].getC() === 1) {
+			atLeastOne1 = true;
+			i = arrLength;
+		}
+
+	//Calculate T and C
+
+	// 1. all C's  = 1
+	var numeratorT = 0, denominatorT = 0;
+	if (allOne) {
+		// set C
+		resC = 1 * (1 - doc);
+		// set T
+		if (allWeightsZero) {// save some calculation time
+			resT = 0;
+		}
+		else {				// or use the function
+			for (i = 0; i < arrLength; ++i) {
+				numeratorT += weights[i] * args[i].getT();
+				denominatorT += weights[i];
+			}
+			resT = numeratorT/denominatorT;
+		}
+	} else {
+		if (atLeastOne1)
+			throw "Illegal arguments. Either all C values must equal 1 or none of them. Operation not allowed\n";
+		else {
+			// 2. Any other combination
+			if (allWeightsZero) { // save some calculation time
+				resT = 0;
+				resC = 0;
+			}
+			else {					// or use the function
+				var numeratorC = 0, denominatorC = 0, mult;
+				for (i = 0; i < arrLength; ++i) {
+					mult = 1;
+					for (var j = 0; j < arrLength; ++j) // Count the product for each sum element
+						if (j !== i)
+							mult *= 1 - args[j].getC();
+					numeratorT += weights[i] * args[i].getT() * args[i].getC() * mult;
+					denominatorT += weights[i] * args[i].getC() * mult;
+					denominatorC += weights[i] * mult;
+				}
+				numeratorC = denominatorT;
+				resC = (numeratorC/denominatorC) * (1 - doc);
+				if (allZero)
+					resT = 0.5;
+				else
+					resT = numeratorT/denominatorT;
+			}
+			// Special case for T
+			if (allZero)
+				resT = 0.5;
+		}
+	}
+
+	// Calculate F
+	if (allWeightsZero)
+		resF = 0;
+	else {
+		var numerator = 0, denominator = 0;
+		for (i = 0; i < arrLength; ++i) {
+			numerator += weights[i] * args[i].getF();
+			denominator += weights[i];
+		}
+		resF = numerator/denominator;
+	}
+
+	var result = args[0].clone();
+	result.setTC(resT, resC);
+	result.setF(resF);
+	result.setDoC(doc);
+	return result;
+};
+
+/**
+ * Performs weighted fusion for an array of CertainTrust objects in correspondence with
+ * an array of weights. Returns new CertainTrust object.
+ * Requirements: N values of CertainTrust objects must be equal.
+ * Number of weights should equal the number of CertainTrust objects.
+ * Arrays must be non-empty
+ * Either all of CertainTrust must be of certainty 1 or none of them.
+ * @param args - an array of CertainTrust objects
+ * @param weights - an integer array of corresponding weights
+ * @return - new CertainTrust object
+ */
+CertainTrust.prototype.wFusion = function(args, weights) {
+	//arrays should be equal
+	if (args.length == weights.length) {
+		//and not empty
+		if (args.length !== 0) {
+			for (var i = 1; i < args.length; ++i)
+				if (!this._operationAllowed(args[0], args[i]))
+					return undefined;
+
+			return this._internalFusion(args, weights, 0);
+		}
+		else throw "Arrays are empty. Operation not allowed. \n";
+	}
+	else throw "Different lengths of arrays. Operation not allowed. \n";
+};
+
+/**
+ * Conflicted Fusion is a variation of weighted fusion, which additionally computes the degree of conflict 
+ * between given opinions (CertainTrust objects) and takes it into consideration while performing fusion.
+ * The degree of conflict is then saved in the resulting CertainTrust object and may be checked with getDoC() function.
+ * @param args - an array of CertainTrust objects
+ * @param weights - an integer array of corresponding weights
+ * @return - new CertainTrust object
+ */
+CertainTrust.prototype.cFusion = function(args, weights) {
+	//arrays should be equal
+	if (args.length == weights.length) {
+		//and not empty
+		if (args.length !== 0) {
+			for (var i = 1; i < args.length; ++i)
+				if (!this._operationAllowed(args[0], args[i]))
+					return undefined;
+			var denominator = args.length*(args.length - 1) / 2;
+			var numerator = 0;
+			for (i = 0; i < args.length; ++i)
+				for (var j = i; j < args.length; ++j)
+					numerator += Math.abs(args[i].getT() - args[j].getT()) *
+						args[i].getC() * args[j].getC() *
+						(1 - Math.abs((weights[i] - weights[j]) /
+							      (weights[i] + weights[j])));
+			var doc = numerator/denominator;
+			return this._internalFusion(args, weights, doc);
+		}
+		else throw "Arrays are empty. Operation not allowed. \n";
+	}
+	else throw "Different lengths of arrays. Operation not allowed. \n";
+};
+
+//=========== Internal Calculations ==========
+/**
+ * Normalises r and s values according to n - maximal number of expected evidence
+ * Important! Doesn't notify observers.
+ */
+CertainTrust.prototype._normaliseRS = function() {
+	if ((this.r + this.s) > this.n) {
+		var initR = this.r;
+		this.r = (this.r * this.n) / (initR + this.s);
+		this.s = (this.s * this.n) / (initR + this.s);
+	}
+};
+
+/**
+ * Calculates t and c values based on existing r and s values
+ * Important! Doesn't notify observers.
+ */
+CertainTrust.prototype._calculateRStoTC = function() {
+	var rs = this.r + this.s;
+	var nrs = this.n * rs;
+	this.c = nrs / ((2 * this.weight * (this.n - this.r - this.s)) + nrs);
+	if (this._almostEqual(this.c, 0))
+		this.t = 0.5;
+	else
+		this.t = this.r / rs;
+};
+
+/**
+ * Calculates r and s values based on existing c and t values
+ * Important! Doesn't notify observers.
+ */
+CertainTrust.prototype._calculateTCtoRS = function() {
+	if (this._almostEqual(this.c, 0)) {
+		this.r = 0;
+		this.s = 0;
+		this.t = 0.5;
+	}
+	else {
+		var c2w = this.c * 2 * this.weight;
+		var c2wn = c2w * this.n;
+		var cn = this.c * this.n;
+		this.r = (c2wn * this.t) / (c2w + this.n - cn);
+		this.s = (c2wn - (c2wn * this.t)) / (c2w + this.n - cn);
+	}
+};
+
+CertainTrust.prototype.clone = function() {
+	var copy = new CertainTrust(this.getN());
+	copy.c = this.c;
+	copy.t = this.t;
+	copy.f = this.f;
+	copy.r = this.r;
+	copy.s = this.s;
+	copy.doc = this.doc;
+	return copy;
+};
+
+CertainTrust.prototype._isString = function (obj) {
+  return typeof(obj) === 'string';
+};
+
+//=========== Observer =================
+CertainTrust.prototype.notifyObservers = function(message) {
+	for (var i = 0; i < this.observers.length; ++i)
+		this.observers[i].update(this.observers[i], message);
+};
+CertainTrust.prototype.addObserver = function(observer) {
+	this.observers.push(observer);
+};
+CertainTrust.prototype.deleteObserver = function(observer) {
+	var idx = this.observers.indexOf(observer);
+	if(idx !== -1)
+		this.observers.splice(idx, 1);
+};
+
+//=== shared functions for frontends ===
+CertainTrust.prototype._insertElement = function(config, element) {
+	var dom;
+	if (config.domReturn === true) {
+		return element;
+	} else if (config.domParent !== undefined) {
+		if (this._isString(config.domParent))
+			document.getElementById(config.domParent).appendChild(element);
+		else
+			config.domParent.appendChild(element);
+	} else if (config.domBefore !== undefined) {
+		if (this._isString(config.domBefore))
+			dom = document.getElementById(config.domBefore);
+		else
+			dom = config.domBefore;
+		dom.parentNode.insertBefore(element, dom);
+	} else {
+		if (config.domAfter === undefined) {
+			// the last script tag in DOM tree is the one creating this widget
+			var scripts = document.getElementsByTagName('script');
+			dom = scripts[scripts.length - 1];
+		} else if (this._isString(config.domAfter))
+			dom = document.getElementById(config.domAfter);
+		else
+			dom = config.domAfter;
+		dom.parentNode.insertBefore(element, dom.nextSibling);
+	}
+	return undefined;
+};
+CertainTrust.prototype._getColor = function(certainty, trust, initf) {
+	var resultp2 = ((1 - certainty) * initf);
+	var result = (trust * certainty) + resultp2;
+	var color;
+	if (result < 0.5) {
+		color = [
+			255,
+			Math.min(255, (255 * 2 * result)),
+			0
+		];
+	} else {
+		color = [
+			Math.min(255, ((2 - (2 * result)) * 255)),
+			255,
+			0
+		];
+	}
+	return color;
+};
+CertainTrust.prototype._pointOnCircle = function(centerx, centery, pointgrade, radius) {
+	var pointrad = ((360 + pointgrade) % 360) * ((2 * Math.PI) / 360);
+	var chord = 2 * radius * Math.sin((pointrad / 2));
+	// height of our new point above the base-edge
+	var y = Math.sqrt(2
+			* (Math.pow(chord, 2) * Math.pow(radius, 2)
+				+ Math.pow(radius, 4) + Math.pow(radius, 2)
+				* Math.pow(chord, 2))
+			- (Math.pow(chord, 4) + 2 * Math.pow(radius, 4)))
+		/ (2 * radius);
+	// distance to the cross-point of base-edge and height
+	var a = Math.pow(radius, 2);
+	var c = Math.pow(y, 2);
+	// we do this to protect us from NaN cause by 1 - 1.00000004
+	var x = (a < c) ? 0 : Math.sqrt(a - c);
+
+	var directions = new Array("NE", "SE", "SW", "NW");
+	var direction = 0;
+	var alpharad = pointrad;
+	while (alpharad > (0.5 * Math.PI)) {
+		++direction;
+		alpharad -= (0.5 * Math.PI);
+	}
+	if (directions[direction] == "NE" || directions[direction] == "NW")
+		x *= -1;
+	if (directions[direction] == "SW" || directions[direction] == "NW")
+		y *= -1;
+	return new Array((centerx + x), (centery + y));
+};
+
+/* optional implementation of CertainTrust without R and S calculations */
+var CertainTrustSimple = function() {
+	this.weight = 2;
+	this.observers = [];
+
+	var offset = 0;
+	this.name = "";
+
+	if (this._isString(arguments[0])) {
+		this.name = arguments[0];
+		offset = 1;
+	}
+	if (arguments.length == 3 + offset || arguments.length == 4 + offset) {
+		// CertainTrustSimple(t, c, f, doc)
+		// doc is a 'private' parameter
+		this.t = arguments[0 + offset];
+		this.c = arguments[1 + offset];
+		this.f = arguments[2 + offset];
+		this.doc = (arguments.length == 3 + offset) ? 0 : arguments[3 + offset];
+
+		if (this.f < 0 && this.f > 1)
+			throw "f should lie within [0;1]. Entered f = " + this.f + "\n";
+		if (this.c < 0 && this.c > 1)
+			throw "c should lie within [0;1]. Entered c = " + this.c + "\n";
+		if (this.t < 0 && this.t > 1)
+			throw "t should lie within [0;1]. Entered t = " + this.t + "\n";
+	} else {
+		this.c = 0;
+		this.t = 0.5;
+		this.f = 0.5;
+		this.doc = 0;
+	}
+};
+CertainTrustSimple.prototype = new CertainTrust(1);
+CertainTrustSimple.prototype.constructor = CertainTrustSimple;
+CertainTrustSimple.prototype._operationAllowed = function() { return true; }
+CertainTrustSimple.prototype._calculateTCtoRS = function() { }
+CertainTrustSimple.prototype._calculateRStoTC = function() { }
+CertainTrustSimple.prototype._normaliseRS = function() { }
+CertainTrustSimple.prototype.setRS = undefined;
+CertainTrustSimple.prototype.addR = undefined;
+CertainTrustSimple.prototype.addS = undefined;
+CertainTrustSimple.prototype.setN = undefined;
+CertainTrustSimple.prototype.getR = undefined;
+CertainTrustSimple.prototype.getS = undefined;
+CertainTrustSimple.prototype.getN = undefined;
+CertainTrustSimple.prototype.clone = function() {
+	var copy = new CertainTrustSimple();
+	copy.c = this.c;
+	copy.t = this.t;
+	copy.f = this.f;
+	copy.doc = this.doc;
+	return copy;
+};
+
+/*Added by Debashis*/
+CertainTrustSimple.prototype._singlesimpleAND = function(arg){
+	var c1 = this.getC();
+	var f1 = this.getF();
+	var t1 = this.getT();
+
+	var c2 = arg.getC();
+	var f2 = arg.getF();
+	var t2 = arg.getT();
+
+	var resC = 0, resT = 0.5, resF = 0.5;
+
+	if (!this._operationAllowed(this, arg))
+		return undefined;
+
+	resF = f1*f2;
+	if (this._almostEqual(resF, 1))		//avoid division by 0
+		resC = c1 + c2 - c1*c2;
+	else
+		resC = c1 + c2 - c1*c2 - (c2*t2*(1-c1)*(1-f1)+c1*t1*(1-c2)*(1-f2)) / (1 - resF);
+
+	if (this._almostEqual(resC, 0))
+		resT = 0.5;
+	else if (this._almostEqual(resF, 1))	//avoid division by 0
+		resT = (1/resC) *  (c1*t1*c2*t2);
+	else resT = (1/resC) *  ((c1*t1*c2*t2) + (c1*f2*t1*(1-c2)*(1-f1)+c2*f1*t2*(1-c1)*(1-f2)) / (1 - resF));
+
+	resT = this._adjustValue(resT);
+	resC = this._adjustValue(resC);
+	resF = this._adjustValue(resF);
+
+	return new CertainTrustSimple(resT, resC, resF);
+};
+
+CertainTrustSimple.prototype.simpleAND = function() {
+	var result = this.clone();
+	for (var i = 0; i < arguments.length; i++) {
+		var m = arguments[i];
+		if (!this._operationAllowed(this, m))
+			continue;
+		result = result._singlesimpleAND(m);
+	}
+	return result;
+};
+
+CertainTrust.prototype.setName = function(newname) {
+	this.name = newname;
+};
+
+/**
+ * Computes CONSENSUS function for this CertainTrust object and the specified argument. Result is returned as a new object,
+ * argument and this CertainTrust object remain unchanged.
+ * N values of both objects should be equal.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @param arg - CertainTrust object
+ * @return - result of CONSENSUS computation for this object and an argument.
+ */
+CertainTrust.prototype._singleCONSENSUS = function(arg){
+	var c1 = this.getC();
+	var f1 = this.getF();
+	var t1 = this.getT();
+
+	var c2 = arg.getC();
+	var f2 = arg.getF();
+	var t2 = arg.getT();
+
+	var resC = 0, resT = 0.5, resF = 0.5;
+
+	if (!this._operationAllowed(this, arg))
+		return undefined;
+
+	//resF = f1*f2;
+	if (this._almostEqual(resF, 1))		//avoid division by 0
+		resC = (c1+c2-2*c1*c2)/(1-c1*c2);
+	else
+		resC = (c1+c2-2*c1*c2)/(1-c1*c2);
+
+	if (this._almostEqual(resC, 0))
+		resT = 0.5;
+	else if (this._almostEqual(resF, 1))	//avoid division by 0
+		resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1*(1-c2)+c2*(1-c1));
+	else resT = (c1*t1*(1-c2)+c2*t2*(1-c1))/(c1*(1-c2)+c2*(1-c1));
+
+	resT = this._adjustValue(resT);
+	resC = this._adjustValue(resC);
+	resF = this._adjustValue(resF);
+
+	return new CertainTrust(resT, resC, resF, this.n, 0);
+};
+
+CertainTrust.prototype.CONSENSUS = function() {
+	var result = this.clone();
+	for (var i = 0; i < arguments.length; i++) {
+		var m = arguments[i];
+		if (!this._operationAllowed(this, m))
+			continue;
+		result = result._singleCONSENSUS(m);
+	}
+	return result;
+};
+
+/**
+ * Computes DISCOUNTING function for this CertainTrust object and the specified argument. Result is returned as a new object,
+ * argument and this CertainTrust object remain unchanged.
+ * N values of both objects should be equal.
+ * For detailed information see CertainLogic: A Logic for Modeling Trust and Uncertainty
+ * @param arg - CertainTrust object
+ * @return - result of DISCOUNTING computation for this object and an argument.
+ */
+CertainTrust.prototype._singleDISCOUNTING = function(arg){
+	var c1 = this.getC();
+	var f1 = this.getF();
+	var t1 = this.getT();
+
+	var c2 = arg.getC();
+	var f2 = arg.getF();
+	var t2 = arg.getT();
+
+	var resC = 0, resT = 0.5, resF = 0.5;
+
+	if (!this._operationAllowed(this, arg))
+		return undefined;
+
+	//resF = f1*f2;
+	if (this._almostEqual(resF, 1))		//avoid division by 0
+		resC = t1*c1*c2;
+	else
+		resC = t1*c1*c2;
+
+	if (this._almostEqual(resC, 0))
+		resT = t2;
+	else if (this._almostEqual(resF, 1))	//avoid division by 0
+		resT = t2;
+	else resT = t2;
+
+	resT = this._adjustValue(resT);
+	resC = this._adjustValue(resC);
+	resF = this._adjustValue(resF);
+
+	return new CertainTrust(resT, resC, resF, this.n, 0);
+};
+
+CertainTrust.prototype.DISCOUNTING = function() {
+	var result = this.clone();
+	for (var i = 0; i < arguments.length; i++) {
+		var m = arguments[i];
+		if (!this._operationAllowed(this, m))
+			continue;
+		result = result._singleDISCOUNTING(m);
+	}
+	return result;
+};

+ 373 - 0
JavaScript/JavaScript_SDK/Mozilla Public License Version 2.0.txt

@@ -0,0 +1,373 @@
+Mozilla Public License Version 2.0
+==================================
+
+1. Definitions
+--------------
+
+1.1. "Contributor"
+    means each individual or legal entity that creates, contributes to
+    the creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+    means the combination of the Contributions of others (if any) used
+    by a Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+    means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+    means Source Code Form to which the initial Contributor has attached
+    the notice in Exhibit A, the Executable Form of such Source Code
+    Form, and Modifications of such Source Code Form, in each case
+    including portions thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+    means
+
+    (a) that the initial Contributor has attached the notice described
+        in Exhibit B to the Covered Software; or
+
+    (b) that the Covered Software was made available under the terms of
+        version 1.1 or earlier of the License, but not also under the
+        terms of a Secondary License.
+
+1.6. "Executable Form"
+    means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+    means a work that combines Covered Software with other material, in 
+    a separate file or files, that is not Covered Software.
+
+1.8. "License"
+    means this document.
+
+1.9. "Licensable"
+    means having the right to grant, to the maximum extent possible,
+    whether at the time of the initial grant or subsequently, any and
+    all of the rights conveyed by this License.
+
+1.10. "Modifications"
+    means any of the following:
+
+    (a) any file in Source Code Form that results from an addition to,
+        deletion from, or modification of the contents of Covered
+        Software; or
+
+    (b) any new file in Source Code Form that contains any Covered
+        Software.
+
+1.11. "Patent Claims" of a Contributor
+    means any patent claim(s), including without limitation, method,
+    process, and apparatus claims, in any patent Licensable by such
+    Contributor that would be infringed, but for the grant of the
+    License, by the making, using, selling, offering for sale, having
+    made, import, or transfer of either its Contributions or its
+    Contributor Version.
+
+1.12. "Secondary License"
+    means either the GNU General Public License, Version 2.0, the GNU
+    Lesser General Public License, Version 2.1, the GNU Affero General
+    Public License, Version 3.0, or any later versions of those
+    licenses.
+
+1.13. "Source Code Form"
+    means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+    means an individual or a legal entity exercising rights under this
+    License. For legal entities, "You" includes any entity that
+    controls, is controlled by, or is under common control with You. For
+    purposes of this definition, "control" means (a) the power, direct
+    or indirect, to cause the direction or management of such entity,
+    whether by contract or otherwise, or (b) ownership of more than
+    fifty percent (50%) of the outstanding shares or beneficial
+    ownership of such entity.
+
+2. License Grants and Conditions
+--------------------------------
+
+2.1. Grants
+
+Each Contributor hereby grants You a world-wide, royalty-free,
+non-exclusive license:
+
+(a) under intellectual property rights (other than patent or trademark)
+    Licensable by such Contributor to use, reproduce, make available,
+    modify, display, perform, distribute, and otherwise exploit its
+    Contributions, either on an unmodified basis, with Modifications, or
+    as part of a Larger Work; and
+
+(b) under Patent Claims of such Contributor to make, use, sell, offer
+    for sale, have made, import, and otherwise transfer either its
+    Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+The licenses granted in Section 2.1 with respect to any Contribution
+become effective for each Contribution on the date the Contributor first
+distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+The licenses granted in this Section 2 are the only rights granted under
+this License. No additional rights or licenses will be implied from the
+distribution or licensing of Covered Software under this License.
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
+Contributor:
+
+(a) for any code that a Contributor has removed from Covered Software;
+    or
+
+(b) for infringements caused by: (i) Your and any other third party's
+    modifications of Covered Software, or (ii) the combination of its
+    Contributions with other software (except as part of its Contributor
+    Version); or
+
+(c) under Patent Claims infringed by Covered Software in the absence of
+    its Contributions.
+
+This License does not grant any rights in the trademarks, service marks,
+or logos of any Contributor (except as may be necessary to comply with
+the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+No Contributor makes additional grants as a result of Your choice to
+distribute the Covered Software under a subsequent version of this
+License (see Section 10.2) or under the terms of a Secondary License (if
+permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+Each Contributor represents that the Contributor believes its
+Contributions are its original creation(s) or it has sufficient rights
+to grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+This License is not intended to limit any rights You have under
+applicable copyright doctrines of fair use, fair dealing, or other
+equivalents.
+
+2.7. Conditions
+
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
+in Section 2.1.
+
+3. Responsibilities
+-------------------
+
+3.1. Distribution of Source Form
+
+All distribution of Covered Software in Source Code Form, including any
+Modifications that You create or to which You contribute, must be under
+the terms of this License. You must inform recipients that the Source
+Code Form of the Covered Software is governed by the terms of this
+License, and how they can obtain a copy of this License. You may not
+attempt to alter or restrict the recipients' rights in the Source Code
+Form.
+
+3.2. Distribution of Executable Form
+
+If You distribute Covered Software in Executable Form then:
+
+(a) such Covered Software must also be made available in Source Code
+    Form, as described in Section 3.1, and You must inform recipients of
+    the Executable Form how they can obtain a copy of such Source Code
+    Form by reasonable means in a timely manner, at a charge no more
+    than the cost of distribution to the recipient; and
+
+(b) You may distribute such Executable Form under the terms of this
+    License, or sublicense it under different terms, provided that the
+    license for the Executable Form does not attempt to limit or alter
+    the recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+You may create and distribute a Larger Work under terms of Your choice,
+provided that You also comply with the requirements of this License for
+the Covered Software. If the Larger Work is a combination of Covered
+Software with a work governed by one or more Secondary Licenses, and the
+Covered Software is not Incompatible With Secondary Licenses, this
+License permits You to additionally distribute such Covered Software
+under the terms of such Secondary License(s), so that the recipient of
+the Larger Work may, at their option, further distribute the Covered
+Software under the terms of either this License or such Secondary
+License(s).
+
+3.4. Notices
+
+You may not remove or alter the substance of any license notices
+(including copyright notices, patent notices, disclaimers of warranty,
+or limitations of liability) contained within the Source Code Form of
+the Covered Software, except that You may alter any license notices to
+the extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+You may choose to offer, and to charge a fee for, warranty, support,
+indemnity or liability obligations to one or more recipients of Covered
+Software. However, You may do so only on Your own behalf, and not on
+behalf of any Contributor. You must make it absolutely clear that any
+such warranty, support, indemnity, or liability obligation is offered by
+You alone, and You hereby agree to indemnify every Contributor for any
+liability incurred by such Contributor as a result of warranty, support,
+indemnity or liability terms You offer. You may include additional
+disclaimers of warranty and limitations of liability specific to any
+jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+---------------------------------------------------
+
+If it is impossible for You to comply with any of the terms of this
+License with respect to some or all of the Covered Software due to
+statute, judicial order, or regulation then You must: (a) comply with
+the terms of this License to the maximum extent possible; and (b)
+describe the limitations and the code they affect. Such description must
+be placed in a text file included with all distributions of the Covered
+Software under this License. Except to the extent prohibited by statute
+or regulation, such description must be sufficiently detailed for a
+recipient of ordinary skill to be able to understand it.
+
+5. Termination
+--------------
+
+5.1. The rights granted under this License will terminate automatically
+if You fail to comply with any of its terms. However, if You become
+compliant, then the rights granted under this License from a particular
+Contributor are reinstated (a) provisionally, unless and until such
+Contributor explicitly and finally terminates Your grants, and (b) on an
+ongoing basis, if such Contributor fails to notify You of the
+non-compliance by some reasonable means prior to 60 days after You have
+come back into compliance. Moreover, Your grants from a particular
+Contributor are reinstated on an ongoing basis if such Contributor
+notifies You of the non-compliance by some reasonable means, this is the
+first time You have received notice of non-compliance with this License
+from such Contributor, and You become compliant prior to 30 days after
+Your receipt of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+infringement claim (excluding declaratory judgment actions,
+counter-claims, and cross-claims) alleging that a Contributor Version
+directly or indirectly infringes any patent, then the rights granted to
+You by any and all Contributors for the Covered Software under Section
+2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
+end user license agreements (excluding distributors and resellers) which
+have been validly granted by You or Your distributors under this License
+prior to termination shall survive termination.
+
+************************************************************************
+*                                                                      *
+*  6. Disclaimer of Warranty                                           *
+*  -------------------------                                           *
+*                                                                      *
+*  Covered Software is provided under this License on an "as is"       *
+*  basis, without warranty of any kind, either expressed, implied, or  *
+*  statutory, including, without limitation, warranties that the       *
+*  Covered Software is free of defects, merchantable, fit for a        *
+*  particular purpose or non-infringing. The entire risk as to the     *
+*  quality and performance of the Covered Software is with You.        *
+*  Should any Covered Software prove defective in any respect, You     *
+*  (not any Contributor) assume the cost of any necessary servicing,   *
+*  repair, or correction. This disclaimer of warranty constitutes an   *
+*  essential part of this License. No use of any Covered Software is   *
+*  authorized under this License except under this disclaimer.         *
+*                                                                      *
+************************************************************************
+
+************************************************************************
+*                                                                      *
+*  7. Limitation of Liability                                          *
+*  --------------------------                                          *
+*                                                                      *
+*  Under no circumstances and under no legal theory, whether tort      *
+*  (including negligence), contract, or otherwise, shall any           *
+*  Contributor, or anyone who distributes Covered Software as          *
+*  permitted above, be liable to You for any direct, indirect,         *
+*  special, incidental, or consequential damages of any character      *
+*  including, without limitation, damages for lost profits, loss of    *
+*  goodwill, work stoppage, computer failure or malfunction, or any    *
+*  and all other commercial damages or losses, even if such party      *
+*  shall have been informed of the possibility of such damages. This   *
+*  limitation of liability shall not apply to liability for death or   *
+*  personal injury resulting from such party's negligence to the       *
+*  extent applicable law prohibits such limitation. Some               *
+*  jurisdictions do not allow the exclusion or limitation of           *
+*  incidental or consequential damages, so this exclusion and          *
+*  limitation may not apply to You.                                    *
+*                                                                      *
+************************************************************************
+
+8. Litigation
+-------------
+
+Any litigation relating to this License may be brought only in the
+courts of a jurisdiction where the defendant maintains its principal
+place of business and such litigation shall be governed by laws of that
+jurisdiction, without reference to its conflict-of-law provisions.
+Nothing in this Section shall prevent a party's ability to bring
+cross-claims or counter-claims.
+
+9. Miscellaneous
+----------------
+
+This License represents the complete agreement concerning the subject
+matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent
+necessary to make it enforceable. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+shall not be used to construe this License against a Contributor.
+
+10. Versions of the License
+---------------------------
+
+10.1. New Versions
+
+Mozilla Foundation is the license steward. Except as provided in Section
+10.3, no one other than the license steward has the right to modify or
+publish new versions of this License. Each version will be given a
+distinguishing version number.
+
+10.2. Effect of New Versions
+
+You may distribute the Covered Software under the terms of the version
+of the License under which You originally received the Covered Software,
+or under the terms of any subsequent version published by the license
+steward.
+
+10.3. Modified Versions
+
+If you create software not governed by this License, and you want to
+create a new license for such software, you may create and use a
+modified version of this License if you rename the license and remove
+any references to the name of the license steward (except to note that
+such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+Licenses
+
+If You choose to distribute Source Code Form that is Incompatible With
+Secondary Licenses under the terms of this version of the License, the
+notice described in Exhibit B of this License must be attached.
+
+Exhibit A - Source Code Form License Notice
+-------------------------------------------
+
+  This Source Code Form is subject to the terms of the Mozilla Public
+  License, v. 2.0. If a copy of the MPL was not distributed with this
+  file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular
+file, then You may include the notice in a location (such as a LICENSE
+file in a relevant directory) where a recipient would be likely to look
+for such a notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+---------------------------------------------------------
+
+  This Source Code Form is "Incompatible With Secondary Licenses", as
+  defined by the Mozilla Public License, v. 2.0.

+ 34 - 0
JavaScript/JavaScript_SDK/certainTrustHTI.css

@@ -0,0 +1,34 @@
+/**
+ * CertainTrust SDK
+ * 
+ * Implements the computational trust model "CertainTrust"
+ * in JavaScript.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ * 
+ * 
+ * Telecooperation Department, Technische Universität Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ * 
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ * 
+ * 
+ * @author	David Kalnischkies
+ * @author	Florian Volk
+ * @version	1.0
+ */
+ 
+ /* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+  
+ 
+
+.certaintrust-hti { border: 1px solid black; padding: 1em; white-space: nowrap; display: inline-block; }
+.certaintrust-hti > h1 { text-align: center; margin:0; margin-bottom: 1em; }
+.certaintrust-hti > .certaintrust-hti { border: 0; padding: 0; margin: 0; }
+.certaintrust-hti-e { margin-top: 1em; }
+.certaintrust-hti canvas { border: 1px solid black; }
+.certaintrust-hti form { float: left; margin-right: 1.5em; }
+.certaintrust-hti label { display: block; float: left; width: 7em; font-size: 1em; }
+.certaintrust-hti input { width: 4em; margin-bottom: 0.5em; }

+ 461 - 0
JavaScript/JavaScript_SDK/certainTrustHTI.js

@@ -0,0 +1,461 @@
+/**
+ * CertainTrust SDK
+ * 
+ * Implements the computational trust model "CertainTrust"
+ * in JavaScript.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ * 
+ * 
+ * Telecooperation Department, Technische Universität Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ * 
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ * 
+ * 
+ * @author	David Kalnischkies
+ * @author	Florian Volk
+ * @version	1.0
+ */
+ 
+ /* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+ 
+
+/** Certain Trust Widget
+ *
+ * Creates a color-coded graph created from an initial trust value
+ * in which the user can pick certainty (y-axis) and trust (x-axis)
+ * with the mouse in the graph.
+ *
+ * The values are displayed and can be modified inside a form
+ * while the graph in the canvas will be updated from those values.
+ *
+ * Options can be given in an object as parameter to the constructor
+ * The following keys are understood:
+ *  id is the id the top-div of the widget will get. Its used as basename for all element ids in it, too
+ *  label is an object for various messages which are shown to the user
+ *   lang is the language to use. Available are 'de' and 'en' (default)
+ *   Alternatively f, t, c and e can be used to set the text explicitly
+ *  canvas is an object containing subkeys 'width' and 'height' defining dimensions of the canvas element
+ *  line is an object defining the style of the lines building the cross to mark the chosen trust/certainty
+ *   cap is the canvas.lineCap defining the style used to smooth the end of the lines
+ *   height is the length of the line from start to the crosspoint
+ *   width is the thickness of the line
+ *   style is the color of the line
+ *  readonly can be used to disable input in the HTI as a whole,
+ *   Alternatively f, t, c, e, inputs for all of the previous and mouse can be used to disable specific elements.
+ *  show can be used to disable display of certain inputs refered to as
+ *   f, t, c, e, inputs for all of the previous, title and axes.
+ *
+ * One of the following keys can be used to specify the position of the widget in the DOM,
+ * the first defined will be used. If none is provided domAfter will be set to the <script>-tag calling
+ * the creation of the widget (= the last <script>-tag currently in the DOM)
+ * Either the DOM element itself can be given or the ID of the element as a string.
+ *  domReturn is set to true to get the DOM subtree as return value of the constructor instead [update() is NOT called]
+ *  domParent is (the id of) the parent for the widget
+ *  domBefore is (the id of) the element which the widget will be in front of
+ *  domAfter is (the id of) the element after which the widget will be inserted
+ */
+
+
+
+var CertainTrustHTI = function(certainlogic, config) {
+	if (certainlogic === undefined)
+		this.certainTrust = new CertainTrust(5);
+	else
+		this.certainTrust = certainlogic;
+
+	this.NR = CertainTrustHTIElement.length();
+	CertainTrustHTIElement.push(this);
+	this.certainTrust.addObserver(this);
+
+	// set sane defaults for config if nothing is set
+	if (config === undefined) config = {};
+	if (config.id === undefined) config.id = 'certaintrust-hti-' + this.NR;
+	// design your widget
+	if (config.canvas === undefined) config.canvas = {};
+	if (config.canvas.height === undefined) config.canvas.height = 100;
+	if (config.canvas.width === undefined) config.canvas.width = 120;
+	if (config.line === undefined) config.line = {};
+	if (config.line.cap === undefined) config.line.cap = 'round';
+	if (config.line.height === undefined) config.line.height = 5;
+	if (config.line.width === undefined) config.line.width = 1;
+	if (config.line.style === undefined) config.line.style = 'black';
+	if (config.line.baserad === undefined) config.line.baserad = 45;
+	else config.line.baserad %= 90;
+	if (config.confidence === undefined) config.confidence = {};
+	if (config.confidence.cap === undefined) config.confidence.cap = 'round';
+	if (config.confidence.height === undefined) config.confidence.height = 5;
+	if (config.confidence.width === undefined) config.confidence.width = 0;
+	if (config.confidence.style === undefined) config.confidence.style = 'gray';
+	if (config.confidence.quantil === undefined) config.confidence.quantil = 1.96;
+
+	// language settings
+	if (config.label === undefined) config.label = {};
+	if (config.label.lang === undefined) config.label.lang = 'en';
+	if (config.label.lang === 'de') {
+		if (config.label.f === undefined) config.label.f = 'Initialwert';
+		if (config.label.t === undefined) config.label.t = 'Vertrauen';
+		if (config.label.c === undefined) config.label.c = 'Sicherheit';
+		if (config.label.e === undefined) config.label.e = 'Erwartung';
+	} else {
+		if (config.label.f === undefined) config.label.f = 'Init. value';
+		if (config.label.t === undefined) config.label.t = 'Trust';
+		if (config.label.c === undefined) config.label.c = 'Certainty';
+		if (config.label.e === undefined) config.label.e = 'Expectation';
+	}
+	// readonly forms maybe?
+	var readonlyflag = false;
+	if (config.readonly === undefined) {
+		config.readonly = {};
+		config.readonly.e = true;
+	} else {
+		readonlyflag = config.readonly;
+		config.readonly = {};
+	}
+	if (config.readonly.inputs === undefined) config.readonly.inputs = readonlyflag;
+	if (config.readonly.f === undefined) config.readonly.f = config.readonly.inputs;
+	if (config.readonly.t === undefined) config.readonly.t = config.readonly.inputs;
+	if (config.readonly.c === undefined) config.readonly.c = config.readonly.inputs;
+	if (config.readonly.e === undefined) config.readonly.e = config.readonly.inputs;
+	if (config.readonly.mouse === undefined) config.readonly.mouse = readonlyflag;
+
+	// show/disable elements
+	var showflag = true;
+	if (config.show === undefined) config.show = {};
+	else {
+		showflag = config.show;
+		config.show = {};
+	}
+	if (config.show.inputs === undefined) config.show.inputs = showflag;
+	if (config.show.f === undefined) config.show.f = config.show.inputs;
+	if (config.show.t === undefined) config.show.t = config.show.inputs;
+	if (config.show.c === undefined) config.show.c = config.show.inputs;
+	if (config.show.e === undefined) config.show.e = config.show.inputs;
+	if (config.show.title === undefined) config.show.title = showflag;
+	if (config.show.axes === undefined) config.show.axes = showflag;
+
+	this.ID = config.id;
+	this.config = config;
+	var element = document.createElement('div');
+	element.setAttribute('id', this.ID);
+	element.setAttribute('class', 'certaintrust-hti');
+	if (config.show.title === true && this.certainTrust.getName().length !== 0)
+	{
+		var title = document.createElement('h1');
+		var msg = document.createTextNode(this.certainTrust.getName());
+		title.appendChild(msg);
+		element.appendChild(title);
+	}
+	var form = document.createElement('form');
+	form.setAttribute('id', this.ID + '-form');
+	var appendInput = function (form, id, nr, type, value, text, readonly, show) {
+		if (show === false)
+			return;
+		var div = document.createElement('div');
+		div.setAttribute('class', 'certaintrust-hti-' + type);
+		var label = document.createElement('label');
+		label.setAttribute('for', id + '-' + type);
+		div.appendChild(label);
+		var labeltext = document.createTextNode(text);
+		label.appendChild(labeltext);
+		var input = document.createElement('input');
+		input.setAttribute('type', 'text');
+		input.setAttribute('id', id + '-' + type);
+		var cte = CertainTrustHTIElement.ByNr(nr);
+		input.setAttribute('value', value);
+		if (readonly === true) {
+			input.setAttribute('readonly', 'readonly');
+			input.setAttribute('tabindex', '-1');
+		} else {
+			input.addEventListener('keypress', cte._onKeyPress, false);
+			input.addEventListener('blur', cte._onBlur, false);
+		}
+		div.appendChild(input);
+		form.appendChild(div);
+	};
+	appendInput(form, this.ID, this.NR, 'f', this.certainTrust.getF(), config.label.f, config.readonly.f, config.show.f);
+	appendInput(form, this.ID, this.NR, 't', this.certainTrust.getT(), config.label.t, config.readonly.t, config.show.t);
+	appendInput(form, this.ID, this.NR, 'c', this.certainTrust.getC(), config.label.c, config.readonly.c, config.show.c);
+	appendInput(form, this.ID, this.NR, 'e', this.certainTrust.getExpectation(), config.label.e, config.readonly.e, config.show.e);
+	if (form.hasChildNodes())
+		element.appendChild(form);
+
+	var hti = document.createElement('div');
+	hti.style.cssFloat=hti.style.styleFloat='left';
+	if (config.show.axes === true)
+	{
+		var yaxis = document.createElement('span');
+		yaxis.setAttribute('class', 'certaintrust-hti-yaxis');
+		yaxis.style.cssFloat=yaxis.style.styleFloat='left';
+		// width still defines the width of the box even if the
+		// element in it is rotated, so we need to set this to 1em
+		// even if the text will overflow it to have the canvas close
+		yaxis.style.width='1em';
+		// transform in theory:
+		yaxis.style.transform='rotate(270deg) translate(-4em,0em)';
+		yaxis.style.transformOrigin='100% 100%';
+		// transform in practice:
+		yaxis.style.MozTransform='rotate(270deg) translate(-4em,0em)';
+		yaxis.style.MozTransformOrigin='100% 100%';
+		yaxis.style.webkitTransform='rotate(270deg) translate(-4em,0em)';
+		yaxis.style.webkitTransformOrigin='100% 100%';
+		yaxis.style.msTransform='rotate(270deg) translate(-4em,0em)';
+		yaxis.style.msTransformOrigin='100% 100%';
+		yaxis.style.OTransform='rotate(270deg) translate(-4em,0em)';
+		yaxis.style.OTransformOrigin='100% 100%';
+		// \u00a0 is a non-breaking space, \u2192 is a right arrow
+		var yaxislabel = document.createTextNode(config.label.c + '\u00a0\u2192');
+		yaxis.appendChild(yaxislabel);
+		hti.appendChild(yaxis);
+	}
+	this.canvas = document.createElement('canvas');
+	this.canvas.style.cssFloat=this.canvas.style.styleFloat='left';
+	this.canvas.setAttribute('id', this.ID + '-canvas');
+	this.canvas.setAttribute('width', config.canvas.width);
+	this.canvas.setAttribute('height', config.canvas.height);
+//	this.canvas.setAttribute('title', this.ID); // useful to identify which widget is which
+	this.canvas.addEventListener("mousedown", this._onClick, false);
+	this.canvas.addEventListener("mousemove", this._onMove, false);
+	hti.appendChild(this.canvas);
+	if (config.show.axes === true)
+	{
+		var origin = document.createElement('span');
+		origin.style.textAlign='center';
+		origin.style.width='1em';
+		origin.style.clear='both';
+		origin.style.cssFloat=origin.style.styleFloat='left';
+		var originlabel = document.createTextNode('0');
+		origin.appendChild(originlabel);
+		hti.appendChild(origin);
+		var xaxis = document.createElement('span');
+		xaxis.style.cssFloat=xaxis.style.styleFloat='left';
+		var xaxislabel = document.createTextNode(config.label.t + '\u00a0\u2192');
+		xaxis.appendChild(xaxislabel);
+		hti.appendChild(xaxis);
+	}
+	element.appendChild(hti);
+
+	var dom = this.certainTrust._insertElement(config, element);
+	if (dom !== undefined)
+		return dom;
+
+	this.update();
+};
+
+/** (re)draws the canvas
+ *  The widget must be in the DOM tree to be able to be drawn */
+CertainTrustHTI.prototype.update = function() {
+	var ctx = this.canvas.getContext('2d');
+	var width = parseInt(this.canvas.getAttribute('width'), 10);
+	var height = parseInt(this.canvas.getAttribute('height'), 10);
+
+	var initf = this.certainTrust.getF();
+	var imageData = ctx.createImageData(width, height);
+	var d = 0;
+	for (var y = 0; y < height; ++y) {
+		var certainty = 1 - (y / height);
+		for (var x = 0; x < width; ++x) {
+			var trust = x / width;
+			var color = this.certainTrust._getColor(certainty, trust, initf);
+			// each pixel consists of four numbers: red, green, blue and alpha ranging from 0 to 255
+			imageData.data[d++] = color[0];
+			imageData.data[d++] = color[1];
+			imageData.data[d++] = color[2];
+			imageData.data[d++] = 255; // set no alpha-transparency
+		}
+	}
+	ctx.putImageData(imageData, 0, 0);
+
+	// put a 'cross' on the 'pixel' representing certainty/trust
+	var dotmiddle = Math.floor(this.config.line.width / 2);
+	var doty = Math.round(((1 - this.certainTrust.getC()) * height) - dotmiddle);
+	var dotx = Math.round((this.certainTrust.getT() * width) - dotmiddle);
+
+	// confidence interval
+	if (this.config.confidence.width !== 0) {
+		// if the line has an odd-size we have to place it on half-pixels or it looks odd
+		var middle = (this.config.confidence.width % 2 === 0) ? 0 : 0.5;
+		// calculate upper/lower bound of Wilson confidence interval
+		var K = this.config.confidence.quantil;
+		var x = this.certainTrust.getR();
+		var n = this.certainTrust.getR() + this.certainTrust.getS();
+		var p = this.certainTrust.getT();
+		var wilson = this.intervalCertainty(K, x, n, p, width);
+
+		ctx.beginPath();
+		ctx.moveTo(Math.floor(wilson.upper - dotmiddle), doty + middle - this.config.confidence.height);
+		ctx.lineTo(Math.floor(wilson.upper - dotmiddle), doty + middle + this.config.confidence.height);
+		ctx.moveTo(Math.floor(wilson.upper - dotmiddle), doty + middle);
+		ctx.lineTo(Math.floor(wilson.lower - dotmiddle), doty + middle);
+		ctx.moveTo(Math.floor(wilson.lower - dotmiddle), doty + middle - this.config.confidence.height);
+		ctx.lineTo(Math.floor(wilson.lower - dotmiddle), doty + middle + this.config.confidence.height);
+		ctx.lineWidth = this.config.confidence.width;
+		ctx.lineCap = this.config.confidence.cap;
+		ctx.strokeStyle = this.config.confidence.style;
+		ctx.stroke();
+		ctx.closePath();
+	}
+
+	// if the line has an odd-size we have to place it on half-pixels or it looks odd
+	var middle = (this.config.line.width % 2 === 0) ? 0 : 0.5;
+	var line1 = new Array(
+		this.certainTrust._pointOnCircle(dotx, doty + middle, (this.config.line.baserad + 0), this.config.line.height),
+		this.certainTrust._pointOnCircle(dotx, doty + middle, (this.config.line.baserad + 180), this.config.line.height)
+	);
+	var line2 = new Array(
+		this.certainTrust._pointOnCircle(dotx, doty + middle, (this.config.line.baserad + 90), this.config.line.height),
+		this.certainTrust._pointOnCircle(dotx, doty + middle, (this.config.line.baserad + 270), this.config.line.height)
+	);
+
+	ctx.beginPath();
+	ctx.moveTo(Math.round(line1[0][0]) + middle, Math.round(line1[0][1]) + middle);
+	ctx.lineTo(Math.round(line1[1][0]) + middle, Math.round(line1[1][1]) + middle);
+	ctx.moveTo(Math.round(line2[0][0]) + middle, Math.round(line2[0][1]) + middle);
+	ctx.lineTo(Math.round(line2[1][0]) + middle, Math.round(line2[1][1]) + middle);
+	ctx.lineWidth = this.config.line.width;
+	ctx.lineCap = this.config.line.cap;
+	ctx.strokeStyle = this.config.line.style;
+	ctx.stroke();
+	ctx.closePath();
+
+	// display the certainTrust values in a user-friendly way without modifying their internal state
+	this._setElementValue(this.ID + '-f', this.certainTrust.getF());
+	this._setElementValue(this.ID + '-c', this.certainTrust.getC());
+	this._setElementValue(this.ID + '-t', this.certainTrust.getT());
+	this._setElementValue(this.ID + '-e', this.certainTrust.getExpectation());
+};
+CertainTrustHTI.prototype._setElementValue = function(id, value) {
+	var element = document.getElementById(id);
+	if (element === null)
+		return;
+	element.value = this._formatNumber(value);
+};
+
+/** calculating Wilson/Goldman interval boundaries */
+CertainTrustHTI.prototype.intervalCertainty = function(K, x, n, p, width) {
+	var K2 = Math.pow(K, 2);
+	var nK2 = n + K2;
+	var part1 = (x + (K2 / 2)) / nK2;
+	var part2 = (K * Math.sqrt(n)) / nK2;
+	var part3 = Math.sqrt(p * (1 - p) + (K2 / (4 * n)));
+	var uwx = (part1 + part2 * part3) * width;
+	var lwx = (part1 - part2 * part3) * width;
+	return { upper: uwx, lower: lwx };
+};
+
+CertainTrustHTI.prototype._onMove = function(e) {
+	if (CertainTrustHTIElement._isMouseDown !== true)
+		return;
+	var cte = CertainTrustHTIElement.ByCanvas(this);
+	if (cte.config.readonly.mouse === true)
+		return;
+	cte._onClick(e, this);
+};
+
+CertainTrustHTI.prototype._onClick = function(e, clkcanvas) {
+	// if it's called by onMove this is not the clicked canvas but the element, so we have to pass it on
+	if (clkcanvas === undefined)
+		clkcanvas = this;
+
+	var cte = CertainTrustHTIElement.ByCanvas(clkcanvas);
+	if (cte.config.readonly.mouse === true)
+		return;
+	// this could be the start of a drag across the canvas
+	CertainTrustHTIElement._isMouseDown = true;
+
+	// convert screen-relative coordinates to canvas-relatives to trust/certainty and limit these values to [0;1]
+	var x = e.clientX;
+	var y = e.clientY;
+	// https://developer.mozilla.org/en-US/docs/Web/API/element.getBoundingClientRect
+	var ctBounding = clkcanvas.getBoundingClientRect();
+	var cx = ctBounding.left;
+	var cy = ctBounding.top;
+	var newT = Math.max(0, Math.min(1, (x - cx) / clkcanvas.width));
+	var newC = Math.max(0, Math.min(1, 1 - ((y - cy) / clkcanvas.height)));
+	cte.certainTrust.setTC(newT, newC);
+};
+
+CertainTrustHTI.prototype._onKeyPress = function(e) {
+	if (e.keyCode != 13)
+		return;
+
+	// update values only in case the user pressed the return key
+	var cid = this.id.substring(0, this.id.lastIndexOf('-'));
+	var cte = CertainTrustHTIElement.ById(cid);
+	cte._updateInput(this.id);
+};
+
+CertainTrustHTI.prototype._onBlur = function(e) {
+	// update values if focus left the input field
+	var cid = this.id.substring(0, this.id.lastIndexOf('-'));
+	var cte = CertainTrustHTIElement.ById(cid);
+	cte._updateInput(this.id);
+};
+
+CertainTrustHTI.prototype._updateInput = function(id) {
+	// this is the input-element the key was pressed in - thankfully the id for
+	// these input fields are autogenerated from the id of the widget
+	var cid = id.substring(0, id.lastIndexOf('-'));
+	if (id.substring(id.lastIndexOf('-')) === '-f') {
+		var newF = this._normalizeInput(document.getElementById(cid + '-f').value);
+		this.certainTrust.setF((isNaN(newF)) ? this.certainTrust.getF() : newF);
+	} else { // if ( == '-c' || == '-t')
+		var newT = this._normalizeInput(document.getElementById(cid + '-t').value);
+		var newC = this._normalizeInput(document.getElementById(cid + '-c').value);
+		this.certainTrust.setTC(
+			(isNaN(newT)) ? this.certainTrust.getT() : newT,
+			(isNaN(newC)) ? this.certainTrust.getC() : newC
+		);
+	}
+};
+
+// parse the user-input to a number (best attempt approach)
+CertainTrustHTI.prototype._normalizeInput = function(input) {
+	// first, replace the first "," with "." to enable German-language style floating point input
+	var rawInput = (input+"").replace(/,/, ".");
+	// now, strip out all leading 0s to prevent parseFloat from treating the input as octal
+	rawInput = rawInput.replace(/^0+\./, ".");
+
+	// convert to a number
+	var floatInput = parseFloat(rawInput); // attention, this may be NaN -> _updateInput handles this
+	if ((1 < floatInput) || (0 > floatInput)) {
+		return NaN;
+	} else {
+		return floatInput;
+	}
+};
+
+// rounds numbers to at most 3 decimal places
+CertainTrustHTI.prototype._formatNumber = function(number) {
+	// return number.toFixed(3);
+	return Math.round(number * 1000) / 1000;
+};
+
+// global var for storing and accessing all the widgets
+var CertainTrustHTIElement = { _elements: [],
+	_isMouseDown: false,
+	ByCanvas: function(canvas) {
+		for (var i = 0; i < CertainTrustHTIElement._elements.length; ++i) {
+			if (CertainTrustHTIElement._elements[i].canvas === canvas)
+				return CertainTrustHTIElement._elements[i];
+		}
+		return null;
+	},
+	ById: function(id) {
+		for (var i = 0; i < CertainTrustHTIElement._elements.length; ++i) {
+			if (CertainTrustHTIElement._elements[i].ID === id)
+				return CertainTrustHTIElement._elements[i];
+		}
+		return null;
+	},
+	ByNr: function(nr) { return CertainTrustHTIElement._elements[nr]; },
+	push: function(cte) { CertainTrustHTIElement._elements.push(cte); },
+	length: function() { return CertainTrustHTIElement._elements.length; }
+
+};
+
+// react on every mouseup - even outside of a canvas
+document.addEventListener("mouseup", function() { CertainTrustHTIElement._isMouseDown = false; }, false);

+ 38 - 0
JavaScript/JavaScript_SDK/certainTrustTViz.css

@@ -0,0 +1,38 @@
+/**
+ * CertainTrust SDK
+ *
+ * Implements the computational trust model "CertainTrust"
+ * in JavaScript.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ *
+ *
+ * Telecooperation Department, Technische Universität Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ *
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ *
+ *
+ * @author	David Kalnischkies
+ * @version	1.0
+ */
+
+ /* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+.certaintrust-tviz-axes line {
+	shape-rendering: crispedges;
+}
+.certaintrust-tviz-axis-right text {
+	text-anchor: start;
+	stroke-width: 0;
+}
+.certaintrust-tviz-axis-left text {
+	text-anchor: end;
+	stroke-width: 0;
+}
+.certaintrust-tviz-arcs path:hover {
+	stroke: skyblue;
+	stroke-width: 3;
+}

+ 328 - 0
JavaScript/JavaScript_SDK/certainTrustTViz.js

@@ -0,0 +1,328 @@
+/**
+ * CertainTrust SDK
+ *
+ * Implements the computational trust model "CertainTrust"
+ * in JavaScript.
+ * See <http://www.tk.informatik.tu-darmstadt.de/de/research/smart-security-and-trust/> for further details.
+ *
+ *
+ * Telecooperation Department, Technische Universität Darmstadt
+ * <http://www.tk.informatik.tu-darmstadt.de/>
+ *
+ * Prof. Dr. Max Mühlhäuser <max@informatik.tu-darmstadt.de>
+ * Florian Volk <florian.volk@cased.de>
+ *
+ *
+ * @author	Daniel Dieth
+ * @author	David Kalnischkies
+ * @author	Maria Pelevina
+ * @version	1.0
+ */
+
+ /* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+//##########################################################################################
+// CertainTrustTViz constructor
+//##########################################################################################
+var CertainTrustTViz = function(data, config) {
+	this.NR = CertainTrustTVizElement.length();
+	CertainTrustTVizElement.push(this);
+	this.certainTrusts = [];
+	this.add(data);
+
+	// set sane defaults for config if nothing is set
+	if (config === undefined) config = {};
+	if (config.id === undefined) config.id = 'certaintrust-tviz-' + this.NR;
+	// design your widget
+	if (config.canvas === undefined) config.canvas = {};
+	if (config.canvas.height === undefined) config.canvas.height = 440;
+	if (config.canvas.width === undefined) config.canvas.width = 440;
+	if (config.canvas.inner === undefined) config.canvas.inner = 30;
+	if (config.middle === undefined) config.middle = 'AVERAGE';
+	if (config.onClick === undefined) config.onClick = undefined;
+
+	this.ID = config.id;
+	this.config = config;
+
+	var element = document.createElement('div');
+	element.setAttribute('id', this.ID);
+	var dom = this.certainTrusts[0]._insertElement(config, element);
+
+	this.update();
+
+	if (dom !== undefined)
+		return dom;
+};
+CertainTrustTViz.prototype.update = function() {
+	var xmlns = 'http://www.w3.org/2000/svg';
+	var dotx = this.config.canvas.height / 2;
+	var doty = this.config.canvas.width / 2;
+	var rotate = 360 - 45;
+	var circle_y = this.config.canvas.inner;
+	var circle_height = dotx - (2 * circle_y);
+	var rotationstep = 360 / this.certainTrusts.length;
+
+	var element = document.getElementById(this.ID);
+
+	// see if we have to redraw thanks to an added/removed CertainTrust element
+	if (element.hasChildNodes() === true) {
+		var old_arcs = document.getElementById(this.ID + '-arcs');
+		if (old_arcs.childNodes.length !== this.certainTrusts.length)
+			element.removeChild(element.firstChild);
+	}
+
+	var arcs = document.createElementNS(xmlns, 'g');
+	arcs.setAttribute('stroke', 'none');
+	arcs.setAttribute('class', 'certaintrust-tviz-arcs');
+	arcs.setAttribute('id', this.ID + '-arcs');
+
+	// first time run or removed by the if above: full build
+	if (element.hasChildNodes() === false)
+	{
+		// prepare the various elements we need
+		var axes = document.createElementNS(xmlns, 'g');
+		axes.setAttribute('fill', 'none');
+		axes.setAttribute('stroke', 'grey');
+		axes.setAttribute('class', 'certaintrust-tviz-axes');
+		var desc = document.createElementNS(xmlns, 'g');
+		for (var a = 0; a < this.certainTrusts.length; ++a) {
+			var rotation = (rotate + (rotationstep * a)) % 360;
+			// an axis for each arc to show of how big each arc could be
+			var axis = this._generateAxis(xmlns, dotx, doty, circle_height, circle_y, rotation);
+			axes.appendChild(axis);
+			// the arc representing the CertainTrust element
+			var arc = this._generateArc(xmlns, this.certainTrusts[a], dotx, doty, circle_height, circle_y, rotation, rotationstep);
+			arcs.appendChild(arc);
+			// label for each arc
+			var label = this._generateArcLabel(xmlns, this.certainTrusts[a], dotx, doty, circle_height, circle_y, rotation, rotationstep);
+			desc.appendChild(label);
+		}
+		if (this.config.middle !== 'NONE') {
+			var total = this._generateTotalInTheMiddle(xmlns, dotx, doty);
+			desc.appendChild(total);
+		}
+		// draw circles to indicate how large the arcs could be
+		var circles = this._generateCircles(xmlns, circle_y, circle_height);
+		// our new tviz
+		var svg = document.createElementNS(xmlns, 'svg');
+		svg.setAttribute('height', this.config.canvas.height);
+		svg.setAttribute('width', this.config.canvas.width);
+		svg.appendChild(circles);
+		svg.appendChild(arcs);
+		svg.appendChild(axes);
+		svg.appendChild(desc);
+		// finally, insert tviz
+		element.appendChild(svg);
+	} else {
+		// we have most of the image, so just change what has changed
+		element = element.firstChild;
+		// get the new arcs set
+		for (var a = 0; a < this.certainTrusts.length; ++a) {
+			var rotation = (rotate + (rotationstep * a)) % 360;
+			var arc = this._generateArc(xmlns, this.certainTrusts[a], dotx, doty, circle_height, circle_y, rotation, rotationstep);
+			arcs.appendChild(arc);
+		}
+		// find the old arcs set and exchange it with the new set
+		var old_arcs = document.getElementById(this.ID + '-arcs');
+		element.insertBefore(arcs, old_arcs);
+		element.removeChild(old_arcs);
+		if (this.config.middle !== 'NONE') {
+			// and now change the text of label in the middle
+			var total = document.getElementById(this.ID + '-middle');
+			total.firstChild.nodeValue = this._calcMiddleLabel(this.certainTrusts);
+		}
+	}
+};
+CertainTrustTViz.prototype.add = function() {
+	for (var i = 0; i < arguments.length; ++i) {
+		var ct = arguments[i];
+		if (ct instanceof Array) {
+			for (var j = 0; j < ct.length; ++j) {
+				var c = ct[j];
+				this.certainTrusts.push(c);
+				c.addObserver(this);
+			}
+		} else {
+			this.certainTrusts.push(ct);
+			ct.addObserver(this);
+		}
+	}
+	// don't trigger on first call from constructor
+	if (this.ID !== undefined)
+		this.update();
+};
+CertainTrustTViz.prototype.remove = function() {
+	for (var i = 0; i < arguments.length; ++i) {
+		var ct = arguments[i];
+		if (ct instanceof CertainTrust) {
+			for (var j = 0; j < ct.length; ++j) {
+				for (var k = 0; k < this.certainTrusts.length; ++k) {
+					if (this.certainTrusts[k] !== ct[j])
+						continue;
+					ct[j].deleteObserver(this);
+					this.certainTrusts.splice(k, 1);
+					break;
+				}
+			}
+		} else {
+			for (var k = 0; k < this.certainTrusts.length; ++k) {
+				if (this.certainTrusts[k].getName() !== ct)
+					continue;
+				this.certainTrusts[k].deleteObserver(this);
+				this.certainTrusts.splice(k, 1);
+				break;
+			}
+		}
+	}
+	this.update();
+};
+CertainTrustTViz.prototype._generateAxis = function(xmlns, dotx, doty, circle_height, circle_y, rotation) {
+		var point = this.certainTrusts[0]._pointOnCircle(dotx, doty, rotation, circle_y);
+		var axis = document.createElementNS(xmlns, 'g');
+		axis.setAttribute('fill', 'none');
+		axis.setAttribute('stroke', 'grey');
+		var placement;
+		if (rotation >= 270 && rotation < 360 || rotation >= 0 && rotation < 90) {
+			axis.setAttribute('transform', 'translate(' + point[1] + ',' + point[0] + ') rotate(' + (rotation) + ')');
+			axis.setAttribute('class', 'certaintrust-tviz-axis-left');
+			placement = -1;
+		} else {
+			axis.setAttribute('transform', 'translate(' + point[1] + ',' + point[0] + ') rotate(' + (rotation - 180) + ')');
+			axis.setAttribute('class', 'certaintrust-tviz-axis-right');
+			placement = 1;
+		}
+		var axis_line = document.createElementNS(xmlns, 'line');
+		axis_line.setAttribute('fill', 'inherit');
+		axis_line.setAttribute('stroke', 'inherit');
+		axis_line.setAttribute('x1', 0);
+		axis_line.setAttribute('y1', 0);
+		axis_line.setAttribute('x2', 0);
+		axis_line.setAttribute('y2', placement * circle_height);
+		axis.appendChild(axis_line);
+		for (var t = 0; t < 6; ++t) {
+			var y = placement * (circle_height * (t / 5));
+			var tick_line = document.createElementNS(xmlns, 'line');
+			tick_line.setAttribute('fill', 'inherit');
+			tick_line.setAttribute('stroke', 'inherit');
+			tick_line.setAttribute('x1', 0);
+			tick_line.setAttribute('y1', y);
+			tick_line.setAttribute('x2', placement * 6);
+			tick_line.setAttribute('y2', y);
+			var tick_text = document.createElementNS(xmlns, 'text');
+			tick_text.setAttribute('fill', 'grey');
+			tick_text.setAttribute('x', placement * 9);
+			tick_text.setAttribute('y', y);
+			tick_text.setAttribute('dy', '.5em');
+			tick_text.setAttribute('font-size', '.5em');
+			var msg = document.createTextNode(t * 20);
+			tick_text.appendChild(msg);
+			var tick = document.createElementNS(xmlns, 'g');
+			tick.setAttribute('fill', 'inherit');
+			tick.setAttribute('stroke', 'inherit');
+			tick.appendChild(tick_line);
+			tick.appendChild(tick_text);
+			axis.appendChild(tick);
+		}
+	return axis;
+};
+CertainTrustTViz.prototype._generateArc = function(xmlns, certainTrust, dotx, doty, circle_height, circle_y, rotation, rotationstep) {
+	var arc_width = rotationstep * certainTrust.getC();
+	var arc_free = (rotationstep - arc_width) / 2;
+	var arc_low_left = certainTrust._pointOnCircle(dotx, doty, (rotation + arc_free), circle_y);
+	var arc_low_right = certainTrust._pointOnCircle(dotx, doty, (rotation + rotationstep - arc_free), circle_y);
+	var arc_height = (circle_height * certainTrust.getT()) + circle_y;
+	var arc_high_left = certainTrust._pointOnCircle(dotx, doty, (rotation + arc_free), arc_height);
+	var arc_high_right = certainTrust._pointOnCircle(dotx, doty, (rotation + rotationstep - arc_free), arc_height);
+	var color = certainTrust._getColor(certainTrust.getC(), certainTrust.getT(), certainTrust.getF());
+	var arc = document.createElementNS(xmlns, 'path');
+	arc.setAttribute('fill', 'rgb(' + Math.round(color[0]) + ',' + Math.round(color[1]) + ',' + Math.round(color[2]) + ')');
+	arc.setAttribute('stroke', 'inherit');
+	arc.setAttribute('d', 'M' + arc_low_left[1] + ' ' + arc_low_left[0] +
+		'A' + circle_y + ',' + circle_y + ' 0 0,1 ' + arc_low_right[1] + ',' + arc_low_right[0] +
+		'L' + arc_high_right[1] + ' ' + arc_high_right[0] +
+		'A' + arc_height + ',' + arc_height + ' 0 0,0 ' + arc_high_left[1] + ',' + arc_high_left[0] +
+		'z');
+	arc.setAttribute('title', 'Trust: ' + certainTrust.getT() + '\nCertainty: ' + certainTrust.getC());
+
+	if (this.config.onClick !== undefined)
+	{
+		var onClick = this.config.onClick;
+		arc.addEventListener("click", function(e) { onClick(certainTrust); }, false);
+	}
+	return arc;
+};
+CertainTrustTViz.prototype._generateArcLabel = function(xmlns, certainTrust, dotx, doty, circle_height, circle_y, rotation, rotationstep) {
+	var label = document.createElementNS(xmlns, 'text');
+	label.setAttribute('fill', 'black');
+	var outerpoint = this.certainTrusts[0]._pointOnCircle(dotx, doty, (rotation + (rotationstep / 2)), (circle_height + circle_y));
+	label.setAttribute('x', outerpoint[1]);
+	label.setAttribute('y', outerpoint[0]);
+	label.setAttribute('dy', '.5em');
+	label.setAttribute('text-anchor', 'middle');
+	var msg = document.createTextNode(certainTrust.getName());
+	label.appendChild(msg);
+	return label;
+};
+CertainTrustTViz.prototype._generateTotalInTheMiddle = function(xmlns, dotx, doty) {
+	var total = document.createElementNS(xmlns, 'text');
+	total.setAttribute('fill', 'grey');
+	total.setAttribute('x', dotx);
+	total.setAttribute('y', doty);
+	total.setAttribute('dy', '.5em');
+	total.setAttribute('text-anchor', 'middle');
+	total.setAttribute('id', this.ID + '-middle');
+	var msg = document.createTextNode(this._calcMiddleLabel(this.certainTrusts));
+	total.appendChild(msg);
+	return total;
+};
+CertainTrustTViz.prototype._generateCircles = function(xmlns, circle_y, circle_height) {
+	var circles = document.createElementNS(xmlns, 'g');
+	circles.setAttribute('fill', 'none');
+	circles.setAttribute('stroke', 'lightgrey');
+	circles.setAttribute('class', 'certaintrust-tviz-circles');
+	for (var i = 0; i < 11; ++i) {
+		var circle = document.createElementNS(xmlns, 'circle');
+		circle.setAttribute('cx', '50%');
+		circle.setAttribute('cy', '50%');
+		var r = circle_y + (circle_height * (i / 10));
+		circle.setAttribute('r', r);
+		circle.setAttribute('fill', 'inherit');
+		circle.setAttribute('stroke', 'inherit');
+		circles.appendChild(circle);
+	}
+	return circles;
+};
+// Calculate the average over all included CertainTrusts
+CertainTrustTViz.prototype._calcMiddleLabel = function(indata) {
+	if (this.config.middle === "NONE")
+		return "";
+	else if (this.config.middle === "AVERAGE") {
+		var avg = 0.0;
+		for (var i = 0; i < indata.length; i++) {
+			avg += indata[i].getExpectation();
+		}
+		return (Math.round(avg/indata.length*1000)/10) + "%";
+	} else if (this.config.middle === "AND") {
+		var result = indata[0];
+		for (var i = 1; i < indata.length; i++) {
+			result = result.AND(indata[i]);
+		}
+		return (Math.round(result.getExpectation()*1000)/10) + "%";
+	} else
+		return this.config.middle(indata);
+};
+// global var for storing and accessing all the widgets
+var CertainTrustTVizElement = { _elements: [],
+	ById: function(id) {
+		for (var i = 0; i < CertainTrustTVizElement._elements.length; ++i) {
+			if (CertainTrustTVizElement._elements[i].ID === id)
+				return CertainTrustTVizElement._elements[i];
+		}
+		return null;
+	},
+	ByNr: function(nr) { return CertainTrustTVizElement._elements[nr]; },
+	push: function(cte) { CertainTrustTVizElement._elements.push(cte); },
+	length: function() { return CertainTrustTVizElement._elements.length; }
+};

BIN
QuickStart.pdf


BIN
Tutorial.pdf