Browse Source

CertainTrust.js updated in JavaScript examples

Debashis Chandra Ray 6 years ago
parent
commit
58d6b2f0ee
1 changed files with 11 additions and 8 deletions
  1. 11 8
      JavaScript/JavaScript_Examples/CertainTrust.js

+ 11 - 8
JavaScript/JavaScript_Examples/CertainTrust.js

@@ -449,6 +449,13 @@ CertainTrust.prototype._internalFusion = function(args, weights, doc) {
 			atLeastOne1 = true;
 			i = arrLength;
 		}
+		
+	if(atLeastOne1 && !allOne){
+		for (i = 0; i < arrLength; ++i)
+		if (args[i].getC() === 1) {
+			args[i].setTC(args[i].getT(),0.99999);
+		}
+	}
 
 	//Calculate T and C
 
@@ -469,9 +476,6 @@ CertainTrust.prototype._internalFusion = function(args, weights, doc) {
 			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;
@@ -498,7 +502,6 @@ CertainTrust.prototype._internalFusion = function(args, weights, doc) {
 			// Special case for T
 			if (allZero)
 				resT = 0.5;
-		}
 	}
 
 	// Calculate F
@@ -601,7 +604,7 @@ CertainTrust.prototype._calculateRStoTC = function() {
 	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;
+		this.t = 0;
 	else
 		this.t = this.r / rs;
 };
@@ -614,7 +617,7 @@ CertainTrust.prototype._calculateTCtoRS = function() {
 	if (this._almostEqual(this.c, 0)) {
 		this.r = 0;
 		this.s = 0;
-		this.t = 0.5;
+		this.t = 0;
 	}
 	else {
 		var c2w = this.c * 2 * this.weight;
@@ -1005,12 +1008,12 @@ CertainTrust.prototype._singleDISCOUNTING = function(arg){
 	var f2 = arg.getF();
 	var t2 = arg.getT();
 
-	var resC = 0, resT = 0.5, resF = 0.5;
+	var resC = 0, resT = 0, resF = 0;
 
 	if (!this._operationAllowed(this, arg))
 		return undefined;
 
-	//resF = f1*f2;
+	resF = f2;
 	if (this._almostEqual(resF, 1))		//avoid division by 0
 		resC = t1*c1*c2;
 	else