[4089] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[4089] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[4722] | 22 | using System.IO;
|
---|
| 23 | using Google.ProtocolBuffers;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
[4089] | 25 | using HeuristicLab.Core;
|
---|
[4722] | 26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[14927] | 27 | using HeuristicLab.Persistence;
|
---|
| 28 | using HeuristicLab.Persistence.Default.Xml;
|
---|
[4089] | 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.ExternalEvaluation.GP {
|
---|
| 31 | [Item("SymbolicExpressionTreeBinaryConverter", "Converts a symbolic expression tree into a binary representation by iterating over all nodes in a prefix way. The binary format is defined in HeuristicLab.Persistence.")]
|
---|
[14927] | 32 | [StorableType("940ef9f1-e002-4d9b-80d1-521f5b869570")]
|
---|
[4089] | 33 | public class SymbolicExpressionTreeBinaryConverter : SymbolicExpressionTreeConverter {
|
---|
[4722] | 34 | [StorableConstructor]
|
---|
[15018] | 35 | protected SymbolicExpressionTreeBinaryConverter(StorableConstructorFlag deserializing) : base(deserializing) { }
|
---|
[4722] | 36 | protected SymbolicExpressionTreeBinaryConverter(SymbolicExpressionTreeBinaryConverter original, Cloner cloner)
|
---|
| 37 | : base(original, cloner) {
|
---|
| 38 | }
|
---|
| 39 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 40 | return new SymbolicExpressionTreeBinaryConverter(this, cloner);
|
---|
| 41 | }
|
---|
| 42 | public SymbolicExpressionTreeBinaryConverter() : base() { }
|
---|
[4089] | 43 |
|
---|
| 44 | protected override void ConvertSymbolicExpressionTree(SymbolicExpressionTree tree, string name, SolutionMessage.Builder builder) {
|
---|
| 45 | using (MemoryStream memoryStream = new MemoryStream()) {
|
---|
[14927] | 46 | XmlGenerator.Serialize(tree, memoryStream);
|
---|
[4089] | 47 | byte[] byteRep = memoryStream.ToArray();
|
---|
| 48 | SolutionMessage.Types.RawVariable.Builder rawVariable = SolutionMessage.Types.RawVariable.CreateBuilder();
|
---|
| 49 | rawVariable.SetName(name).SetData(ByteString.CopyFrom(byteRep));
|
---|
| 50 | builder.AddRawVars(rawVariable.Build());
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | }
|
---|