Skip to content

Commit

Permalink
Merge pull request #5 from supix/devel
Browse files Browse the repository at this point in the history
 Bug fix on solution encoding.
  • Loading branch information
supix committed Apr 25, 2017
2 parents d993b59 + e231d2e commit 59f9937
Show file tree
Hide file tree
Showing 39 changed files with 114 additions and 74 deletions.
Binary file added docs/images/SampleSimpleWorkshift.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using NaturalShift.Model.ProblemModel.FluentInterfaces;
using NaturalShift.SolvingEnvironment;
using NUnit.Framework;
using System;

namespace NaturalShift.IntegrationTests
{
Expand Down Expand Up @@ -73,11 +73,17 @@ public void ZeroConsecutiveSlotAptitudeIsRespected()

var solution = solvingEnvironment.Solve();

for (int item = 0; item < problem.Items; item++)
for (int day = 0; day < problem.Days - 1; day++)
if ((solution.Allocations[item, day] >= fromSlot1) &&
((solution.Allocations[item, day] <= toSlot1)))
Assert.That(solution.Allocations[item, day + 1], Is.Null.Or.Not.InRange(fromSlot2, toSlot2));
for (int day = 0; day < problem.Days - 1; day++)
for (int slot = fromSlot1; slot <= toSlot1; slot++)
{
if (day < problem.Days - 2)
{
var chosenItem = solution.Allocations[day, slot];
if (chosenItem.HasValue)
for (int slot2 = fromSlot2; slot2 <= toSlot2; slot2++)
Assert.That(solution.Allocations[day + 1, slot2], Is.Null.Or.Not.EqualTo(chosenItem));
}
}
}
}
}
8 changes: 4 additions & 4 deletions sources/NaturalShift.IntegrationTests/TestSlotClosure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using NaturalShift.Model.ProblemModel.FluentInterfaces;
using NaturalShift.SolvingEnvironment;
using NUnit.Framework;
using System;

namespace NaturalShift.IntegrationTests
{
Expand Down Expand Up @@ -72,9 +72,9 @@ public void ClosedSlotsAreEmpty()

var solution = solvingEnvironment.Solve();

for (int item = 0; item < problem.Items; item++)
for (int day = fromDay; day <= toDay; day++)
Assert.That(solution.Allocations[item, day], Is.Null.Or.Not.InRange(fromSlot, toSlot));
for (int day = fromDay; day <= toDay; day++)
for (int slot = fromSlot; slot <= toSlot; slot++)
Assert.That(solution.Allocations[day, slot], Is.Null);
}
}
}
8 changes: 4 additions & 4 deletions sources/NaturalShift.IntegrationTests/TestUnavailableItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using NaturalShift.Model.ProblemModel.FluentInterfaces;
using NaturalShift.SolvingEnvironment;
using NUnit.Framework;
using System;

namespace NaturalShift.IntegrationTests
{
Expand Down Expand Up @@ -81,9 +81,9 @@ public void UnavailableItemDoesntShift()

var solution = solvingEnvironment.Solve();

for (int item = fromItem; item <= toItem; item++)
for (int day = fromDay; day <= toDay; day++)
Assert.That(solution.Allocations[item, day], Is.Null.Or.Not.InRange(fromSlot, toSlot));
for (int day = fromDay; day <= toDay; day++)
for (int slot = fromSlot; slot <= toSlot; slot++)
Assert.That(solution.Allocations[day, slot], Is.Null.Or.Not.InRange(fromItem, toItem));
}
}
}
2 changes: 1 addition & 1 deletion sources/NaturalShift.UnitTests/TestAllocationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using Moq;
using NaturalShift.SolvingEnvironment.ItemSelectors;
using NaturalShift.SolvingEnvironment.Matrix;
using NUnit.Framework;
using System;

namespace NaturalShift.UnitTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using NaturalShift.SolvingEnvironment;
using NUnit.Framework;
using System;

namespace NaturalShift.UnitTests
{
Expand Down
2 changes: 1 addition & 1 deletion sources/NaturalShift.UnitTests/TestIntRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using NaturalShift.Model.ProblemModel;
using NUnit.Framework;
using System;

namespace NaturalShift.UnitTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using Moq;
using NaturalShift.Model.ProblemModel;
using NaturalShift.SolvingEnvironment;
using NUnit.Framework;
using System;

namespace NaturalShift.UnitTests
{
Expand Down
2 changes: 1 addition & 1 deletion sources/NaturalShift.UnitTests/TestProblem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using NaturalShift.Model.ProblemModel;
using NUnit.Framework;
using System;

namespace NaturalShift.UnitTests
{
Expand Down
2 changes: 1 addition & 1 deletion sources/NaturalShift.UnitTests/TestProblemBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using NaturalShift.Model.ProblemModel.FluentInterfaces;
using NUnit.Framework;
using System;

namespace NaturalShift.UnitTests
{
Expand Down
2 changes: 1 addition & 1 deletion sources/NaturalShift.UnitTests/TestRouletteWheel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using NaturalShift.SolvingEnvironment.ItemSelectors;
using NUnit.Framework;
using System;

namespace NaturalShift.UnitTests
{
Expand Down
2 changes: 1 addition & 1 deletion sources/NaturalShift.UnitTests/TestShiftMatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using NaturalShift.SolvingEnvironment.Matrix;
using NUnit.Framework;
using System;

namespace NaturalShift.UnitTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using Moq;
using NaturalShift.Model.ProblemModel;
using NaturalShift.SolvingEnvironment;
using NUnit.Framework;
using System;

namespace NaturalShift.UnitTests
{
Expand Down
2 changes: 1 addition & 1 deletion sources/NaturalShift/Model/SolutionModel/ISolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace NaturalShift.Model.SolutionModel
public interface ISolution
{
/// <summary>
/// The matrix [item, day] whose value is the slot index covered (if any).
/// The matrix [day, slot] whose value is the item index covering the slot in the day (if any).
/// </summary>
int?[,] Allocations { get; }

Expand Down
39 changes: 34 additions & 5 deletions sources/NaturalShift/Model/SolutionModel/Solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System.Collections.Generic;
using System.Text;

namespace NaturalShift.Model.SolutionModel
{
public class Solution : ISolution
{
private readonly int numberOfItems;

public Solution(int numberOfItems)
{
this.numberOfItems = numberOfItems;
}

public double Fitness { get; set; }
public int?[,] Allocations { get; set; }
public int EvaluatedSolutions { get; set; }
Expand All @@ -36,18 +44,39 @@ public override string ToString()
sb.AppendLine(Fitness.ToString());
sb.Append("Evaluated solutions: ");
sb.AppendLine(EvaluatedSolutions.ToString());
for (int item = 0; item < Allocations.GetLength(0); item++)

for (int item = 0; item < numberOfItems; item++)
{
for (int day = 0; day < Allocations.GetLength(1); day++)
for (int day = 0; day < Allocations.GetLength(0); day++)
{
sb.Append(Allocations[item, day].HasValue ? Allocations[item, day].Value.ToString().PadLeft(3) : " -");
if (day < Allocations.GetLength(1) - 1)
sb.Append(",");
var shifts = new List<int>();
for (int slot = 0; slot < Allocations.GetLength(1); slot++)
{
if (Allocations[day, slot] == item)
shifts.Add(slot);
}

sb.Append(shiftsToString(shifts));

if (day < Allocations.GetLength(0) - 1)
sb.Append(", ");
}
sb.AppendLine();
}

return sb.ToString();
}

private string shiftsToString(List<int> shifts)
{
if (shifts.Count == 0)
return " -";

if (shifts.Count == 1)
return shifts[0].ToString().PadLeft(2);

var joinedShifts = string.Join(",", shifts);
return string.Format("({0})", joinedShifts);
}
}
}
11 changes: 9 additions & 2 deletions sources/NaturalShift/NaturalShift.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
<owners>supix</owners>
<licenseUrl>https://www.gnu.org/licenses/agpl-3.0.en.html</licenseUrl>
<projectUrl>https://github.com/supix/NaturalShift</projectUrl>
<iconUrl>https://s12.postimg.org/mpp0zumf1/Logo.png</iconUrl>
<iconUrl>https://s17.postimg.org/s9ditc3an/Natural_Shift_Logo.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>XML documentation file is distributed along with the main assembly.</releaseNotes>
<releaseNotes> Bug fix on solution encoding.

Solution encoding allows for multiple slots
covered by the same item in the same day (which is possible in case of
compatible slots enabled in problem configuration).

Solution.ToString() method handles this case as well: for instance, if the
1st and 2nd slots are simultaneously covered, the solution shows the string `(1, 2)`.</releaseNotes>
<copyright>Copyright 2016-2017</copyright>
<tags>workshift shift fair arrangement shifter table night genetic</tags>
</metadata>
Expand Down
4 changes: 2 additions & 2 deletions sources/NaturalShift/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: InternalsVisibleTo("NaturalShift.UnitTests")]
[assembly: InternalsVisibleTo("NaturalShift.IntegrationTests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using NaturalShift.SolvingEnvironment.Constraints;
using NaturalShift.SolvingEnvironment.Matrix;
using NaturalShift.SolvingEnvironment.MatrixEnumerators;
using System;
using System.Collections.Generic;

namespace NaturalShift.SolvingEnvironment.Chromosomes
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using NaturalShift.SolvingEnvironment.Utils;
using System;
using NaturalShift.SolvingEnvironment.Utils;

namespace NaturalShift.SolvingEnvironment
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using NaturalShift.SolvingEnvironment.Matrix;
using System;
using NaturalShift.SolvingEnvironment.Matrix;

namespace NaturalShift.SolvingEnvironment.Constraints
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using NaturalShift.Model.ProblemModel;
using System.Collections.Generic;
using NaturalShift.Model.ProblemModel;

namespace NaturalShift.SolvingEnvironment.Constraints
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using NaturalShift.SolvingEnvironment.Matrix;
using System;
using NaturalShift.SolvingEnvironment.Matrix;

namespace NaturalShift.SolvingEnvironment.Constraints
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using NaturalShift.SolvingEnvironment.Matrix;
using System;
using NaturalShift.SolvingEnvironment.Matrix;

namespace NaturalShift.SolvingEnvironment.Constraints
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using NaturalShift.SolvingEnvironment.Matrix;
using System;
using System.Diagnostics;
using NaturalShift.SolvingEnvironment.Matrix;

namespace NaturalShift.SolvingEnvironment.Fitness
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
//-----------------------------------------------------------------------
using NaturalShift.SolvingEnvironment.Matrix;
using System;
using System.Diagnostics;
using System.Linq;
using NaturalShift.SolvingEnvironment.Matrix;

namespace NaturalShift.SolvingEnvironment.Fitness
{
Expand Down
Loading

0 comments on commit 59f9937

Please sign in to comment.