Skip to content

Commit

Permalink
Merge branch 'release/2.2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomelli committed Jan 14, 2019
2 parents ac17144 + 9825fd0 commit f9c504d
Show file tree
Hide file tree
Showing 20 changed files with 296 additions and 40 deletions.
11 changes: 1 addition & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/

[Oo]bj/

# mstest test results
Expand Down Expand Up @@ -88,7 +88,6 @@ csx
AppPackages/

# Others
[Bb]in
[Oo]bj
sql
TestResults
Expand Down Expand Up @@ -118,14 +117,6 @@ opencoverCoverage.xml
*.nupkg
stylecop-report.violations.xml
stylecop-report.xml
src/GeneticSharp.Extensions/ExpressionTree/ExpressionTreeChromosome.cs
src/GeneticSharp.Extensions/Hangman/HangmanChromosome.cs
src/GeneticSharp.Extensions/Hangman/HangmanEnglishFitness.cs
src/GeneticSharp.Extensions/Numberlink/NumberlinkChromosome.cs
src/GeneticSharp.Extensions/Numberlink/NumberlinkFitness.cs
src/GeneticSharp.Extensions/Numberlink/NumberlinkSquare.cs
src/GeneticSharp.Runner.ConsoleApp/Samples/HangmanSampleController.cs
src/GeneticSharp.Runner.GtkApp/Samples/NumberlinkSampleController.cs
dupFinder-report.xml
Issue9Sample.sln.GhostDoc.xml
/build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace GeneticSharp.Domain.UnitTests.Chromosomes
public class BinaryChromosomeBaseTest
{
[Test]
public void FlipBit_Index_ValueFlip()
public void FlipGene_Index_ValueFlip()
{
var target = new BinaryChromosomeStub (2);
target.ReplaceGenes (0, new Gene[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ public void Constructor_FromZeroToZero_Double()

Assert.AreEqual(0, actual);
}
}

[Test]
public void FlipGene_Index_ValueFlip()
{
RandomizationProvider.Current = Substitute.For<IRandomization>();
RandomizationProvider.Current.GetDouble(0, 0).Returns(0);
var target = new FloatingPointChromosome(0, 0, 2);

target.FlipGene(0);
Assert.AreEqual("10000000000000000000000000000000", target.ToString());

target.FlipGene(1);
Assert.AreEqual("11000000000000000000000000000000", target.ToString());

target.FlipGene(31);
Assert.AreEqual("11000000000000000000000000000001", target.ToString());

target.FlipGene(30);
Assert.AreEqual("11000000000000000000000000000011", target.ToString());
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ public void CreateNew_NoArgs_NewInstance()
var actual = target.ToInteger();
Assert.AreEqual(-2, actual);
}

[Test]
public void FlipGene_Index_ValueFlip()
{
RandomizationProvider.Current = Substitute.For<IRandomization>();
RandomizationProvider.Current.GetInt(0, 3).Returns(-2);

var target = new IntegerChromosome(0, 3);
Assert.AreEqual("11111111111111111111111111111110", target.ToString());

target.FlipGene(0);
Assert.AreEqual("01111111111111111111111111111110", target.ToString());

target.FlipGene(1);
Assert.AreEqual("00111111111111111111111111111110", target.ToString());

target.FlipGene(10);
Assert.AreEqual("00111111110111111111111111111110", target.ToString());

target.FlipGene(31);
Assert.AreEqual("00111111110111111111111111111111", target.ToString());

target.FlipGene(30);
Assert.AreEqual("00111111110111111111111111111101", target.ToString());
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected BinaryChromosomeBase(int length)
/// <remarks>>
/// If gene's value is 0, the it will be flip to 1 and vice-versa.</remarks>
/// <param name="index">The gene index.</param>
public void FlipGene (int index)
public virtual void FlipGene (int index)
{
var value = (int) GetGene (index).Value;

Expand Down
17 changes: 14 additions & 3 deletions src/GeneticSharp.Domain/Chromosomes/IntegerChromosome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public IntegerChromosome(int minValue, int maxValue) : base(32)
CreateGenes();
}

#region implemented abstract members of ChromosomeBase
/// <summary>
/// Generates the gene.
/// </summary>
Expand All @@ -51,8 +50,6 @@ public override IChromosome CreateNew()
return new IntegerChromosome(m_minValue, m_maxValue);
}

#endregion

/// <summary>
/// Converts the chromosome to its integer representation.
/// </summary>
Expand All @@ -75,6 +72,20 @@ public override string ToString()
{
return String.Join("", GetGenes().Reverse().Select(g => (bool) g.Value ? "1" : "0").ToArray());
}

/// <summary>
/// Flips the gene.
/// </summary>
/// <remarks>>
/// If gene's value is 0, the it will be flip to 1 and vice-versa.</remarks>
/// <param name="index">The gene index.</param>
public override void FlipGene(int index)
{
var realIndex = Math.Abs(31 - index);
var value = (bool)GetGene(realIndex).Value;

ReplaceGene(realIndex, new Gene(!value));
}
}
}

22 changes: 11 additions & 11 deletions src/GeneticSharp.Domain/Crossovers/PartiallyMappedCrossover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace GeneticSharp.Domain.Crossovers
/// The partially-mapped crossover operator was suggested by Gold- berg and Lingle (1985).
/// It passes on ordering and value information from the parent tours to the offspring tours.
/// A portion of one parent’s string is mapped onto a portion of the other parent’s string and the remaining information is exchanged.
/// <see href="http://lev4projdissertation.googlecode.com/svn-history/r100/trunk/reading/read/aiRev99.pdf">Genetic Algorithms for the Travelling Salesman Problem - A Review of Representations and Operators</see>
/// <see href="http://www.dca.fee.unicamp.br/~gomide/courses/EA072/artigos/Genetic_Algorithm_TSPR_eview_Larranaga_1999.pdf">Genetic Algorithms for the Travelling Salesman Problem - A Review of Representations and Operators</see>
/// </remarks>
/// </summary>
[DisplayName("Partially Mapped (PMX)")]
Expand Down Expand Up @@ -44,26 +44,26 @@ protected override IList<IChromosome> PerformCross(IList<IChromosome> parents)
throw new CrossoverException(this, "The Partially Mapped Crossover (PMX) can be only used with ordered chromosomes. The specified chromosome has repeated genes.");
}

// Chosse the thow parents.
// Choose the thow parents.
var parent1 = parents[0];
var parent2 = parents[1];

// Create, sort and define the cut point indexes.
var cutPointsIndexes = RandomizationProvider.Current.GetUniqueInts(2, 0, parent1.Length);
Array.Sort(cutPointsIndexes);
var firstCutPointIndex = cutPointsIndexes[0];
var secondCutPointIdnex = cutPointsIndexes[1];
var secondCutPointIndex = cutPointsIndexes[1];

// Parent1 creates the mapping section.
var parent1Genes = parent1.GetGenes();
var parent1MappingSection = parent1Genes.Skip(firstCutPointIndex).Take((secondCutPointIdnex - firstCutPointIndex) + 1).ToArray();
var parent1MappingSection = parent1Genes.Skip(firstCutPointIndex).Take((secondCutPointIndex - firstCutPointIndex) + 1).ToArray();

// Parent12 creates the mapping section.
var parent2Genes = parent2.GetGenes();
var parent2MappingSection = parent2Genes.Skip(firstCutPointIndex).Take((secondCutPointIdnex - firstCutPointIndex) + 1).ToArray();
var parent2MappingSection = parent2Genes.Skip(firstCutPointIndex).Take((secondCutPointIndex - firstCutPointIndex) + 1).ToArray();

// The new offsprings are created and
// their genes ar replaced starat in the first cut point index
// their genes ar replaced start in the first cut point index
// and using the genes in the mapping section from parent 1 e 2.
var offspring1 = parent1.CreateNew();
var offspring2 = parent2.CreateNew();
Expand All @@ -75,16 +75,16 @@ protected override IList<IChromosome> PerformCross(IList<IChromosome> parents)

for (int i = 0; i < length; i++)
{
if (i >= firstCutPointIndex && i <= secondCutPointIdnex)
if (i >= firstCutPointIndex && i <= secondCutPointIndex)
{
continue;
}

var geneForUffspring1 = GetGeneNotInMappingSection(parent1Genes[i], parent2MappingSection, parent1MappingSection);
offspring1.ReplaceGene(i, geneForUffspring1);
var geneForOffspring1 = GetGeneNotInMappingSection(parent1Genes[i], parent2MappingSection, parent1MappingSection);
offspring1.ReplaceGene(i, geneForOffspring1);

var geneForoffspring2 = GetGeneNotInMappingSection(parent2Genes[i], parent1MappingSection, parent2MappingSection);
offspring2.ReplaceGene(i, geneForoffspring2);
var geneForOffspring2 = GetGeneNotInMappingSection(parent2Genes[i], parent1MappingSection, parent2MappingSection);
offspring2.ReplaceGene(i, geneForOffspring2);
}

return new List<IChromosome>() { offspring1, offspring2 };
Expand Down
Binary file modified tools/sonar-scanner-msbuild/SonarScanner.MSBuild.Common.dll
Binary file not shown.
Binary file not shown.
Binary file modified tools/sonar-scanner-msbuild/SonarScanner.MSBuild.PreProcessor.dll
Binary file not shown.
Binary file modified tools/sonar-scanner-msbuild/SonarScanner.MSBuild.Shim.dll
Binary file not shown.
Binary file modified tools/sonar-scanner-msbuild/SonarScanner.MSBuild.TFS.dll
Binary file not shown.
Binary file modified tools/sonar-scanner-msbuild/SonarScanner.MSBuild.Tasks.dll
Binary file not shown.
Binary file modified tools/sonar-scanner-msbuild/SonarScanner.MSBuild.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
<!-- **************************************************************************** -->
<!-- Diagnostic/error-checking target
Causes the build to fail if the analysis properties are not correctly configured
Causes the build to fail if the analysis properties are not correctly configured
i.e. if the user has requested a SonarQube analysis run, but the analysis targets
cannot be found.
Writes out diagnostic information to help with troubleshooting. -->
<!-- **************************************************************************** -->
<Target Name="SonarQubeImportBeforeInfo" Condition=" $(SonarQubeTempPath) != '' AND $(BuildingInsideVisualStudio) != 'true' " BeforeTargets="CoreCompile">
Expand Down
46 changes: 35 additions & 11 deletions tools/sonar-scanner-msbuild/Targets/SonarQube.Integration.targets
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,28 @@
<Target Name="SetRoslynCodeAnalysisProperties">

<!-- Fetch the relevant settings from the config file -->
<GetAnalyzerSettings AnalysisConfigDir="$(SonarQubeConfigPath)" Language="$(SQLanguage)" OriginalAdditionalFiles="@(AdditionalFiles)">
<GetAnalyzerSettings AnalysisConfigDir="$(SonarQubeConfigPath)"
Language="$(SQLanguage)"
CurrentProjectDirectoryPath="$(MSBuildProjectDirectory)"
OriginalAnalyzers="@(Analyzer)"
OriginalAdditionalFiles="@(AdditionalFiles)"
OriginalRulesetFilePath="$(ResolvedCodeAnalysisRuleset)"
ProjectSpecificConfigDirectory="$(ProjectSpecificConfDir)">
<Output TaskParameter="RuleSetFilePath" PropertyName="SQRuleSetFilePath" />
<Output TaskParameter="AnalyzerFilePaths" ItemName="SQAnalyzerFilePaths" />
<Output TaskParameter="AdditionalFiles" ItemName="SQAdditionalFiles" />
<Output TaskParameter="AdditionalFilesToRemove" ItemName="SQAdditionalFilesToRemove" />
<Output TaskParameter="AdditionalFilePaths" ItemName="SQAdditionalFiles" />
</GetAnalyzerSettings>

<PropertyGroup>
<PropertyGroup Condition=" $(ErrorLog) == '' ">
<!-- Keep the path so that we could set SonarQubeSetting with sonar.language.roslyn.reportFilePaths -->
<!-- https://jira.sonarsource.com/browse/SONARMSBRU-211 - the name of the report should be unique
as the TargetDir can point to the same directory for multiple projects, leading to the report being overwritten.
This style of naming is consistent with how FxCop names its report.-->
<ErrorLog Condition=" $(ErrorLog) == '' " >$(TargetDir)$(TargetFileName).RoslynCA.json</ErrorLog>
<SonarCompileErrorLog>$(TargetDir)$(TargetFileName).RoslynCA.json</SonarCompileErrorLog>
<ErrorLog>$(SonarCompileErrorLog)</ErrorLog>
</PropertyGroup>

<PropertyGroup>
<ResolvedCodeAnalysisRuleSet>$(SQRuleSetFilePath)</ResolvedCodeAnalysisRuleSet>
<ProjectConfFilePath>$(ProjectSpecificConfDir)\ProjectOutFolderPath.txt</ProjectConfFilePath>
</PropertyGroup>
Expand All @@ -400,31 +410,45 @@
</WriteLinesToFile>

<ItemGroup>
<!-- Remove any existing analyzers and additional files -->
<!-- Clear the original set of analyzers and additional files -->
<Analyzer Remove="@(Analyzer)" />
<AdditionalFiles Remove="@(SQAdditionalFilesToRemove)" />
<AdditionalFiles Remove="@(AdditionalFiles)" />

<!-- Add specified analyzers and additional files (if any) -->
<!-- Use the set of analyzers and additional files calculated by the GetAnalyzerSettings task -->
<Analyzer Include="@(SQAnalyzerFilePaths)" />
<AdditionalFiles Include="@(SQAdditionalFiles)" />
<AdditionalFiles Include="$(ProjectConfFilePath)" />
</ItemGroup>

</Target>

<Target Name="SetRazorCodeAnalysisProperties" BeforeTargets="RazorCoreCompile" AfterTargets="CopyFilesToOutputDirectory">
<PropertyGroup Condition=" $(ErrorLog) == $(SonarCompileErrorLog) ">
<!-- Keep the path so that we could set SonarQubeSetting with sonar.language.roslyn.reportFilePaths -->
<RazorSonarCompileErrorLog>$(TargetDir)$(TargetName)$(RazorTargetNameSuffix)$(TargetExt).RoslynCA.json</RazorSonarCompileErrorLog>
<ErrorLog>$(RazorSonarCompileErrorLog)</ErrorLog>
</PropertyGroup>
</Target>

<Target Name="SetRoslynAnalysisResults"
Condition=" $(SonarQubeTempPath) != '' "
AfterTargets="Build;CreateProjectSpecificDirs"
BeforeTargets="WriteSonarQubeProjectData">

<ItemGroup>
<SonarReportFilePath Condition=" $(SonarCompileErrorLog) != '' AND $([System.IO.File]::Exists($(SonarCompileErrorLog))) == 'true' " Include="$(SonarCompileErrorLog)" />
<SonarReportFilePath Condition=" $(RazorSonarCompileErrorLog) != '' AND $([System.IO.File]::Exists($(RazorSonarCompileErrorLog))) == 'true' " Include="$(RazorSonarCompileErrorLog)" />
</ItemGroup>

<ItemGroup>
<SonarQubeSetting Include="sonar.$(SQLanguage).roslyn.reportFilePath"
Condition=" $(ErrorLog) != '' AND $([System.IO.File]::Exists($(ErrorLog))) == 'true' ">
<Value>$(ErrorLog)</Value>
Condition=" @(SonarReportFilePath) != '' ">
<!-- Join the paths with | -->
<!-- This delimiter needs to be the same as PropertiesFileGenerator.RoslynReportPathsDelimiter -->
<Value>@(SonarReportFilePath->'%(identity)','|')</Value>
</SonarQubeSetting>
<SonarQubeSetting Include="sonar.$(SQLanguage).analyzer.projectOutPath"
Condition=" $(ErrorLog) != '' AND $([System.IO.File]::Exists($(ErrorLog))) == 'true' ">
Condition=" $(SonarCompileErrorLog) != '' AND $([System.IO.File]::Exists($(SonarCompileErrorLog))) == 'true' ">
<Value>$(ProjectSpecificOutDir)</Value>
</SonarQubeSetting>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh
#
# SonarQube Scanner Startup Script for Unix
#
# Optional ENV vars:
# SONAR_SCANNER_OPTS - Parameters passed to the Java VM when running the SonarQube Scanner
# SONAR_SCANNER_DEBUG_OPTS - Extra parameters passed to the Java VM for debugging
# JAVA_HOME - Location of Java's installation

real_path () {
target=$1

(
while true; do
cd "$(dirname "$target")"
target=$(basename "$target")
test -L "$target" || break
target=$(readlink "$target")
done

echo "$(pwd -P)/$target"
)
}

script_path=$(real_path "$0")
sonar_scanner_home=$(dirname "$script_path")/..

# make it fully qualified
sonar_scanner_home=$(cd "$sonar_scanner_home" && pwd -P)

jar_file=$sonar_scanner_home/lib/sonar-scanner-cli-3.2.0.1227.jar

# check that sonar_scanner_home has been correctly set
if [ ! -f "$jar_file" ] ; then
echo "File does not exist: $jar_file"
echo "'$sonar_scanner_home' does not point to a valid installation directory: $sonar_scanner_home"
exit 1
fi

use_embedded_jre=false
if [ "$use_embedded_jre" = true ]; then
export JAVA_HOME=$sonar_scanner_home/jre
fi

if [ -n "$JAVA_HOME" ]
then
java_cmd="$JAVA_HOME/bin/java"
else
java_cmd="$(which java)"
fi

project_home=$(pwd)

#echo "Info: Using sonar-scanner at $sonar_scanner_home"
#echo "Info: Using java at $java_cmd"
#echo "Info: Using classpath $jar_file"
#echo "Info: Using project $project_home"

exec "$java_cmd" \
-Djava.awt.headless=true \
$SONAR_SCANNER_OPTS \
$SONAR_SCANNER_DEBUG_OPTS \
-classpath "$jar_file" \
-Dscanner.home="$sonar_scanner_home" \
-Dproject.home="$project_home" \
org.sonarsource.scanner.cli.Main "$@"

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
#
# SonarQube Scanner Startup Script for Unix
#
# Optional ENV vars:
# SONAR_SCANNER_OPTS - parameters passed to the Java VM when running the SonarQube Scanner
# JAVA_HOME - Location of Java's installation

SONAR_SCANNER_DEBUG_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"

echo "Executing SonarQube Scanner in Debug Mode"
echo "SONAR_SCANNER_DEBUG_OPTS=\"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000\""

env SONAR_SCANNER_OPTS="$SONAR_SCANNER_OPTS" SONAR_SCANNER_DEBUG_OPTS="$SONAR_SCANNER_DEBUG_OPTS" "$(dirname "$0")"/sonar-scanner "$@"
Loading

0 comments on commit f9c504d

Please sign in to comment.