public int[] GetPath(int n, IMeasure measure) { var result = new int[n]; result[0] = 0; var v = new bool[n]; v[0] = true; for (int k = 1; k < n; k++) { var prev = result[k - 1]; int next = -1; double bestCost = 0; for (int i = 0; i < n; i++) { if (!v[i]) { if (next == -1 || bestCost > measure[prev, i]) { next = i; bestCost = measure[prev, i]; } } } result[k] = next; v[next] = true; } return result; }
public override int[] GetPath(int n, IMeasure measure) { stopwatch = Stopwatch.StartNew(); timelimit = (int)(RunProperties.RunTimeInSeconds * 1000); cycle = 0; timeout = false; bestPath = null; bestLength = 1e30; totalCount = 0; S = new bool[n, n]; var threads = new Thread[ThreadCount]; for (int t = 0; t < ThreadCount; t++) { threads[t] = new Thread(() => RunSearch(n, measure)); } for (int i = 0; i < ThreadCount; i++) { threads[i].Start(); } for (int i = 0; i < ThreadCount; i++) { threads[i].Join(); } return bestPath; }
public override bool TestInput(IMeasure measure) { CheckInput(measure); // SSIDs have not a standard character set if (Ssid.Equals(measure.Ssid, StringComparison.Ordinal)) { // if not enough stable (and if N = 1 then stdDev = 0) if (N < StableN) { return true; } double dist = Math.Abs((measure.SignalQuality - Mean)); double range = K * StdDev; // if stdDev < misure error (input is uint) if (range.CompareTo(SignalQualityUnit) > 0) { return (dist.CompareTo(range) <= 0); //double safe comparison } else { return (dist.CompareTo(SignalQualityUnit) <= 0); } } return false; }
public override int[] GetPath(int n, IMeasure measure) { var edges = new List<Edge>((n * (n - 1)) % 2); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { edges.Add(new Edge(i, j)); } } var set = new DisjointSetUnion<int>(); for (int i = 0; i < n; i++) { set.MakeSet(i); } var result = new List<Edge>(n - 1); var r = new int[n]; foreach (var edge in edges.OrderBy(a => measure[a.From, a.To])) { if (r[edge.From] < 2 && r[edge.To] < 2 && set.FindSet(edge.From) != set.FindSet(edge.To)) { result.Add(edge); set.UnionSets(edge.From, edge.To); r[edge.From]++; r[edge.To]++; } } return GetResult(n, result); }
public GaussianNetwork(IMeasure measure) : base(measure) { CheckInput(measure); _mean = measure.SignalQuality; _s = 0D; _n = 1; }
public override int[] GetPath(int n, IMeasure measure) { var e = new List<int>[n]; for (int i = 0; i < n; i++) { e[i] = new List<int>(); } var d = new double[n]; for (int i = 0; i < n; i++) { d[i] = double.MaxValue; } var s = new Random().Next(n); d[s] = 0; var v = new bool[n]; var p = new int[n]; for (int i = 0; i < n; i++) { p[i] = -1; } for (int k = 0; k < n; k++) { var mini = -1; for (int i = 0; i < n; i++) { if (!v[i] && (mini == -1 || d[i] < d[mini])) { mini = i; } } if (p[mini] != -1) { e[mini].Add(p[mini]); e[p[mini]].Add(mini); } v[mini] = true; for (int i = 0; i < n; i++) { if (!v[i] && d[i] > measure[mini, i]) { d[i] = measure[mini, i]; p[i] = mini; } } } v = new bool[n]; var path = new List<int>(); BuildPath(s, e, v, path); return path.ToArray(); }
protected static double CalcLength(int[] path, IMeasure measure) { var n = path.Length; var length = measure[path[n - 1], path[0]]; for (int i = 0; i < n - 1; i++) { length += measure[path[i], path[i + 1]]; } return length; }
/// <summary> /// Adds a new measure item to the list /// </summary> /// <param name="measure"></param> public void AddMeasure(IMeasure measure) { //add a new sorted list if neccesary if (!this.Rows.ContainsKey(measure.DateTime)) { this.Rows.Add(measure.DateTime, new KwhTableRow(measure.DateTime)); } //Add the measure this.Rows[measure.DateTime].kwhValues.Add(measure); _count++; //Add the inverter to the Inverter List if neccessary if (!this._knownInverterIDs.ContainsKey(measure.PrivateInverterId)) { this._knownInverterIDs.Add(measure.PrivateInverterId, measure.PublicInverterId); } }
public override int[] GetPath(int n, IMeasure measure) { var baseState = new GenerationState { C = new double[n,n], Edges = new List<Edge>(n), N = n, VertexSet = new int[n] }; baseState.C = measure.GetMatrix(); for (int i = 0; i < n; i++) { baseState.C[i, i] = Inf; } baseState.J = ReductMatrix(n, baseState.C); for (int i = 0; i < n; i++) { baseState.VertexSet[i] = i; } var queue = new PriorityQueue<GenerationState>((a, b) => -a.J.CompareTo(b.J)); queue.Enqueue(baseState); while (queue.Count > 0) { var current = queue.Dequeue(); if (current.Edges.Count == n - 1) { var result = GetResult(n, current.Edges); return result; } Process(current, queue); } throw new ApplicationException("Path not found"); }
/// <summary> /// Creates a new MeasureResult /// </summary> /// <param name="measure"></param> /// <param name="init"></param> public DoubleMeasureResult(IMeasure measure, double init) { this._value = init; this.Measure = measure; this.Count = 0; }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> /// <param name="other">An object to compare with this object.</param> bool IEquatable <IMeasure> .Equals(IMeasure other) { return(this.Equals(other as IMeasure <SurfaceTension>)); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> /// <param name="other">An object to compare with this object.</param> bool IEquatable <IMeasure> .Equals(IMeasure other) { return(this.Equals(other as IMeasure <Meterset>)); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> /// <param name="other">An object to compare with this object.</param> bool IEquatable <IMeasure> .Equals(IMeasure other) { return(this.Equals(other as IMeasure <ElectricResistance>)); }
private void RunSearch(int n, IMeasure measure) { var rnd = new Random(); while (!timeout) { // Generate random path //var p = new[] {1, 3, 2, 0}; var p = Permutations.GetRandomPermutation(n); var path = new UniversalNode[n]; for (int i = 0; i < n - 1; i++) { path[p[i]].Right = p[i + 1]; } for (int i = 1; i < n; i++) { path[p[i]].Left = p[i - 1]; } path[p[0]].Left = p[n - 1]; path[p[n - 1]].Right = p[0]; /*var pst = 0; var st = path[0].Left;*/ int q = totalCount > 0 ? 1 : 0; while (true) { // init var i = rnd.Next(n); var inext = path[i].Left; var ipr = path[i].Next(inext); int jpr = 0; int j = 0; int jnext = 0; int kpr = 0; int k = 0; int knext = 0; int trType = -1; var found = false; for (int icount = 0; icount < n; icount++) { // iterate ipr = i; i = inext; inext = path[i].Next(ipr); if (q == 1 && S[i, inext]) { continue; } // init j = inext; jnext = i; jpr = path[j].Next(jnext); for (int jcount = 0; jcount < n - 3; jcount++) { // iterate jpr = j; j = jnext; jnext = path[j].Next(jpr); cycle++; if (cycle >= ThreadCount * 10000) { lock (_lockStopwatch) { stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds > timelimit) { timeout = true; break; } cycle = 0; stopwatch.Start(); } } /*// run 2-opt if (inext != j && jnext != i) { if (measure[i, inext] + measure[j, jnext] > measure[i, j] + measure[inext, jnext]) { found = true; break; } }*/ // run 3-opt // init kpr = jpr; k = j; knext = jnext; for (int kcount = 0; kcount < n - 3 - jcount; kcount++) { // iterate kpr = k; k = knext; knext = path[k].Next(kpr); double d; if (measure[inext, k] + measure[i, jnext] <= measure[inext, jnext] + measure[i, k]) { d = measure[inext, k] + measure[i, jnext]; trType = 0; } else { d = measure[inext, jnext] + measure[i, k]; trType = 1; } if (d + measure[j, knext] < measure[i, inext] + measure[j, jnext] + measure[k, knext]) { found = true; break; } // TODO: need more condition? /*if (inext != j && jnext != k && knext != i) { if (measure[i, inext] + measure[j, jnext] + measure[k, knext] > measure[i, jnext] + measure[j, knext] + measure[k, inext]) { trType = 0; found = true; break; } if (measure[i, inext] + measure[j, jnext] + measure[k, knext] > measure[i, jnext] + measure[j, k] + measure[inext, knext]) { trType = 1; found = true; break; } }*/ } /*if (found) { break; } k = -1;*/ if (timeout || found) { break; } /*if (i == st) { break; }*/ } if (timeout || found) { break; } } if (!found) { if (q == 1) { q = 0; continue; } break; } //var inext2 = path[inext].Next(i); //var jprev = path[j].Next(jnext); if (k < 0) { path[i].Change(inext, j); path[j].Change(jnext, i); path[inext].Change(i, jnext); path[jnext].Change(j, inext); } else { if (trType == 0) { path[i].Change(inext, jnext); path[j].Change(jnext, knext); path[k].Change(knext, inext); path[inext].Change(i, k); path[jnext].Change(j, i); path[knext].Change(k, j); } else { path[i].Change(inext, k); path[j].Change(jnext, knext); path[k].Change(knext, i); path[inext].Change(i, jnext); path[jnext].Change(j, inext); path[knext].Change(k, j); } } // heuristic shift /*var sttmp = st; st = path[st].Next(pst); pst = sttmp;*/ } var tpr = 0; var t = path[0].Right; p[0] = 0; var count = 1; while (t != 0) { p[count] = t; count++; var tmp = t; t = path[t].Next(tpr); tpr = tmp; } S[p[0], p[n - 1]] = true; S[p[n - 1], p[0]] = true; for (int i = 0; i < n - 1; i++) { S[p[i], p[i + 1]] = true; S[p[i + 1], p[i]] = true; } var l = CalcLength(p, measure); lock (_lockUpdateBest) { if (l < bestLength) { bestLength = l; bestPath = p; } } lock (_lockTotalCount) { totalCount++; } } }
public int[] GetPath(int n, IMeasure measure) { //var p = Permutations.GetRandomPermutation(n); var p = new Greedy2().GetPath(n, measure); //p = new[] {1, 3, 2, 0}; var path = new PathNode[n]; for (int i = 0; i < n - 1; i++) { path[p[i]].Next = p[i + 1]; } for (int i = 1; i < n; i++) { path[p[i]].Prev = p[i - 1]; } path[p[0]].Prev = p[n - 1]; path[p[n - 1]].Next = p[0]; double l = 0; var bestPath = new int[n]; var t = 0; var count = 0; while (true) { bestPath[count] = t; count++; l += measure[t, path[t].Next]; t = path[t].Next; if (t == 0) { break; } } var bestL = l; var rnd = new Random(); var T = 40; var tabu = new int[n,n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { tabu[i, j] = int.MinValue; } } var stopwatch = Stopwatch.StartNew(); var maxCycles = 100000; var timelimit = 1; for (int cycle = 0; ; cycle++) { if (cycle % 10000 == 0) { stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds > timelimit * 1000) { break; } stopwatch.Start(); } var bestx = 0; var besty = 0; double bestDelta = -1e10; int xprev; int xnext; int yprev; int ynext; for (int k = 0; k < n * 10; k++) { var x = rnd.Next(n); var y = rnd.Next(n - 1); //x = 1; //y = 0; if (y >= x) y++; xprev = path[x].Prev != y ? path[x].Prev : x; xnext = path[x].Next != y ? path[x].Next : x; yprev = path[y].Prev != x ? path[y].Prev : y; ynext = path[y].Next != x ? path[y].Next : y; var delta = measure[path[x].Prev, x] + measure[x, path[x].Next] + measure[path[y].Prev, y] + measure[y, path[y].Next] - (measure[xprev, y] + measure[y, xnext] + measure[yprev, x] + measure[x, ynext]); if (l - delta > bestL) { if (tabu[x, y] + T >= cycle) { continue; } } if (delta > bestDelta) { bestDelta = delta; bestx = x; besty = y; } if (delta > 0) { break; } } l -= bestDelta; xprev = path[bestx].Prev;// != besty ? path[bestx].Prev : bestx; xnext = path[bestx].Next;// != besty ? path[bestx].Next : bestx; yprev = path[besty].Prev;// != bestx ? path[besty].Prev : besty; ynext = path[besty].Next;// != bestx ? path[besty].Next : besty; path[xprev].Next = besty; path[xnext].Prev = besty; path[yprev].Next = bestx; path[ynext].Prev = bestx; var tmp = path[bestx].Prev; path[bestx].Prev = path[besty].Prev; path[besty].Prev = tmp; tmp = path[bestx].Next; path[bestx].Next = path[besty].Next; path[besty].Next = tmp; tabu[besty, bestx] = cycle; if (l < bestL) { bestL = l; t = 0; count = 0; while (true) { bestPath[count] = t; count++; t = path[t].Next; if (t == 0) { break; } } } } return bestPath; }
public abstract int[] GetPath(int n, IMeasure measure);
/// <summary> /// Initializes a angular velocity object from an object implementing the IMeasure<AngularVelocity> interface /// </summary> /// <param name="other">Object implemeting the IMeasure<AngularVelocity> interface</param> public AngularVelocity(IMeasure <AngularVelocity> other) : this(other.StandardAmount) { }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> /// <param name="other">An object to compare with this object.</param> bool IEquatable <IMeasure> .Equals(IMeasure other) { return(this.Equals(other as IMeasure <AngularVelocity>)); }
/// <summary> /// Initializes a dynamic viscosity object from an object implementing the IMeasure<DynamicViscosity> interface /// </summary> /// <param name="other">Object implemeting the IMeasure<DynamicViscosity> interface</param> public DynamicViscosity(IMeasure <DynamicViscosity> other) : this(other.StandardAmount) { }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> /// <param name="other">An object to compare with this object.</param> bool IEquatable <IMeasure> .Equals(IMeasure other) { return(this.Equals(other as IMeasure <DynamicViscosity>)); }
/// <summary> /// Initializes a inductance object from an object implementing the IMeasure<Inductance> interface /// </summary> /// <param name="other">Object implemeting the IMeasure<Inductance> interface</param> public Inductance(IMeasure <Inductance> other) : this(other.StandardAmount) { }
/// <summary> /// Initializes a length object from an object implementing the IMeasure<Length> interface /// </summary> /// <param name="other">Object implemeting the IMeasure<Length> interface</param> public Length(IMeasure <Length> other) : this(other.StandardAmount) { }
/// <summary> /// Initializes a solid angle object from an object implementing the IMeasure<SolidAngle> interface /// </summary> /// <param name="other">Object implemeting the IMeasure<SolidAngle> interface</param> public SolidAngle(IMeasure <SolidAngle> other) : this(other.StandardAmount) { }
/// <summary> /// Creates a new MeasureResult /// </summary> /// <param name="measure"></param> /// <param name="init"></param> public TimeSpanMeasureResult(IMeasure measure, TimeSpan init) { this._value = init; this.Measure = measure; this.Count = 0; }
public abstract IMeasureBasic calculate(IMeasure second, operation op);
/// <summary> /// Multiply two measures, each raised to a specific power, to return a resulting measure of a specified quantity /// </summary> /// <typeparam name="Q">Quantity type of resulting measure</typeparam> /// <typeparam name="Q1">Quantity type of first factor</typeparam> /// <typeparam name="Q2">Quantity type of second factor</typeparam> /// <param name="iFirst">First measure to raise and multiply</param> /// <param name="iFirstExponent">Exponent to which the first measure should be raised</param> /// <param name="iSecond">Second measure to raise and multiply</param> /// <param name="iSecondExponent">Exponent to which the second measure should be raised</param> /// <param name="oResult">Measure resulting from multiplication, given in standard unit of quantity</param> public static void Product <Q, Q1, Q2>(IMeasure <Q1> iFirst, int iFirstExponent, IMeasure <Q2> iSecond, int iSecondExponent, out StandardMeasure <Q> oResult) where Q : struct, IQuantity <Q> where Q1 : struct, IQuantity <Q1> where Q2 : struct, IQuantity <Q2> { AssertMatchingQuantities <Q, Q1, Q2>(iFirstExponent, iSecondExponent); #if DOUBLE oResult = new StandardMeasure <Q>(Math.Pow(iFirst.StandardAmount, iFirstExponent) * Math.Pow(iSecond.StandardAmount, iSecondExponent)); #else oResult = new StandardMeasure <Q>(Math.Pow((double)iFirst.StandardAmount, iFirstExponent) * Math.Pow((double)iSecond.StandardAmount, iSecondExponent)); #endif }
internal static Dictionary<string, Dictionary<string, Dictionary<string, RelativeEffectivenessEstimate>>> GetSystemSystemQueryRelatives( Dictionary<string, Dictionary<string, Run>> sqRuns, IMeasure measure, IRelevanceEstimator relEstimator, IConfidenceEstimator confEstimator) { Dictionary<string, Dictionary<string, Dictionary<string, RelativeEffectivenessEstimate>>> ssqRelEstimates = new Dictionary<string, Dictionary<string, Dictionary<string, RelativeEffectivenessEstimate>>>(); // [sysA [sysB [query rel]]] string[] allSystems = sqRuns.Keys.ToArray(); Parallel.For(0, allSystems.Length - 1, i => { string sysA = allSystems[i]; var runsA = sqRuns[sysA]; Dictionary<string, Dictionary<string, RelativeEffectivenessEstimate>> sqRelEstimates = new Dictionary<string, Dictionary<string, RelativeEffectivenessEstimate>>(); for (int j = i + 1; j < allSystems.Length; j++) { Dictionary<string, RelativeEffectivenessEstimate> qRelEstimates = new Dictionary<string, RelativeEffectivenessEstimate>(); string sysB = allSystems[j]; var runsB = sqRuns[sysB]; foreach (var qRun in runsA) { qRelEstimates.Add(qRun.Key, measure.Estimate(qRun.Value, runsB[qRun.Key], relEstimator, confEstimator)); } sqRelEstimates.Add(sysB, qRelEstimates); } lock (ssqRelEstimates) { ssqRelEstimates.Add(sysA, sqRelEstimates); } }); //for (int i = 0; i < allSystems.Length - 1; i++) { // string sysA = allSystems[i]; // var runsA = sqRuns[sysA]; // Dictionary<string, Dictionary<string, RelativeEffectivenessEstimate>> sqRelEstimates = new Dictionary<string, Dictionary<string, RelativeEffectivenessEstimate>>(); // for (int j = i + 1; j < allSystems.Length; j++) { // Dictionary<string, RelativeEffectivenessEstimate> qRelEstimates = new Dictionary<string, RelativeEffectivenessEstimate>(); // string sysB = allSystems[j]; // var runsB = sqRuns[sysB]; // foreach (var qRun in runsA) { // qRelEstimates.Add(qRun.Key, measure.Estimate(qRun.Value, runsB[qRun.Key], relEstimator, confEstimator)); // } // sqRelEstimates.Add(sysB, qRelEstimates); // } // ssqRelEstimates.Add(sysA, sqRelEstimates); //} return ssqRelEstimates; }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> /// <param name="other">An object to compare with this object.</param> bool IEquatable <IMeasure> .Equals(IMeasure other) { return(this.Equals(other as IMeasure <ElectricCharge>)); }
private static DateTime ExtractHourDateTime(IMeasure lastMeasure) { DateTime last = lastMeasure.DateTime; return new DateTime(last.Year, last.Month, last.Day, last.Hour, 0, 0); }
/// <summary> /// Initializes a electric charge object from an object implementing the IMeasure<ElectricCharge> interface /// </summary> /// <param name="other">Object implemeting the IMeasure<ElectricCharge> interface</param> public ElectricCharge(IMeasure <ElectricCharge> other) : this(other.StandardAmount) { }
public virtual Network CreateNetwork(IMeasure measure) { return new GaussianNetwork(measure); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> /// <param name="other">An object to compare with this object.</param> bool IEquatable <IMeasure> .Equals(IMeasure other) { return(this.Equals(other as IMeasure <Force>)); }
/// <summary> /// Initializes a electric resistance object from an object implementing the IMeasure<ElectricResistance> interface /// </summary> /// <param name="other">Object implemeting the IMeasure<ElectricResistance> interface</param> public ElectricResistance(IMeasure <ElectricResistance> other) : this(other.StandardAmount) { }
/// <summary> /// Initializes a force object from an object implementing the IMeasure<Force> interface /// </summary> /// <param name="other">Object implemeting the IMeasure<Force> interface</param> public Force(IMeasure <Force> other) : this(other.StandardAmount) { }
/// <summary> /// Initializes a meterset object from an object implementing the IMeasure<Meterset> interface /// </summary> /// <param name="other">Object implemeting the IMeasure<Meterset> interface</param> public Meterset(IMeasure <Meterset> other) : this(other.StandardAmount) { }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> /// <param name="other">An object to compare with this object.</param> bool IEquatable <IMeasure> .Equals(IMeasure other) { return(this.Equals(other as IMeasure <MagneticFieldStrength>)); }
/// <summary> /// Initializes a surface tension object from an object implementing the IMeasure<SurfaceTension> interface /// </summary> /// <param name="other">Object implemeting the IMeasure<SurfaceTension> interface</param> public SurfaceTension(IMeasure <SurfaceTension> other) : this(other.StandardAmount) { }
/// <summary> /// Initializes a magnetic field strength object from an object implementing the IMeasure<MagneticFieldStrength> interface /// </summary> /// <param name="other">Object implemeting the IMeasure<MagneticFieldStrength> interface</param> public MagneticFieldStrength(IMeasure <MagneticFieldStrength> other) : this(other.StandardAmount) { }
/// <summary> /// Creates a new MeasureResult /// </summary> /// <param name="measure"></param> /// <param name="init"></param> public IntMeasureResult(IMeasure measure, int init) { this._value = init; this.Measure = measure; this.Count = 0; }
public void Setup() { _instance = new Measure<Mass>(0.01, Mass.MetricTon); }
/// <summary> /// Creates a new MeasureResult /// </summary> /// <param name="measure"></param> /// <param name="init"></param> public DecimalMeasureResult(IMeasure measure, decimal init) { this._value = init; this.Measure = measure; this.Count = 0; }
protected Network(IMeasure measure) { _ssid = measure.Ssid; }
public override int[] GetPath(int n, IMeasure measure) { var stopwatch = Stopwatch.StartNew(); var cycle = 0; var timelimit = RunProperties.RunTimeInSeconds; var timeout = false; int[] bestPath = null; var bestLength = 1e30; while (!timeout) { // Generate random path //var p = new[] {1, 3, 2, 0}; var p = Permutations.GetRandomPermutation(n); var path = new UniversalNode[n]; for (int i = 0; i < n - 1; i++) { path[p[i]].Right = p[i + 1]; } for (int i = 1; i < n; i++) { path[p[i]].Left = p[i - 1]; } path[p[0]].Left = p[n - 1]; path[p[n - 1]].Right = p[0]; var pst = 0; var st = path[0].Left; while (true) { var found = false; var i = st; var inext = path[i].Right; var ipr = path[i].Next(inext); int jpr = 0; int j = 0; int jnext = 0; while (true) { cycle++; if (cycle == 10000) { stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds > timelimit * 1000) { timeout = true; break; } cycle = 0; stopwatch.Start(); } jpr = i; j = path[i].Next(ipr); jnext = path[j].Next(jpr); while (j != i) { if (inext != j && jnext != i) { if (measure[i, inext] + measure[j, jnext] > measure[i, j] + measure[inext, jnext]) { found = true; break; } } jpr = j; j = jnext; jnext = path[j].Next(jpr); } if (found) { break; } ipr = i; i = inext; inext = path[i].Next(ipr); if (i == st) { break; } } if (!found) { break; } //var inext2 = path[inext].Next(i); //var jprev = path[j].Next(jnext); path[i].Change(inext, j); path[j].Change(jnext, i); path[inext].Change(i, jnext); path[jnext].Change(j, inext); var sttmp = st; st = path[st].Next(pst); pst = sttmp; } var tpr = 0; var t = path[0].Right; p[0] = 0; var count = 1; while (t != 0) { p[count] = t; count++; var tmp = t; t = path[t].Next(tpr); tpr = tmp; } var l = CalcLength(p, measure); if (l < bestLength) { bestLength = l; bestPath = p; } } return bestPath; }
// update statistics of the network with the input measures public abstract void UpdateStats(IMeasure measure);
internal static Dictionary<string, Dictionary<string, AbsoluteEffectivenessEstimate>> GetSystemQueryAbsolutes( Dictionary<string, Dictionary<string, Run>> sqRuns, IMeasure measure, IRelevanceEstimator relEstimator, IConfidenceEstimator confEstimator) { Dictionary<string, Dictionary<string, AbsoluteEffectivenessEstimate>> sqAbss = new Dictionary<string, Dictionary<string, AbsoluteEffectivenessEstimate>>(); foreach (var sqRun in sqRuns) { Dictionary<string, AbsoluteEffectivenessEstimate> qAbs = new Dictionary<string, AbsoluteEffectivenessEstimate>(); foreach (var qRun in sqRun.Value) { qAbs.Add(qRun.Key, measure.Estimate(qRun.Value, relEstimator, confEstimator)); } sqAbss.Add(sqRun.Key, qAbs); } return sqAbss; }
private static void CheckInput(IMeasure measure) { if (measure == null) { throw new ArgumentNullException("measure"); } if (measure.SignalQuality < SignalQualityMin || measure.SignalQuality > SignalQualityMax) { throw new ArgumentOutOfRangeException("measure" + " SignalQuality out of range"); } }
public int[] GetPath(int n, IMeasure measure) { var vis = new double[n,n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) { vis[i, j] = 1 / measure[i, j]; } else { vis[i, j] = 0; } } } var cstart = 1000; var Q = 1000; var bestL = 1e30; int[] solution = new int[n]; var trail = new double[n,n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { trail[i, j] = cstart; } } var m = n; var pr = new double[n,n]; var alpha = 1; var beta = 5; var rho = 0.5; // var stopwatch = Stopwatch.StartNew(); var threadCount = 4; var maxSteps = 2000; for (int cycle = 0; cycle < maxSteps; cycle++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { pr[i, j] = Math.Pow(trail[i, j], alpha) * Math.Pow(vis[i, j], beta); /*if (pr[i, j] < 1e-25) { pr[i, j] = 0; }*/ } } var path = new int[m,n]; var threads = new Thread[threadCount]; for (int i = 0; i < threadCount; i++) { var left = (i * m) / threadCount; var right = ((i + 1) * m) / threadCount; var thread = new Thread(() => RunSearch(left, right, n, pr, path)); threads[i] = thread; thread.Start(); } for (int i = 0; i < threadCount; i++) { threads[i].Join(); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { trail[i, j] *= rho; } } double delta; double avgL = 0; for (int k = 0; k < m; k++) { var l = measure[path[k, n - 1], path[k, 0]]; for (int i = 0; i < n - 1; i++) { l += measure[path[k, i], path[k, i + 1]]; } avgL += l; if (bestL > l) { bestL = l; for (int i = 0; i < n; i++) { solution[i] = path[k, i]; } } delta = Q / l; trail[path[k, n - 1], path[k, 0]] += delta; for (int i = 0; i < n - 1; i++) { trail[path[k, i], path[k, i + 1]] += delta; } } /*if (cycle % 1000 == 0) { Console.WriteLine("{0} {1} {2}", cycle, bestL, avgL / m); }*/ if (avgL - bestL * m < 1e-10) { break; } // elitist strategy /*var e = Math.Sqrt(n); delta = Q / bestL * e; trail[solution[n - 1], solution[0]] += delta; for (int i = 0; i < n - 1; i++) { trail[solution[i], solution[i + 1]] += delta; }*/ } return solution; }
/// <summary> /// Initializes a dose equivalent object from an object implementing the IMeasure<DoseEquivalent> interface /// </summary> /// <param name="other">Object implemeting the IMeasure<DoseEquivalent> interface</param> public DoseEquivalent(IMeasure <DoseEquivalent> other) : this(other.StandardAmount) { }
private static IView CreateCumulativeView( IViewName name, IMeasure measure, IAggregation aggregation, List <string> keys) { return(View.Create(name, VIEW_DESCRIPTION, measure, aggregation, keys)); }
private static bool AreInSameHour(IMeasure measure, DateTime hourToCheck) { var current = hourToCheck; var last = measure.DateTime; var currentHour = new DateTime(current.Year, current.Month, current.Day, current.Hour, 0, 0); var lastHour = new DateTime(last.Year, last.Month, last.Day, last.Hour, 0, 0); return currentHour == lastHour; }
public void Teardown() { _instance = null; }
ICompositeMeasure IMeasure.Times(IMeasure measure) { return(this.Times(measure)); }
// test if the input measures are compatible with the network public abstract bool TestInput(IMeasure measure);
public CompositeMeasure <Measure <T>, IMeasure> Times(IMeasure measure) { return(new CompositeMeasure <Measure <T>, IMeasure>(this, measure)); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> /// <param name="other">An object to compare with this object.</param> bool IEquatable <IMeasure> .Equals(IMeasure other) { return(this.Equals(other as IMeasure <DoseEquivalent>)); }
public override void UpdateStats(IMeasure measure) { CheckInput(measure); //online mean and standard deviation var sample = (double)measure.SignalQuality; N += 1; var delta = sample - Mean; Mean = Mean + (delta / N); _s = _s + delta * (sample - Mean); // if overflow consider _variance = _variance + delta/n * (sample - Mean) // but it may suffer by numeric cancellation if (_s.Equals(Double.PositiveInfinity)) { throw new OverflowException("S overflowed!!!!"); } }