public DBM Clone() { if (TimerArray == null) { return new DBM(Ceiling); } List<List<int>> newMatrix = new List<List<int>>(); for (int i = 0; i < Matrix.Count; i++) { List<int> newRow = new List<int>(); for (int j = 0; j < Matrix.Count; j++) { newRow.Add(Matrix[i][j]); } newMatrix.Add(newRow); } return new DBM(new List<int>(this.TimerArray), newMatrix, IsCanonicalForm); }
public DBM KeepTimers(int[] activeTimer) { Contract.Requires(this.IsCanonicalForm, "Keep Timers Failure"); List<int> idArray = new List<int>(); List<List<int>> newMatrix = new List<List<int>>(4); List<int> temp = new List<int>(); temp.Add(0); foreach (int timerID in activeTimer) { int timerIndex = this.TimerArray.IndexOf(timerID) + 1; idArray.Add(timerID); temp.Add(timerIndex); } foreach (int i in temp) { List<int> constantRow = new List<int>(4); foreach (int j in temp) { constantRow.Add(Matrix[i][j]); } newMatrix.Add(constantRow); } return new DBM(idArray, newMatrix, true); }
/// <summary> /// Add a new timer id /// </summary> /// <param name="timerID"></param> public void AddTimer(int timerID) { Contract.Ensures(IsCanonicalForm, "Add Timer Failure: DBM is not in Canonical Form!"); if (TimerArray == null) { //initialize the system TimerArray = new List<int>(4); Matrix = new List<List<int>>(4); List<int> constantRow = new List<int>(4); constantRow.Add(0); Matrix.Add(constantRow); } else { if (TimerArray.Contains(timerID)) { if (!this.IsCanonicalForm) { this.GetCanonicalForm(); } return; } /************************************** //add the last column to be maxvalue Matrix[0].Add(0); for (int i = 1; i < Matrix.Count; i++) { //Matrix[i].Add(int.MaxValue); Matrix[i].Add(Matrix[i][0]); } ***************************************/ } if (!this.IsCanonicalForm) { this.GetCanonicalForm(); } Matrix[0].Add(0); for (int i = 1; i < Matrix.Count; i++) { Matrix[i].Add(Matrix[i][0]); } TimerArray.Add(timerID); List<int> newTimerRow = new List<int>(Matrix[0].Count); //the last row are all 0 //newTimerRow.AddRange(new int[TimerArray.Count + 1]); for (int i = 0; i < Matrix[0].Count; i++) { newTimerRow.Add(Matrix[0][i]); } //add the last row Matrix.Add(newTimerRow); }