2010-03-18 07:39:48 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Moserware.Skills.FactorGraphs
|
|
|
|
|
{
|
|
|
|
|
public class VariableFactory<TValue>
|
|
|
|
|
{
|
|
|
|
|
// using a Func<TValue> to encourage fresh copies in case it's overwritten
|
|
|
|
|
private readonly Func<TValue> _VariablePriorInitializer;
|
|
|
|
|
|
|
|
|
|
public VariableFactory(Func<TValue> variablePriorInitializer)
|
|
|
|
|
{
|
|
|
|
|
_VariablePriorInitializer = variablePriorInitializer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Variable<TValue> CreateBasicVariable(string nameFormat, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
var newVar = new Variable<TValue>(
|
2010-05-02 21:26:31 -04:00
|
|
|
|
String.Format(nameFormat, args),
|
2010-03-18 07:39:48 -04:00
|
|
|
|
_VariablePriorInitializer());
|
|
|
|
|
|
|
|
|
|
return newVar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public KeyedVariable<TKey, TValue> CreateKeyedVariable<TKey>(TKey key, string nameFormat, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
var newVar = new KeyedVariable<TKey, TValue>(
|
|
|
|
|
key,
|
2010-05-02 21:31:09 -04:00
|
|
|
|
String.Format(nameFormat, args),
|
2010-03-18 07:39:48 -04:00
|
|
|
|
_VariablePriorInitializer());
|
2010-05-02 21:31:09 -04:00
|
|
|
|
|
2010-03-18 07:39:48 -04:00
|
|
|
|
return newVar;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|