/// <summary> /// Add constraint of only 1 clock /// </summary> /// <param name="timer"></param> /// <param name="op"></param> /// <param name="constant"></param> public void AddConstraint(short timer, TimerOperationType op, int constant) { switch (op) { case TimerOperationType.Equals: AddConstraint(timer, 0, constant, LessThanEqual); AddConstraint(0, timer, -constant, LessThanEqual); break; case TimerOperationType.GreaterThanOrEqualTo: AddConstraint(0, timer, -constant, LessThanEqual); break; case TimerOperationType.LessThanOrEqualTo: AddConstraint(timer, 0, constant, LessThanEqual); break; case TimerOperationType.GreaterThan: AddConstraint(0, timer, -constant, LessThan); break; case TimerOperationType.LessThan: AddConstraint(timer, 0, constant, LessThan); break; } }
public void AddConstraint(short x, short y, TimerOperationType op, int constant) { Debug.Assert(x != y); Debug.Assert(x >= 0); Debug.Assert(y >= 0); switch (op) { case TimerOperationType.Equals: AddConstraint(x, y, false, constant); AddConstraint(y, x, false, -1 * constant); break; case TimerOperationType.GreaterThanOrEqualTo: AddConstraint(y, x, false, -1 * constant); break; case TimerOperationType.LessThanOrEqualTo: AddConstraint(x, y, false, constant); break; case TimerOperationType.GreaterThan: AddConstraint(y, x, true, -1 * constant); break; case TimerOperationType.LessThan: AddConstraint(x, y, true, constant); break; } }
/// <summary> /// Update the FullDBM with a new constraint /// </summary> /// <param name="timerID">which timer the constraint is on</param> /// <param name="op">0 for equal; 1 for >=; -1 for <=</param> /// <param name="constant"></param> public void AddConstraint(byte timer, TimerOperationType op, int constant) { Debug.Assert(timer > 0); int boundt0 = DBMConstraint.dbm_raw2bound(Matrix[timer * dimention + 0]); int bound0t = DBMConstraint.dbm_raw2bound(Matrix[0 * dimention + timer]); switch (op) { case TimerOperationType.Equals: if (boundt0 > constant) { Matrix[timer * dimention + 0] = DBMConstraint.dbm_bound2raw(constant, dbm_WEAK); } if (bound0t > -1 * constant) { Matrix[0 * dimention + timer] = DBMConstraint.dbm_bound2raw(-1 * constant, dbm_WEAK); } break; case TimerOperationType.GreaterThanOrEqualTo: if (bound0t > -1 * constant) { Matrix[0 * dimention + timer] = DBMConstraint.dbm_bound2raw(-1 * constant, dbm_WEAK); } break; case TimerOperationType.LessThanOrEqualTo: if (boundt0 > constant) { Matrix[timer * dimention + 0] = DBMConstraint.dbm_bound2raw(constant, dbm_WEAK); } break; case TimerOperationType.GreaterThan: if (bound0t > -1 * constant) { Matrix[0 * dimention + timer] = DBMConstraint.dbm_bound2raw(-1 * constant, dbm_STRICT); //MatrixStrictness[0 * dimention + timer] = true; } //ClockLowerValues[timer - 1] = Math.Max(constant, ClockLowerValues[timer - 1]); break; case TimerOperationType.LessThan: if (boundt0 > constant) { Matrix[timer * dimention + 0] = DBMConstraint.dbm_bound2raw(constant, dbm_STRICT); } break; } IsCanonicalForm = false; }
/// <summary> /// Check whether the DBM satisfies a given primitive constraint /// </summary> /// <param name="timerID"></param> /// <param name="op"></param> /// <param name="constant"></param> public bool Implies(int timerID, TimerOperationType op, int constant) { if (!IsCanonicalForm) { GetCanonicalForm(); } switch (op) { case TimerOperationType.Equals: return(Matrix[timerID][0] == constant && Matrix[0][timerID] == -1 * constant); case TimerOperationType.GreaterThanOrEqualTo: return(Matrix[0][timerID] <= -1 * constant); default: //TimerOperationType.LessThanOrEqualTo: return(Matrix[timerID][0] <= constant); } }
/// <summary> /// Add the clock constraint into the DBM, after adding the DBM is still in carnomical form /// </summary> /// <param name="timerID"></param> /// <param name="op"></param> /// <param name="constant"></param> public void AddConstraint(int timerID, TimerOperationType op, int constant) { Debug.Assert(timerID != 0); switch (op) { case TimerOperationType.Equals: AddConstraintXY(timerID, 0, constant); AddConstraintXY(0, timerID, -1 * constant); break; case TimerOperationType.GreaterThanOrEqualTo: AddConstraintXY(0, timerID, -1 * constant); break; case TimerOperationType.LessThanOrEqualTo: AddConstraintXY(timerID, 0, constant); break; } }
private static void AddConstraint(int[] valuation, short timer, TimerOperationType op, int constant) { switch (op) { case TimerOperationType.Equals: if (valuation[timer] != constant) { SetValuationEmpty(valuation); } break; case TimerOperationType.GreaterThanOrEqualTo: if (valuation[timer] < constant) { SetValuationEmpty(valuation); } break; case TimerOperationType.LessThanOrEqualTo: if (valuation[timer] > constant) { SetValuationEmpty(valuation); } break; case TimerOperationType.GreaterThan: if (valuation[timer] <= constant) { SetValuationEmpty(valuation); } break; case TimerOperationType.LessThan: if (valuation[timer] >= constant) { SetValuationEmpty(valuation); } break; } }
public void AddConstraint(short x, short y, TimerOperationType op, int constant, int[,] bound) { Debug.Assert(x != y); Debug.Assert(x >= 0); Debug.Assert(y >= 0); switch (op) { case TimerOperationType.Equals: AddConstraint(x, y, false, constant); AddConstraint(y, x, false, -1 * constant); break; case TimerOperationType.GreaterThanOrEqualTo: AddConstraint(y, x, false, -1 * constant); break; case TimerOperationType.LessThanOrEqualTo: AddConstraint(x, y, false, constant); break; case TimerOperationType.GreaterThan: AddConstraint(y, x, true, -1 * constant); break; case TimerOperationType.LessThan: AddConstraint(x, y, true, constant); break; } if (bound != null) { Extrapolation(bound); } IsCanonicalForm = true; }
/// <summary> /// Update the FullDBM with a new constraint /// </summary> /// <param name="timer">which timer the constraint is on</param> /// <param name="op">0 for equal; 1 for >=; -1 for <=</param> /// <param name="constant"></param> public void AddConstraint(short timer, TimerOperationType op, int constant) { Debug.Assert(timer > 0); if (Matrix[timer * dimention] != int.MaxValue && Matrix[timer] != int.MaxValue && Matrix[timer * dimention] + Matrix[timer] < 0) { IsCanonicalForm = true; Matrix[0] = -1; return; } switch (op) { case TimerOperationType.Equals: if (Matrix[timer * dimention] > constant) { Matrix[timer * dimention] = constant; MatrixStrictness[timer * dimention] = false; } if (Matrix[timer] > -1 * constant) { Matrix[timer] = -1 * constant; MatrixStrictness[timer] = false; } break; case TimerOperationType.GreaterThanOrEqualTo: if (Matrix[timer] > -1 * constant) { Matrix[timer] = -1 * constant; MatrixStrictness[timer] = false; } break; case TimerOperationType.LessThanOrEqualTo: if (Matrix[timer * dimention] > constant) { Matrix[timer * dimention] = constant; MatrixStrictness[timer * dimention] = false; } break; case TimerOperationType.GreaterThan: if (Matrix[timer] >= -1 * constant) { Matrix[timer] = -1 * constant; MatrixStrictness[timer] = true; } break; case TimerOperationType.LessThan: if (Matrix[timer * dimention] >= constant) { Matrix[timer * dimention] = constant; MatrixStrictness[timer * dimention] = true; } break; } for (int i = 0; i < dimention; i++) { for (int j = 0; j < dimention; j++) { if (Matrix[i * dimention + timer] != int.MaxValue && Matrix[timer * dimention + j] != int.MaxValue) { if (Matrix[i * dimention + j] > Matrix[i * dimention + timer] + Matrix[timer * dimention + j]) { Matrix[i * dimention + j] = Matrix[i * dimention + timer] + Matrix[timer * dimention + j]; MatrixStrictness[i * dimention + j] = MatrixStrictness[i * dimention + timer] || MatrixStrictness[timer * dimention + j]; } else if (Matrix[i * dimention + j] == Matrix[i * dimention + timer] + Matrix[timer * dimention + j]) { MatrixStrictness[i * dimention + j] = MatrixStrictness[i * dimention + j] || (MatrixStrictness[i * dimention + timer] || MatrixStrictness[timer * dimention + j]); } } if (Matrix[i * dimention] != int.MaxValue && Matrix[j] != int.MaxValue) { if (Matrix[i * dimention + j] > Matrix[i * dimention] + Matrix[j]) { Matrix[i * dimention + j] = Matrix[i * dimention] + Matrix[j]; MatrixStrictness[i * dimention + j] = MatrixStrictness[i * dimention] || MatrixStrictness[j]; } else if (Matrix[i * dimention + j] == Matrix[i * dimention] + Matrix[j]) { MatrixStrictness[i * dimention + j] = MatrixStrictness[i * dimention + j] || (MatrixStrictness[i * dimention] || MatrixStrictness[j]); } } } if (Matrix[i * dimention + i] < 0 || MatrixStrictness[0]) { IsCanonicalForm = true; Matrix[0] = -1; return; } } Extrapolation(); IsCanonicalForm = true; }
/// <summary> /// Suppose that in the set of added constraints does not contain conflict /// </summary> /// <param name="valuation"></param> /// <param name="timer"></param> /// <param name="op"></param> /// <param name="constant"></param> public static void UpdateToSmallestSatisfyingValuation(int[] valuation, short timer, TimerOperationType op, int constant) { switch (op) { case TimerOperationType.Equals: if (valuation[timer] > constant) { SetValuationEmpty(valuation); } else { int increasing = constant - valuation[timer]; if (increasing > 0) { for (int i = 1; i < valuation.Length; i++) { valuation[i] += increasing; } } } break; case TimerOperationType.GreaterThanOrEqualTo: if (valuation[timer] < constant) { int increasing = constant - valuation[timer]; if (increasing > 0) { for (int i = 1; i < valuation.Length; i++) { valuation[i] += increasing; } } } break; case TimerOperationType.LessThanOrEqualTo: if (valuation[timer] > constant) { SetValuationEmpty(valuation); } break; case TimerOperationType.GreaterThan: if (valuation[timer] < constant + 1) { int increasing = (constant + 1) - valuation[timer]; if (increasing > 0) { for (int i = 1; i < valuation.Length; i++) { valuation[i] += increasing; } } } break; case TimerOperationType.LessThan: if (valuation[timer] >= constant - 1) { SetValuationEmpty(valuation); } break; } }
private static void AddConstraint(int[] valuation, short timer, TimerOperationType op, int constant) { switch (op) { case TimerOperationType.Equals: if( valuation[timer] != constant) { SetValuationEmpty(valuation); } break; case TimerOperationType.GreaterThanOrEqualTo: if(valuation[timer] < constant) { SetValuationEmpty(valuation); } break; case TimerOperationType.LessThanOrEqualTo: if(valuation[timer] > constant) { SetValuationEmpty(valuation); } break; case TimerOperationType.GreaterThan: if(valuation[timer] <= constant) { SetValuationEmpty(valuation); } break; case TimerOperationType.LessThan: if(valuation[timer] >= constant) { SetValuationEmpty(valuation); } break; } }
/// <summary> /// Suppose that in the set of added constraints does not contain conflict /// </summary> /// <param name="valuation"></param> /// <param name="timer"></param> /// <param name="op"></param> /// <param name="constant"></param> public static void UpdateToSmallestSatisfyingValuation(int[] valuation, short timer, TimerOperationType op, int constant) { switch (op) { case TimerOperationType.Equals: if (valuation[timer] > constant) { SetValuationEmpty(valuation); } else { int increasing = constant - valuation[timer]; if(increasing > 0) { for(int i = 1; i < valuation.Length; i++) { valuation[i] += increasing; } } } break; case TimerOperationType.GreaterThanOrEqualTo: if (valuation[timer] < constant) { int increasing = constant - valuation[timer]; if (increasing > 0) { for (int i = 1; i < valuation.Length; i++) { valuation[i] += increasing; } } } break; case TimerOperationType.LessThanOrEqualTo: if (valuation[timer] > constant) { SetValuationEmpty(valuation); } break; case TimerOperationType.GreaterThan: if (valuation[timer] < constant + 1) { int increasing = (constant + 1)- valuation[timer]; if (increasing > 0) { for (int i = 1; i < valuation.Length; i++) { valuation[i] += increasing; } } } break; case TimerOperationType.LessThan: if (valuation[timer] >= constant - 1) { SetValuationEmpty(valuation); } break; } }
/// <summary> /// Check whether the DBM satisfies a given primitive constraint /// </summary> /// <param name="timerID"></param> /// <param name="op"></param> /// <param name="constant"></param> public bool Implies(int timerID, TimerOperationType op, int constant) { if (!IsCanonicalForm) { GetCanonicalForm(); } switch (op) { case TimerOperationType.Equals: return Matrix[timerID][0] == constant && Matrix[0][timerID] == -1 * constant; case TimerOperationType.GreaterThanOrEqualTo: return Matrix[0][timerID] <= -1 * constant; default: //TimerOperationType.LessThanOrEqualTo: return Matrix[timerID][0] <= constant; } }
/// <summary> /// Add the clock constraint into the DBM, after adding the DBM is still in carnomical form /// </summary> /// <param name="timerID"></param> /// <param name="op"></param> /// <param name="constant"></param> public void AddConstraint(int timerID, TimerOperationType op, int constant) { Debug.Assert(timerID != 0); switch (op) { case TimerOperationType.Equals: AddConstraintXY(timerID, 0, constant); AddConstraintXY(0, timerID, -1*constant); break; case TimerOperationType.GreaterThanOrEqualTo: AddConstraintXY(0, timerID, -1 * constant); break; case TimerOperationType.LessThanOrEqualTo: AddConstraintXY(timerID, 0, constant); break; } }