Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into merschformann/support…
Browse files Browse the repository at this point in the history
…-max-weight
  • Loading branch information
merschformann committed Nov 4, 2024
2 parents 3f07433 + 9241226 commit 19a787d
Show file tree
Hide file tree
Showing 31 changed files with 1,272 additions and 114 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ignore build directories
bin/
obj/

# Ignore some project files
.git/
.vs/
8 changes: 2 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
dotnet-version: ["7.0.x"]
dotnet-version: ["8.0.x"]

steps:
- uses: actions/checkout@v4
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v1.7.2
uses: actions/setup-dotnet@v4.1.0
with:
dotnet-version: ${{ matrix.dotnet-version }}
# - name: Validate version consistency
# run: bash validate-version-consistency.sh
# working-directory: ./Material/Scripts
# shell: bash
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/publish.yml

This file was deleted.

94 changes: 94 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: release
run-name: Release ${{ inputs.VERSION }} by @${{ github.actor }} from ${{ github.ref_name }}

on:
workflow_dispatch:
inputs:
VERSION:
description: "The version to release (e.g. 1.0.0)"
required: true

jobs:
release:
runs-on: ubuntu-latest
env:
VERSION: ${{ inputs.VERSION }}
GH_TOKEN: ${{ github.token }}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
permissions:
contents: write
steps:
- name: configure git with the bot credentials
run: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.BOT_SSH_KEY }}"
echo "${{ secrets.BOT_SIGNING_KEY }}" > ~/.ssh/signing.key
chmod 600 ~/.ssh/signing.key
git config --global user.name "Merschbotmann"
git config --global user.email "bot.merschformann@gmail.com"
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/signing.key
git clone git@github.com:merschformann/sardine-can.git
cd sardine-can
git checkout ${{ github.ref_name }}
git rev-parse --short HEAD
- name: bump version in project
run: |
python Material/Scripts/release.py --version $VERSION
working-directory: ./sardine-can

- name: commit version bump
run: |
git commit -am "Bumping version to $VERSION"
git push origin ${{ github.ref_name }}
working-directory: ./sardine-can

- name: push release tag
run: |
git tag $VERSION
git push origin $VERSION
working-directory: ./sardine-can

- name: create release
run: |
gh release create $VERSION \
--verify-tag \
--generate-notes \
--title $VERSION
working-directory: ./sardine-can

docker-image:
runs-on: ubuntu-24.04
needs: release

steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.VERSION }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Get version
run: |
echo "VERSION=$(cat VERSION.txt)" >> $GITHUB_ENV
- name: Build the SardineCan Docker image
run: |
echo "Building SardineCan docker in ${{ env.VERSION }}"
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
export LATEST_TAG="ghcr.io/merschformann/sardinecan:latest"
export VERSION_TAG="ghcr.io/merschformann/sardinecan:${{ env.VERSION }}"
docker buildx build --platform linux/amd64,linux/arm64 --push -t $LATEST_TAG -t $VERSION_TAG -f Dockerfile ..
working-directory: ./SC.Service
87 changes: 87 additions & 0 deletions Material/Scripts/release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import argparse
import glob
import os
import re
import xml.etree.ElementTree as ET

VERSION_FILE = os.path.join(os.path.dirname(__file__), "..", "..", "VERSION.txt")


def parse_args() -> argparse.Namespace:
"""
Parse command line arguments.
"""
parser = argparse.ArgumentParser(description="Bump the version of the project.")
parser.add_argument("--version", required=True, help="The version to bump to.")
return parser.parse_args()


def check_version(version: str) -> None:
"""
Check whether a given version is in expected format and actually newer than the
current version.
"""
if not re.match(r"^\d+\.\d+\.\d+$", version):
raise Exception(f"Version {version} is not in the format x.y.z")

with open(VERSION_FILE, "r") as f:
current_version = f.read().strip()

def parse_version(version: str):
return tuple(map(int, version.split(".")))

if parse_version(version) <= parse_version(current_version):
raise Exception(
f"New version {version} is not newer than current version {current_version}"
)


def bump_version_csproj(csproj_file: str, version: str) -> None:
"""
Bump the version of a csproj file.
"""
try:
tree = ET.parse(csproj_file)
root = tree.getroot()

bumped = False
for elem in root.iter():
if elem.tag == "Version":
elem.text = version
bumped = True

if not bumped:
raise Exception("No version element found")

tree.write(csproj_file)
except Exception as e:
print(f"Error bumping version in {csproj_file}: {e}")


def bump_version_main(version: str) -> None:
"""
Bump the main version file.
"""
with open(VERSION_FILE, "w") as f:
f.write(version)


def main() -> None:
args = parse_args()
version = args.version

check_version(version)

csproj_files = glob.glob(
os.path.join(os.path.dirname(__file__), "..", "..", "**", "*.csproj"),
recursive=True,
)
for csproj_file in csproj_files:
if "Test" in csproj_file:
continue
bump_version_csproj(csproj_file, version)
bump_version_main(version)


if __name__ == "__main__":
main()
28 changes: 0 additions & 28 deletions Material/Scripts/validate-version-consistency.sh

This file was deleted.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<img src="Material/Icon/sardines.svg" align="left" height="60"/>

# SardineCan
# SardineCan <img src='Material/Icon/sardines.svg' align="right" height="90" />

SardineCan is a humble 3D knapsack / bin packing solver with some special
constraints. It is a collection of constructive heuristics, meta-heuristic
Expand Down
4 changes: 2 additions & 2 deletions SC.CLI/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ private static void LogConfigDetails(Configuration config, Action<string> logger
else
{
if (toStringMethod != null)
value = toStringMethod.Invoke(field.GetValue(config), new object[] { CultureInfo.InvariantCulture }).ToString();
value = toStringMethod.Invoke(field.GetValue(config), new object[] { CultureInfo.InvariantCulture })?.ToString();
else
value = field.GetValue(config).ToString();
value = field.GetValue(config)?.ToString();
}
}
// Output it
Expand Down
7 changes: 4 additions & 3 deletions SC.CLI/SC.CLI.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Version>1.0.12</Version>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<InvariantGlobalization>true</InvariantGlobalization>
Expand All @@ -18,4 +19,4 @@
<ProjectReference Include="..\SC.Linear\SC.Linear.csproj" />
</ItemGroup>

</Project>
</Project>
8 changes: 4 additions & 4 deletions SC.DataPreparation/SC.DataPreparation.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<Version>1.0.6</Version>
<TargetFramework>net8.0</TargetFramework>
<Version>1.0.12</Version>
<SelfContained>true</SelfContained>
</PropertyGroup>

Expand All @@ -12,4 +12,4 @@
<ProjectReference Include="..\SC.ObjectModel\SC.ObjectModel.csproj" />
</ItemGroup>

</Project>
</Project>
8 changes: 4 additions & 4 deletions SC.GUI/SC.GUI.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<UseWPF>true</UseWPF>
<ApplicationIcon>Logo.ico</ApplicationIcon>
<Version>1.0.6</Version>
<Version>1.0.12</Version>
<SelfContained>true</SelfContained>
</PropertyGroup>

Expand Down Expand Up @@ -103,4 +103,4 @@
</EmbeddedResource>
</ItemGroup>

</Project>
</Project>
2 changes: 1 addition & 1 deletion SC.Heuristics/Heuristic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class Heuristic : IMethod
/// <summary>
/// Indicates whether the timelimit is reached. <code>true</code> if the timelimit is exceeded, <code>false</code> otherwise.
/// </summary>
public bool TimeUp { get { return (TimeSpan.MaxValue == Config.TimeLimit) ? false : DateTime.Now > TimeStart + Config.TimeLimit; } }
public bool TimeUp { get { return TimeSpan.MaxValue != Config.TimeLimit && DateTime.Now > TimeStart + Config.TimeLimit; } }

/// <summary>
/// The overall available volume across all containers
Expand Down
5 changes: 4 additions & 1 deletion SC.Heuristics/PrimalHeuristic/ALNS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ protected override void Solve()
currentIteration++;
currentIntervalIteration++;

} while (currentIteration - lastImprovement < Config.StagnationDistance && !Cancelled && !TimeUp);
} while (currentIteration - lastImprovement < Config.StagnationDistance &&
!Cancelled &&
!TimeUp &&
IterationsReached(currentIteration));
}

#endregion
Expand Down
5 changes: 5 additions & 0 deletions SC.Heuristics/PrimalHeuristic/PointInsertionSkeletonBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ public abstract partial class PointInsertionSkeleton : Heuristic
/// Checks whether a solution is available. (Since an empty solution is always valid, a valid solution is always available)
/// </summary>
public override bool HasSolution { get { return true; } }

/// <summary>
/// Indicates whether the maximum number of iterations is reached.
/// </summary>
public bool IterationsReached(int current) => Config.IterationsLimit >= 0 && current >= Config.IterationsLimit;
}
}
7 changes: 6 additions & 1 deletion SC.Heuristics/PrimalHeuristic/PointInsertionSkeletonLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2252,8 +2252,13 @@ protected COSolution GASP(COSolution solution, List<Container> containers, List<
// Init solution
COSolution localSolution = Instance.CreateSolution(Config.Tetris, Config.MeritType, true);



// Start improvement
while (currentIteration - lastImprovement < Config.StagnationDistance && !Cancelled && !TimeUp)
while (currentIteration - lastImprovement < Config.StagnationDistance &&
!Cancelled &&
!TimeUp &&
!IterationsReached(currentIteration))
{
// Break if all pieces packed (can only break when minimization of container count is impossible)
if (solution.NumberOfContainersInUse == 1 && solution.NumberOfPiecesPacked == Instance.Pieces.Count)
Expand Down
Loading

0 comments on commit 19a787d

Please sign in to comment.