Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/27/09 15:42:04 (15 years ago)
Author:
epitzer
Message:

Migration of DataAnalysis, GP, GP.StructureIdentification and Modeling to new Persistence-3.3 (#603)

Location:
trunk/sources/HeuristicLab.GP/3.4
Files:
7 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP/3.4/BakedFunctionTree.cs

    r1529 r1914  
    2828using System.Xml;
    2929using System.Globalization;
     30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3031
    3132namespace HeuristicLab.GP {
    3233
    3334  public class LightWeightFunction {
     35
     36    [Storable]
    3437    public byte arity = 0;
     38
     39    [Storable]
    3540    public IFunction functionType;
     41
     42    [Storable]
    3643    public List<double> data = new List<double>();
    3744
     
    4653
    4754  public class BakedFunctionTree : ItemBase, IFunctionTree {
     55
    4856    private List<LightWeightFunction> linearRepresentation;
     57
     58    [Storable]
    4959    public List<LightWeightFunction> LinearRepresentation {
    5060      get {
    5161        FlattenVariables();
    52         FlattenTrees(); 
     62        FlattenTrees();
    5363        return linearRepresentation;
    5464      }
    55     }
     65      private set {
     66        linearRepresentation = value;
     67        treesExpanded = false;
     68        variablesExpanded = false;
     69      }
     70    }
     71
    5672    private bool treesExpanded = false;
    5773    private List<IFunctionTree> subTrees;
     
    7288      variables = new List<IVariable>();
    7389      variablesExpanded = true;
    74       foreach(IVariableInfo variableInfo in function.VariableInfos) {
    75         if(variableInfo.Local) {
     90      foreach (IVariableInfo variableInfo in function.VariableInfos) {
     91        if (variableInfo.Local) {
    7692          variables.Add((IVariable)function.GetVariable(variableInfo.FormalName).Clone());
    7793        }
     
    84100      fun.functionType = tree.Function;
    85101      linearRepresentation.Add(fun);
    86       foreach(IVariable variable in tree.LocalVariables) {
     102      foreach (IVariable variable in tree.LocalVariables) {
    87103        IItem value = variable.Value;
    88104        fun.data.Add(GetDoubleValue(value));
    89105      }
    90       foreach(IFunctionTree subTree in tree.SubTrees) {
     106      foreach (IFunctionTree subTree in tree.SubTrees) {
    91107        AddSubTree(new BakedFunctionTree(subTree));
    92108      }
     
    94110
    95111    private double GetDoubleValue(IItem value) {
    96       if(value is DoubleData) {
     112      if (value is DoubleData) {
    97113        return ((DoubleData)value).Data;
    98       } else if(value is ConstrainedDoubleData) {
     114      } else if (value is ConstrainedDoubleData) {
    99115        return ((ConstrainedDoubleData)value).Data;
    100       } else if(value is IntData) {
     116      } else if (value is IntData) {
    101117        return ((IntData)value).Data;
    102       } else if(value is ConstrainedIntData) {
     118      } else if (value is ConstrainedIntData) {
    103119        return ((ConstrainedIntData)value).Data;
    104120      } else throw new NotSupportedException("Invalid datatype of local variable for GP");
     
    108124      int arity = linearRepresentation[branchRoot].arity;
    109125      int length = 1;
    110       for(int i = 0; i < arity; i++) {
     126      for (int i = 0; i < arity; i++) {
    111127        length += BranchLength(branchRoot + length);
    112128      }
     
    115131
    116132    private void FlattenTrees() {
    117       if(treesExpanded) {
     133      if (treesExpanded) {
    118134        linearRepresentation[0].arity = (byte)subTrees.Count;
    119         foreach(BakedFunctionTree subTree in subTrees) {
     135        foreach (BakedFunctionTree subTree in subTrees) {
    120136          subTree.FlattenVariables();
    121137          subTree.FlattenTrees();
     
    128144
    129145    private void FlattenVariables() {
    130       if(variablesExpanded) {
     146      if (variablesExpanded) {
    131147        linearRepresentation[0].data.Clear();
    132         foreach(IVariable variable in variables) {
     148        foreach (IVariable variable in variables) {
    133149          linearRepresentation[0].data.Add(GetDoubleValue(variable.Value));
    134150        }
     
    140156    public int Size {
    141157      get {
    142         if(treesExpanded) {
     158        if (treesExpanded) {
    143159          int size = 1;
    144           foreach(BakedFunctionTree tree in subTrees) {
     160          foreach (BakedFunctionTree tree in subTrees) {
    145161            size += tree.Size;
    146162          }
    147163          return size;
    148         } else 
    149         return linearRepresentation.Count;
     164        } else
     165          return linearRepresentation.Count;
    150166      }
    151167    }
     
    153169    public int Height {
    154170      get {
    155         if(treesExpanded) {
     171        if (treesExpanded) {
    156172          int height = 0;
    157           foreach(IFunctionTree subTree in subTrees) {
     173          foreach (IFunctionTree subTree in subTrees) {
    158174            int curHeight = subTree.Height;
    159             if(curHeight > height) height = curHeight;
     175            if (curHeight > height) height = curHeight;
    160176          }
    161           return height+1;
     177          return height + 1;
    162178        } else {
    163179          int nextBranchStart;
     
    171187      int height = 0;
    172188      branchStart++;
    173       for(int i = 0; i < f.arity; i++) {
     189      for (int i = 0; i < f.arity; i++) {
    174190        int curHeight = BranchHeight(branchStart, out nextBranchStart);
    175         if(curHeight > height) height = curHeight;
     191        if (curHeight > height) height = curHeight;
    176192        branchStart = nextBranchStart;
    177193      }
     
    182198    public IList<IFunctionTree> SubTrees {
    183199      get {
    184         if(!treesExpanded) {
     200        if (!treesExpanded) {
    185201          subTrees = new List<IFunctionTree>();
    186202          int arity = linearRepresentation[0].arity;
    187203          int branchIndex = 1;
    188           for(int i = 0; i < arity; i++) {
     204          for (int i = 0; i < arity; i++) {
    189205            BakedFunctionTree subTree = new BakedFunctionTree();
    190206            int length = BranchLength(branchIndex);
    191             for(int j = branchIndex; j < branchIndex + length; j++) {
     207            for (int j = branchIndex; j < branchIndex + length; j++) {
    192208              subTree.linearRepresentation.Add(linearRepresentation[j]);
    193209            }
     
    205221    public ICollection<IVariable> LocalVariables {
    206222      get {
    207         if(!variablesExpanded) {
     223        if (!variablesExpanded) {
    208224          variables = new List<IVariable>();
    209225          IFunction function = Function;
    210226          int localVariableIndex = 0;
    211           foreach(IVariableInfo variableInfo in function.VariableInfos) {
    212             if(variableInfo.Local) {
     227          foreach (IVariableInfo variableInfo in function.VariableInfos) {
     228            if (variableInfo.Local) {
    213229              IVariable clone = (IVariable)function.GetVariable(variableInfo.FormalName).Clone();
    214230              IItem value = clone.Value;
    215               if(value is ConstrainedDoubleData) {
     231              if (value is ConstrainedDoubleData) {
    216232                ((ConstrainedDoubleData)value).Data = linearRepresentation[0].data[localVariableIndex];
    217               } else if(value is ConstrainedIntData) {
     233              } else if (value is ConstrainedIntData) {
    218234                ((ConstrainedIntData)value).Data = (int)linearRepresentation[0].data[localVariableIndex];
    219               } else if(value is DoubleData) {
     235              } else if (value is DoubleData) {
    220236                ((DoubleData)value).Data = linearRepresentation[0].data[localVariableIndex];
    221               } else if(value is IntData) {
     237              } else if (value is IntData) {
    222238                ((IntData)value).Data = (int)linearRepresentation[0].data[localVariableIndex];
    223239              } else throw new NotSupportedException("Invalid local variable type for GP.");
     
    238254
    239255    public IVariable GetLocalVariable(string name) {
    240       foreach(IVariable var in LocalVariables) {
    241         if(var.Name == name) return var;
     256      foreach (IVariable var in LocalVariables) {
     257        if (var.Name == name) return var;
    242258      }
    243259      return null;
     
    253269
    254270    public void AddSubTree(IFunctionTree tree) {
    255       if(!treesExpanded) throw new InvalidOperationException();
     271      if (!treesExpanded) throw new InvalidOperationException();
    256272      subTrees.Add(tree);
    257273    }
    258274
    259275    public void InsertSubTree(int index, IFunctionTree tree) {
    260       if(!treesExpanded) throw new InvalidOperationException();
     276      if (!treesExpanded) throw new InvalidOperationException();
    261277      subTrees.Insert(index, tree);
    262278    }
     
    264280    public void RemoveSubTree(int index) {
    265281      // sanity check
    266       if(!treesExpanded) throw new InvalidOperationException();
     282      if (!treesExpanded) throw new InvalidOperationException();
    267283      subTrees.RemoveAt(index);
    268     }
    269 
    270     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    271       FlattenVariables();
    272       FlattenTrees();
    273       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    274       XmlNode linearRepresentationNode = document.CreateElement("LinearRepresentation");
    275       foreach(LightWeightFunction f in linearRepresentation) {
    276         XmlNode entryNode = PersistenceManager.Persist("FunctionType", f.functionType, document, persistedObjects);
    277         XmlAttribute arityAttribute = document.CreateAttribute("Arity");
    278         arityAttribute.Value = f.arity+"";
    279         entryNode.Attributes.Append(arityAttribute);
    280         if(f.data.Count > 0) {
    281           XmlAttribute dataAttribute = document.CreateAttribute("Data");
    282           dataAttribute.Value = GetString(f.data);
    283           entryNode.Attributes.Append(dataAttribute);
    284         }
    285         linearRepresentationNode.AppendChild(entryNode);
    286       }
    287 
    288       node.AppendChild(linearRepresentationNode);
    289       return node;
    290     }
    291 
    292     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    293       base.Populate(node, restoredObjects);
    294       XmlNode linearRepresentationNode = node.SelectSingleNode("LinearRepresentation");
    295       foreach(XmlNode entryNode in linearRepresentationNode.ChildNodes) {
    296         LightWeightFunction f = new LightWeightFunction();
    297         f.arity = byte.Parse(entryNode.Attributes["Arity"].Value, CultureInfo.InvariantCulture);
    298         if(entryNode.Attributes["Data"]!=null)
    299           f.data = GetList<double>(entryNode.Attributes["Data"].Value, s => double.Parse(s, CultureInfo.InvariantCulture));
    300         f.functionType = (IFunction)PersistenceManager.Restore(entryNode, restoredObjects);
    301         linearRepresentation.Add(f);
    302       }
    303       treesExpanded = false;
    304       variablesExpanded = false;
    305     }
    306 
    307     private string GetString(IEnumerable<double> xs) {
    308       StringBuilder builder = new StringBuilder();
    309       foreach(double x in xs) {
    310         builder.Append(x.ToString("r", CultureInfo.InvariantCulture) + "; ");
    311       }
    312       if(builder.Length > 0) builder.Remove(builder.Length - 2, 2);
    313       return builder.ToString();
    314     }
    315 
    316     private List<T> GetList<T>(string s, Converter<string, T> converter) {
    317       List<T> result = new List<T>();
    318       string[] tokens = s.Split(new char[] { ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
    319       foreach(string token in tokens) {
    320         T x = converter(token.Trim());
    321         result.Add(x);
    322       }
    323       return result;
    324284    }
    325285
     
    327287      BakedFunctionTree clone = new BakedFunctionTree();
    328288      // in case the user (de)serialized the tree between evaluation and selection we have to flatten the tree again.
    329       if(treesExpanded) FlattenTrees();
    330       if(variablesExpanded) FlattenVariables();
    331       foreach(LightWeightFunction f in linearRepresentation) {
     289      if (treesExpanded) FlattenTrees();
     290      if (variablesExpanded) FlattenVariables();
     291      foreach (LightWeightFunction f in linearRepresentation) {
    332292        clone.linearRepresentation.Add(f.Clone());
    333293      }
  • trunk/sources/HeuristicLab.GP/3.4/FunctionBase.cs

    r1529 r1914  
    2828using HeuristicLab.Constraints;
    2929using System.Diagnostics;
     30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3031
    3132namespace HeuristicLab.GP {
     
    3435  /// is to evaluate all children first.
    3536  /// </summary>
     37  [EmptyStorableClass]
    3638  public abstract class FunctionBase : OperatorBase, IFunction {
     39
    3740    public const string INITIALIZATION = "Initialization";
    3841    public const string MANIPULATION = "Manipulation";
  • trunk/sources/HeuristicLab.GP/3.4/GPOperatorGroup.cs

    r1529 r1914  
    2929using HeuristicLab.Random;
    3030using HeuristicLab.Constraints;
     31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3132
    3233namespace HeuristicLab.GP {
     34
     35  [EmptyStorableClass]
    3336  public class GPOperatorGroup : OperatorGroup {
    3437    private Dictionary<IOperator, int> minTreeHeight = new Dictionary<IOperator, int>();
  • trunk/sources/HeuristicLab.GP/3.4/GPOperatorLibrary.cs

    r1529 r1914  
    2626using HeuristicLab.Core;
    2727using System.Xml;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
    2930namespace HeuristicLab.GP {
    30   public class GPOperatorLibrary : ItemBase, IOperatorLibrary, IEditable  {
     31  public class GPOperatorLibrary : ItemBase, IOperatorLibrary, IEditable {
    3132    // constants for variable names
    3233    internal const string MIN_TREE_HEIGHT = "MinTreeHeight";
     
    3435    internal const string TICKETS = "Tickets";
    3536
     37    [Storable]
    3638    private GPOperatorGroup group;
    3739
     
    6365    }
    6466
    65     #region persistence
    66     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    67       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    68       node.AppendChild(PersistenceManager.Persist("Group", group, document, persistedObjects));
    69       return node;
    70     }
    71 
    72     public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    73       base.Populate(node, restoredObjects);
    74       group = (GPOperatorGroup) PersistenceManager.Restore(node.SelectSingleNode("Group"), restoredObjects);
    75     }
    76     #endregion
    77 
    7867    #region IEditable Members
    7968
  • trunk/sources/HeuristicLab.GP/3.4/HeuristicLab.GP-3.4.csproj

    r1907 r1914  
    66    <ProductVersion>9.0.30729</ProductVersion>
    77    <SchemaVersion>2.0</SchemaVersion>
    8     <ProjectGuid>{1F1CF3ED-374C-4288-995B-93F6B872F571}</ProjectGuid>
     8    <ProjectGuid>{DA0D505A-2149-4E3C-B220-5724DE26EB59}</ProjectGuid>
    99    <OutputType>Library</OutputType>
    1010    <AppDesignerFolder>Properties</AppDesignerFolder>
    1111    <RootNamespace>HeuristicLab.GP</RootNamespace>
    12     <AssemblyName>HeuristicLab.GP-3.3</AssemblyName>
     12    <AssemblyName>HeuristicLab.GP-3.4</AssemblyName>
    1313    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    1414    <FileAlignment>512</FileAlignment>
     
    128128  </ItemGroup>
    129129  <ItemGroup>
    130     <ProjectReference Include="..\..\HeuristicLab.Constraints\3.2\HeuristicLab.Constraints-3.2.csproj">
    131       <Project>{FCD62C6F-4793-4593-AE9A-0BDCA256EE99}</Project>
    132       <Name>HeuristicLab.Constraints-3.2</Name>
     130    <ProjectReference Include="..\..\HeuristicLab.Constraints\3.3\HeuristicLab.Constraints-3.3.csproj">
     131      <Project>{19C1E42A-4B48-4EFD-B697-899016F1C198}</Project>
     132      <Name>HeuristicLab.Constraints-3.3</Name>
    133133    </ProjectReference>
    134     <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj">
    135       <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
    136       <Name>HeuristicLab.Core-3.2</Name>
     134    <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
     135      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
     136      <Name>HeuristicLab.Core-3.3</Name>
    137137    </ProjectReference>
    138     <ProjectReference Include="..\..\HeuristicLab.Data\3.2\HeuristicLab.Data-3.2.csproj">
    139       <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>
    140       <Name>HeuristicLab.Data-3.2</Name>
     138    <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
     139      <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
     140      <Name>HeuristicLab.Data-3.3</Name>
    141141    </ProjectReference>
    142     <ProjectReference Include="..\..\HeuristicLab.Evolutionary\3.2\HeuristicLab.Evolutionary-3.2.csproj">
    143       <Project>{F5614C53-153C-4A37-A608-121E1C087F07}</Project>
    144       <Name>HeuristicLab.Evolutionary-3.2</Name>
     142    <ProjectReference Include="..\..\HeuristicLab.Evolutionary\3.3\HeuristicLab.Evolutionary-3.3.csproj">
     143      <Project>{25087811-F74C-4128-BC86-8324271DA13E}</Project>
     144      <Name>HeuristicLab.Evolutionary-3.3</Name>
    145145    </ProjectReference>
    146     <ProjectReference Include="..\..\HeuristicLab.Operators\3.2\HeuristicLab.Operators-3.2.csproj">
    147       <Project>{A9983BA2-B3B2-475E-8E2C-62050B71D1C5}</Project>
    148       <Name>HeuristicLab.Operators-3.2</Name>
     146    <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
     147      <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project>
     148      <Name>HeuristicLab.Operators-3.3</Name>
     149    </ProjectReference>
     150    <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
     151      <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
     152      <Name>HeuristicLab.Persistence-3.3</Name>
    149153    </ProjectReference>
    150154    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
     
    152156      <Name>HeuristicLab.PluginInfrastructure</Name>
    153157    </ProjectReference>
    154     <ProjectReference Include="..\..\HeuristicLab.Random\3.2\HeuristicLab.Random-3.2.csproj">
    155       <Project>{47019A74-F7F7-482E-83AA-D3F4F777E879}</Project>
    156       <Name>HeuristicLab.Random-3.2</Name>
     158    <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">
     159      <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project>
     160      <Name>HeuristicLab.Random-3.3</Name>
    157161    </ProjectReference>
    158     <ProjectReference Include="..\..\HeuristicLab.Selection\3.2\HeuristicLab.Selection-3.2.csproj">
    159       <Project>{F7CF0571-25CB-43D5-8443-0843A1E2861A}</Project>
    160       <Name>HeuristicLab.Selection-3.2</Name>
     162    <ProjectReference Include="..\..\HeuristicLab.Selection\3.3\HeuristicLab.Selection-3.3.csproj">
     163      <Project>{2C36CD4F-E5F5-43A4-801A-201EA895FE17}</Project>
     164      <Name>HeuristicLab.Selection-3.3</Name>
    161165    </ProjectReference>
    162166  </ItemGroup>
  • trunk/sources/HeuristicLab.GP/3.4/HeuristicLabGPPlugin.cs

    r1529 r1914  
    2626
    2727namespace HeuristicLab.GP {
    28   [ClassInfo(Name = "HeuristicLab.GP-3.3")]
    29   [PluginFile(Filename = "HeuristicLab.GP-3.3.dll", Filetype = PluginFileType.Assembly)]
    30   [Dependency(Dependency = "HeuristicLab.Constraints-3.2")]
    31   [Dependency(Dependency = "HeuristicLab.Core-3.2")]
    32   [Dependency(Dependency = "HeuristicLab.Data-3.2")]
    33   [Dependency(Dependency = "HeuristicLab.Evolutionary-3.2")]
    34   [Dependency(Dependency = "HeuristicLab.Operators-3.2")]
    35   [Dependency(Dependency = "HeuristicLab.Random-3.2")]
    36   [Dependency(Dependency = "HeuristicLab.Selection-3.2")]
     28  [ClassInfo(Name = "HeuristicLab.GP-3.4")]
     29  [PluginFile(Filename = "HeuristicLab.GP-3.4.dll", Filetype = PluginFileType.Assembly)]
     30  [Dependency(Dependency = "HeuristicLab.Constraints-3.3")]
     31  [Dependency(Dependency = "HeuristicLab.Core-3.3")]
     32  [Dependency(Dependency = "HeuristicLab.Data-3.3")]
     33  [Dependency(Dependency = "HeuristicLab.Evolutionary-3.3")]
     34  [Dependency(Dependency = "HeuristicLab.Operators-3.3")]
     35  [Dependency(Dependency = "HeuristicLab.Random-3.3")]
     36  [Dependency(Dependency = "HeuristicLab.Selection-3.3")]
     37  [Dependency(Dependency = "HeuristicLab.Persistence-3.3")]
    3738  public class HeuristicLabGPPlugin : PluginBase {
    3839  }
  • trunk/sources/HeuristicLab.GP/3.4/ProbabilisticTreeCreator.cs

    r1529 r1914  
    2727using HeuristicLab.Random;
    2828using System.Diagnostics;
     29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2930
    3031namespace HeuristicLab.GP {
     32
    3133  public class ProbabilisticTreeCreator : OperatorBase {
    3234    private int MAX_TRIES { get { return 100; } }
  • trunk/sources/HeuristicLab.GP/3.4/Properties/AssemblyInfo.frame

    r1527 r1914  
    5454// You can specify all the values or you can default the Revision and Build Numbers
    5555// by using the '*' as shown below:
    56 [assembly: AssemblyVersion("3.3.0.$WCREV$")]
    57 [assembly: AssemblyFileVersion("3.3.0.$WCREV$")]
     56[assembly: AssemblyVersion("3.4.0.$WCREV$")]
     57[assembly: AssemblyFileVersion("3.4.0.$WCREV$")]
    5858[assembly: AssemblyBuildDate("$WCNOW$")]
Note: See TracChangeset for help on using the changeset viewer.