git: renormalize some files
wrong clrf
This commit is contained in:
committed by
Corentin Le Molgat
parent
17fc2ae92b
commit
784c4fecb4
@@ -1,150 +1,150 @@
|
||||
// Copyright 2010-2025 Google LLC
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
/// <summary>
|
||||
/// Fill a 60x50 rectangle exactly using a minimum number of non-overlapping squares."""
|
||||
/// </summary>
|
||||
class CoverRectangleSat
|
||||
{
|
||||
static int sizeX = 60;
|
||||
static int sizeY = 50;
|
||||
|
||||
static bool CoverRectangle(int numSquares)
|
||||
{
|
||||
CpModel model = new CpModel();
|
||||
|
||||
var areas = new List<IntVar>();
|
||||
var sizes = new List<IntVar>();
|
||||
var xIntervals = new List<IntervalVar>();
|
||||
var yIntervals = new List<IntervalVar>();
|
||||
var xStarts = new List<IntVar>();
|
||||
var yStarts = new List<IntVar>();
|
||||
|
||||
// Creates intervals for the NoOverlap2D and size variables.
|
||||
foreach (var i in Enumerable.Range(0, numSquares))
|
||||
{
|
||||
var size = model.NewIntVar(1, sizeY, String.Format("size_{0}", i));
|
||||
var startX = model.NewIntVar(0, sizeX, String.Format("startX_{0}", i));
|
||||
var endX = model.NewIntVar(0, sizeX, String.Format("endX_{0}", i));
|
||||
var startY = model.NewIntVar(0, sizeY, String.Format("startY_{0}", i));
|
||||
var endY = model.NewIntVar(0, sizeY, String.Format("endY_{0}", i));
|
||||
|
||||
var intervalX = model.NewIntervalVar(startX, size, endX, String.Format("intervalX_{0}", i));
|
||||
var intervalY = model.NewIntervalVar(startY, size, endY, String.Format("intervalY_{0}", i));
|
||||
|
||||
var area = model.NewIntVar(1, sizeY * sizeY, String.Format("area_{0}", i));
|
||||
model.AddMultiplicationEquality(area, size, size);
|
||||
|
||||
areas.Add(area);
|
||||
xIntervals.Add(intervalX);
|
||||
yIntervals.Add(intervalY);
|
||||
sizes.Add(size);
|
||||
xStarts.Add(startX);
|
||||
yStarts.Add(startY);
|
||||
}
|
||||
|
||||
// Main constraint.
|
||||
NoOverlap2dConstraint noOverlap2d = model.AddNoOverlap2D();
|
||||
foreach (var i in Enumerable.Range(0, numSquares))
|
||||
{
|
||||
noOverlap2d.AddRectangle(xIntervals[i], yIntervals[i]);
|
||||
}
|
||||
|
||||
// Redundant constraints.
|
||||
model.AddCumulative(sizeY).AddDemands(xIntervals, sizes);
|
||||
model.AddCumulative(sizeX).AddDemands(yIntervals, sizes);
|
||||
|
||||
// Forces the rectangle to be exactly covered.
|
||||
model.Add(LinearExpr.Sum(areas) == sizeX * sizeY);
|
||||
|
||||
// Symmetry breaking 1: sizes are ordered.
|
||||
foreach (var i in Enumerable.Range(0, numSquares - 1))
|
||||
{
|
||||
model.Add(sizes[i] <= sizes[i + 1]);
|
||||
|
||||
// Define same to be true iff sizes[i] == sizes[i + 1]
|
||||
var same = model.NewBoolVar("");
|
||||
model.Add(sizes[i] == sizes[i + 1]).OnlyEnforceIf(same);
|
||||
model.Add(sizes[i] < sizes[i + 1]).OnlyEnforceIf(same.Not());
|
||||
|
||||
// Tie break with starts.
|
||||
model.Add(xStarts[i] <= xStarts[i + 1]).OnlyEnforceIf(same);
|
||||
}
|
||||
|
||||
// Symmetry breaking 2: first square in one quadrant.
|
||||
model.Add(xStarts[0] < (sizeX + 1) / 2);
|
||||
model.Add(yStarts[0] < (sizeY + 1) / 2);
|
||||
|
||||
// Creates a solver and solves.
|
||||
var solver = new CpSolver();
|
||||
solver.StringParameters = "num_search_workers:16, log_search_progress: false, max_time_in_seconds:10";
|
||||
var status = solver.Solve(model);
|
||||
Console.WriteLine(string.Format("{0} found in {1:0.00}s", status, solver.WallTime()));
|
||||
|
||||
// Prints solution.
|
||||
bool solution_found = status == CpSolverStatus.Optimal || status == CpSolverStatus.Feasible;
|
||||
if (solution_found)
|
||||
{
|
||||
char[][] output = new char [sizeY][];
|
||||
foreach (var y in Enumerable.Range(0, sizeY))
|
||||
{
|
||||
|
||||
output[y] = new char[sizeX];
|
||||
foreach (var x in Enumerable.Range(0, sizeX))
|
||||
{
|
||||
output[y][x] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var s in Enumerable.Range(0, numSquares))
|
||||
{
|
||||
int startX = (int)solver.Value(xStarts[s]);
|
||||
int startY = (int)solver.Value(yStarts[s]);
|
||||
int size = (int)solver.Value(sizes[s]);
|
||||
char c = (char)(65 + s);
|
||||
foreach (var x in Enumerable.Range(startX, size))
|
||||
{
|
||||
foreach (var y in Enumerable.Range(startY, size))
|
||||
{
|
||||
if (output[y][x] != ' ')
|
||||
{
|
||||
Console.WriteLine(
|
||||
string.Format("Error at position x={0} y{1}, found {2}", x, y, output[y][x]));
|
||||
}
|
||||
output[y][x] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var y in Enumerable.Range(0, sizeY))
|
||||
{
|
||||
Console.WriteLine(new String(output[y], 0, sizeX));
|
||||
}
|
||||
}
|
||||
return solution_found;
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
foreach (int numSquares in Enumerable.Range(1, 15))
|
||||
{
|
||||
Console.WriteLine("Trying with size = {0}", numSquares);
|
||||
if (CoverRectangle(numSquares))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright 2010-2025 Google LLC
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
/// <summary>
|
||||
/// Fill a 60x50 rectangle exactly using a minimum number of non-overlapping squares."""
|
||||
/// </summary>
|
||||
class CoverRectangleSat
|
||||
{
|
||||
static int sizeX = 60;
|
||||
static int sizeY = 50;
|
||||
|
||||
static bool CoverRectangle(int numSquares)
|
||||
{
|
||||
CpModel model = new CpModel();
|
||||
|
||||
var areas = new List<IntVar>();
|
||||
var sizes = new List<IntVar>();
|
||||
var xIntervals = new List<IntervalVar>();
|
||||
var yIntervals = new List<IntervalVar>();
|
||||
var xStarts = new List<IntVar>();
|
||||
var yStarts = new List<IntVar>();
|
||||
|
||||
// Creates intervals for the NoOverlap2D and size variables.
|
||||
foreach (var i in Enumerable.Range(0, numSquares))
|
||||
{
|
||||
var size = model.NewIntVar(1, sizeY, String.Format("size_{0}", i));
|
||||
var startX = model.NewIntVar(0, sizeX, String.Format("startX_{0}", i));
|
||||
var endX = model.NewIntVar(0, sizeX, String.Format("endX_{0}", i));
|
||||
var startY = model.NewIntVar(0, sizeY, String.Format("startY_{0}", i));
|
||||
var endY = model.NewIntVar(0, sizeY, String.Format("endY_{0}", i));
|
||||
|
||||
var intervalX = model.NewIntervalVar(startX, size, endX, String.Format("intervalX_{0}", i));
|
||||
var intervalY = model.NewIntervalVar(startY, size, endY, String.Format("intervalY_{0}", i));
|
||||
|
||||
var area = model.NewIntVar(1, sizeY * sizeY, String.Format("area_{0}", i));
|
||||
model.AddMultiplicationEquality(area, size, size);
|
||||
|
||||
areas.Add(area);
|
||||
xIntervals.Add(intervalX);
|
||||
yIntervals.Add(intervalY);
|
||||
sizes.Add(size);
|
||||
xStarts.Add(startX);
|
||||
yStarts.Add(startY);
|
||||
}
|
||||
|
||||
// Main constraint.
|
||||
NoOverlap2dConstraint noOverlap2d = model.AddNoOverlap2D();
|
||||
foreach (var i in Enumerable.Range(0, numSquares))
|
||||
{
|
||||
noOverlap2d.AddRectangle(xIntervals[i], yIntervals[i]);
|
||||
}
|
||||
|
||||
// Redundant constraints.
|
||||
model.AddCumulative(sizeY).AddDemands(xIntervals, sizes);
|
||||
model.AddCumulative(sizeX).AddDemands(yIntervals, sizes);
|
||||
|
||||
// Forces the rectangle to be exactly covered.
|
||||
model.Add(LinearExpr.Sum(areas) == sizeX * sizeY);
|
||||
|
||||
// Symmetry breaking 1: sizes are ordered.
|
||||
foreach (var i in Enumerable.Range(0, numSquares - 1))
|
||||
{
|
||||
model.Add(sizes[i] <= sizes[i + 1]);
|
||||
|
||||
// Define same to be true iff sizes[i] == sizes[i + 1]
|
||||
var same = model.NewBoolVar("");
|
||||
model.Add(sizes[i] == sizes[i + 1]).OnlyEnforceIf(same);
|
||||
model.Add(sizes[i] < sizes[i + 1]).OnlyEnforceIf(same.Not());
|
||||
|
||||
// Tie break with starts.
|
||||
model.Add(xStarts[i] <= xStarts[i + 1]).OnlyEnforceIf(same);
|
||||
}
|
||||
|
||||
// Symmetry breaking 2: first square in one quadrant.
|
||||
model.Add(xStarts[0] < (sizeX + 1) / 2);
|
||||
model.Add(yStarts[0] < (sizeY + 1) / 2);
|
||||
|
||||
// Creates a solver and solves.
|
||||
var solver = new CpSolver();
|
||||
solver.StringParameters = "num_search_workers:16, log_search_progress: false, max_time_in_seconds:10";
|
||||
var status = solver.Solve(model);
|
||||
Console.WriteLine(string.Format("{0} found in {1:0.00}s", status, solver.WallTime()));
|
||||
|
||||
// Prints solution.
|
||||
bool solution_found = status == CpSolverStatus.Optimal || status == CpSolverStatus.Feasible;
|
||||
if (solution_found)
|
||||
{
|
||||
char[][] output = new char [sizeY][];
|
||||
foreach (var y in Enumerable.Range(0, sizeY))
|
||||
{
|
||||
|
||||
output[y] = new char[sizeX];
|
||||
foreach (var x in Enumerable.Range(0, sizeX))
|
||||
{
|
||||
output[y][x] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var s in Enumerable.Range(0, numSquares))
|
||||
{
|
||||
int startX = (int)solver.Value(xStarts[s]);
|
||||
int startY = (int)solver.Value(yStarts[s]);
|
||||
int size = (int)solver.Value(sizes[s]);
|
||||
char c = (char)(65 + s);
|
||||
foreach (var x in Enumerable.Range(startX, size))
|
||||
{
|
||||
foreach (var y in Enumerable.Range(startY, size))
|
||||
{
|
||||
if (output[y][x] != ' ')
|
||||
{
|
||||
Console.WriteLine(
|
||||
string.Format("Error at position x={0} y{1}, found {2}", x, y, output[y][x]));
|
||||
}
|
||||
output[y][x] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var y in Enumerable.Range(0, sizeY))
|
||||
{
|
||||
Console.WriteLine(new String(output[y], 0, sizeX));
|
||||
}
|
||||
}
|
||||
return solution_found;
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
foreach (int numSquares in Enumerable.Range(1, 15))
|
||||
{
|
||||
Console.WriteLine("Trying with size = {0}", numSquares);
|
||||
if (CoverRectangle(numSquares))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,199 +1,199 @@
|
||||
// Copyright 2010-2025 Google LLC
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
class Job
|
||||
{
|
||||
public Job(List<Task> tasks)
|
||||
{
|
||||
AlternativeTasks = tasks;
|
||||
}
|
||||
public Job Successor { get; set; }
|
||||
public List<Task> AlternativeTasks { get; set; }
|
||||
}
|
||||
|
||||
class Task
|
||||
{
|
||||
public Task(string name, long duration, long equipment)
|
||||
{
|
||||
Name = name;
|
||||
Duration = duration;
|
||||
Equipment = equipment;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public long StartTime { get; set; }
|
||||
public long EndTime
|
||||
{
|
||||
get {
|
||||
return StartTime + Duration;
|
||||
}
|
||||
}
|
||||
public long Duration { get; set; }
|
||||
public long Equipment { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name + " [ " + Equipment + " ]\tstarts: " + StartTime + " ends:" + EndTime + ", duration: " + Duration;
|
||||
}
|
||||
}
|
||||
|
||||
class TaskSchedulingSat
|
||||
{
|
||||
public static List<Job> myJobList = new List<Job>();
|
||||
public static Dictionary<long, List<IntervalVar>> tasksToEquipment = new Dictionary<long, List<IntervalVar>>();
|
||||
public static Dictionary<string, long> taskIndexes = new Dictionary<string, long>();
|
||||
|
||||
public static void InitTaskList()
|
||||
{
|
||||
List<Task> taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job1Task0a", 15, 0));
|
||||
taskList.Add(new Task("Job1Task0b", 25, 1));
|
||||
taskList.Add(new Task("Job1Task0c", 10, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job1Task1a", 25, 0));
|
||||
taskList.Add(new Task("Job1Task1b", 30, 1));
|
||||
taskList.Add(new Task("Job1Task1c", 40, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job1Task2a", 20, 0));
|
||||
taskList.Add(new Task("Job1Task2b", 35, 1));
|
||||
taskList.Add(new Task("Job1Task2c", 10, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job2Task0a", 15, 0));
|
||||
taskList.Add(new Task("Job2Task0b", 25, 1));
|
||||
taskList.Add(new Task("Job2Task0c", 10, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job2Task1a", 25, 0));
|
||||
taskList.Add(new Task("Job2Task1b", 30, 1));
|
||||
taskList.Add(new Task("Job2Task1c", 40, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job2Task2a", 20, 0));
|
||||
taskList.Add(new Task("Job2Task2b", 35, 1));
|
||||
taskList.Add(new Task("Job2Task2c", 10, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job3Task0a", 10, 0));
|
||||
taskList.Add(new Task("Job3Task0b", 15, 1));
|
||||
taskList.Add(new Task("Job3Task0c", 50, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job3Task1a", 50, 0));
|
||||
taskList.Add(new Task("Job3Task1b", 10, 1));
|
||||
taskList.Add(new Task("Job3Task1c", 20, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job3Task2a", 65, 0));
|
||||
taskList.Add(new Task("Job3Task2b", 5, 1));
|
||||
taskList.Add(new Task("Job3Task2c", 15, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
myJobList[0].Successor = myJobList[1];
|
||||
myJobList[1].Successor = myJobList[2];
|
||||
myJobList[2].Successor = null;
|
||||
|
||||
myJobList[3].Successor = myJobList[4];
|
||||
myJobList[4].Successor = myJobList[5];
|
||||
myJobList[5].Successor = null;
|
||||
|
||||
myJobList[6].Successor = myJobList[7];
|
||||
myJobList[7].Successor = myJobList[8];
|
||||
myJobList[8].Successor = null;
|
||||
}
|
||||
|
||||
public static int GetTaskCount()
|
||||
{
|
||||
int c = 0;
|
||||
foreach (Job j in myJobList)
|
||||
foreach (Task t in j.AlternativeTasks)
|
||||
{
|
||||
taskIndexes[t.Name] = c;
|
||||
c++;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public static int GetEndTaskCount()
|
||||
{
|
||||
int c = 0;
|
||||
foreach (Job j in myJobList)
|
||||
if (j.Successor == null)
|
||||
c += j.AlternativeTasks.Count;
|
||||
return c;
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
InitTaskList();
|
||||
int taskCount = GetTaskCount();
|
||||
|
||||
CpModel model = new CpModel();
|
||||
|
||||
IntervalVar[] tasks = new IntervalVar[taskCount];
|
||||
BoolVar[] taskChoosed = new BoolVar[taskCount];
|
||||
IntVar[] allEnds = new IntVar[GetEndTaskCount()];
|
||||
|
||||
int endJobCounter = 0;
|
||||
foreach (Job j in myJobList)
|
||||
{
|
||||
BoolVar[] tmp = new BoolVar[j.AlternativeTasks.Count];
|
||||
int i = 0;
|
||||
foreach (Task t in j.AlternativeTasks)
|
||||
{
|
||||
long ti = taskIndexes[t.Name];
|
||||
taskChoosed[ti] = model.NewBoolVar(t.Name + "_choose");
|
||||
tmp[i++] = taskChoosed[ti];
|
||||
IntVar start = model.NewIntVar(0, 10000, t.Name + "_start");
|
||||
IntVar end = model.NewIntVar(0, 10000, t.Name + "_end");
|
||||
tasks[ti] = model.NewIntervalVar(start, t.Duration, end, t.Name + "_interval");
|
||||
if (j.Successor == null)
|
||||
allEnds[endJobCounter++] = end;
|
||||
if (!tasksToEquipment.ContainsKey(t.Equipment))
|
||||
tasksToEquipment[t.Equipment] = new List<IntervalVar>();
|
||||
tasksToEquipment[t.Equipment].Add(tasks[ti]);
|
||||
}
|
||||
model.AddExactlyOne(tmp);
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<long, List<IntervalVar>> pair in tasksToEquipment)
|
||||
{
|
||||
model.AddNoOverlap(pair.Value);
|
||||
}
|
||||
|
||||
IntVar makespan = model.NewIntVar(0, 100000, "makespan");
|
||||
model.AddMaxEquality(makespan, allEnds);
|
||||
model.Minimize(makespan);
|
||||
|
||||
// Create the solver.
|
||||
CpSolver solver = new CpSolver();
|
||||
// Solve the problem.
|
||||
solver.Solve(model);
|
||||
Console.WriteLine(solver.ResponseStats());
|
||||
}
|
||||
}
|
||||
// Copyright 2010-2025 Google LLC
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Google.OrTools.Sat;
|
||||
|
||||
class Job
|
||||
{
|
||||
public Job(List<Task> tasks)
|
||||
{
|
||||
AlternativeTasks = tasks;
|
||||
}
|
||||
public Job Successor { get; set; }
|
||||
public List<Task> AlternativeTasks { get; set; }
|
||||
}
|
||||
|
||||
class Task
|
||||
{
|
||||
public Task(string name, long duration, long equipment)
|
||||
{
|
||||
Name = name;
|
||||
Duration = duration;
|
||||
Equipment = equipment;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public long StartTime { get; set; }
|
||||
public long EndTime
|
||||
{
|
||||
get {
|
||||
return StartTime + Duration;
|
||||
}
|
||||
}
|
||||
public long Duration { get; set; }
|
||||
public long Equipment { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name + " [ " + Equipment + " ]\tstarts: " + StartTime + " ends:" + EndTime + ", duration: " + Duration;
|
||||
}
|
||||
}
|
||||
|
||||
class TaskSchedulingSat
|
||||
{
|
||||
public static List<Job> myJobList = new List<Job>();
|
||||
public static Dictionary<long, List<IntervalVar>> tasksToEquipment = new Dictionary<long, List<IntervalVar>>();
|
||||
public static Dictionary<string, long> taskIndexes = new Dictionary<string, long>();
|
||||
|
||||
public static void InitTaskList()
|
||||
{
|
||||
List<Task> taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job1Task0a", 15, 0));
|
||||
taskList.Add(new Task("Job1Task0b", 25, 1));
|
||||
taskList.Add(new Task("Job1Task0c", 10, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job1Task1a", 25, 0));
|
||||
taskList.Add(new Task("Job1Task1b", 30, 1));
|
||||
taskList.Add(new Task("Job1Task1c", 40, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job1Task2a", 20, 0));
|
||||
taskList.Add(new Task("Job1Task2b", 35, 1));
|
||||
taskList.Add(new Task("Job1Task2c", 10, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job2Task0a", 15, 0));
|
||||
taskList.Add(new Task("Job2Task0b", 25, 1));
|
||||
taskList.Add(new Task("Job2Task0c", 10, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job2Task1a", 25, 0));
|
||||
taskList.Add(new Task("Job2Task1b", 30, 1));
|
||||
taskList.Add(new Task("Job2Task1c", 40, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job2Task2a", 20, 0));
|
||||
taskList.Add(new Task("Job2Task2b", 35, 1));
|
||||
taskList.Add(new Task("Job2Task2c", 10, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job3Task0a", 10, 0));
|
||||
taskList.Add(new Task("Job3Task0b", 15, 1));
|
||||
taskList.Add(new Task("Job3Task0c", 50, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job3Task1a", 50, 0));
|
||||
taskList.Add(new Task("Job3Task1b", 10, 1));
|
||||
taskList.Add(new Task("Job3Task1c", 20, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
taskList = new List<Task>();
|
||||
taskList.Add(new Task("Job3Task2a", 65, 0));
|
||||
taskList.Add(new Task("Job3Task2b", 5, 1));
|
||||
taskList.Add(new Task("Job3Task2c", 15, 2));
|
||||
myJobList.Add(new Job(taskList));
|
||||
|
||||
myJobList[0].Successor = myJobList[1];
|
||||
myJobList[1].Successor = myJobList[2];
|
||||
myJobList[2].Successor = null;
|
||||
|
||||
myJobList[3].Successor = myJobList[4];
|
||||
myJobList[4].Successor = myJobList[5];
|
||||
myJobList[5].Successor = null;
|
||||
|
||||
myJobList[6].Successor = myJobList[7];
|
||||
myJobList[7].Successor = myJobList[8];
|
||||
myJobList[8].Successor = null;
|
||||
}
|
||||
|
||||
public static int GetTaskCount()
|
||||
{
|
||||
int c = 0;
|
||||
foreach (Job j in myJobList)
|
||||
foreach (Task t in j.AlternativeTasks)
|
||||
{
|
||||
taskIndexes[t.Name] = c;
|
||||
c++;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public static int GetEndTaskCount()
|
||||
{
|
||||
int c = 0;
|
||||
foreach (Job j in myJobList)
|
||||
if (j.Successor == null)
|
||||
c += j.AlternativeTasks.Count;
|
||||
return c;
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
InitTaskList();
|
||||
int taskCount = GetTaskCount();
|
||||
|
||||
CpModel model = new CpModel();
|
||||
|
||||
IntervalVar[] tasks = new IntervalVar[taskCount];
|
||||
BoolVar[] taskChoosed = new BoolVar[taskCount];
|
||||
IntVar[] allEnds = new IntVar[GetEndTaskCount()];
|
||||
|
||||
int endJobCounter = 0;
|
||||
foreach (Job j in myJobList)
|
||||
{
|
||||
BoolVar[] tmp = new BoolVar[j.AlternativeTasks.Count];
|
||||
int i = 0;
|
||||
foreach (Task t in j.AlternativeTasks)
|
||||
{
|
||||
long ti = taskIndexes[t.Name];
|
||||
taskChoosed[ti] = model.NewBoolVar(t.Name + "_choose");
|
||||
tmp[i++] = taskChoosed[ti];
|
||||
IntVar start = model.NewIntVar(0, 10000, t.Name + "_start");
|
||||
IntVar end = model.NewIntVar(0, 10000, t.Name + "_end");
|
||||
tasks[ti] = model.NewIntervalVar(start, t.Duration, end, t.Name + "_interval");
|
||||
if (j.Successor == null)
|
||||
allEnds[endJobCounter++] = end;
|
||||
if (!tasksToEquipment.ContainsKey(t.Equipment))
|
||||
tasksToEquipment[t.Equipment] = new List<IntervalVar>();
|
||||
tasksToEquipment[t.Equipment].Add(tasks[ti]);
|
||||
}
|
||||
model.AddExactlyOne(tmp);
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<long, List<IntervalVar>> pair in tasksToEquipment)
|
||||
{
|
||||
model.AddNoOverlap(pair.Value);
|
||||
}
|
||||
|
||||
IntVar makespan = model.NewIntVar(0, 100000, "makespan");
|
||||
model.AddMaxEquality(makespan, allEnds);
|
||||
model.Minimize(makespan);
|
||||
|
||||
// Create the solver.
|
||||
CpSolver solver = new CpSolver();
|
||||
// Solve the problem.
|
||||
solver.Solve(model);
|
||||
Console.WriteLine(solver.ResponseStats());
|
||||
}
|
||||
}
|
||||
|
||||
102
examples/python/testdata/salbp_20_1.alb
vendored
102
examples/python/testdata/salbp_20_1.alb
vendored
@@ -1,51 +1,51 @@
|
||||
<number of tasks>
|
||||
20
|
||||
|
||||
<cycle time>
|
||||
1000
|
||||
|
||||
<order strength>
|
||||
0,268
|
||||
|
||||
|
||||
<task times>
|
||||
1 142
|
||||
2 34
|
||||
3 140
|
||||
4 214
|
||||
5 121
|
||||
6 279
|
||||
7 50
|
||||
8 282
|
||||
9 129
|
||||
10 175
|
||||
11 97
|
||||
12 132
|
||||
13 107
|
||||
14 132
|
||||
15 69
|
||||
16 169
|
||||
17 73
|
||||
18 231
|
||||
19 120
|
||||
20 186
|
||||
|
||||
<precedence relations>
|
||||
1,6
|
||||
2,7
|
||||
4,8
|
||||
5,9
|
||||
6,10
|
||||
7,11
|
||||
8,12
|
||||
10,13
|
||||
11,13
|
||||
12,14
|
||||
12,15
|
||||
13,16
|
||||
13,17
|
||||
13,18
|
||||
14,20
|
||||
15,19
|
||||
|
||||
<end>
|
||||
<number of tasks>
|
||||
20
|
||||
|
||||
<cycle time>
|
||||
1000
|
||||
|
||||
<order strength>
|
||||
0,268
|
||||
|
||||
|
||||
<task times>
|
||||
1 142
|
||||
2 34
|
||||
3 140
|
||||
4 214
|
||||
5 121
|
||||
6 279
|
||||
7 50
|
||||
8 282
|
||||
9 129
|
||||
10 175
|
||||
11 97
|
||||
12 132
|
||||
13 107
|
||||
14 132
|
||||
15 69
|
||||
16 169
|
||||
17 73
|
||||
18 231
|
||||
19 120
|
||||
20 186
|
||||
|
||||
<precedence relations>
|
||||
1,6
|
||||
2,7
|
||||
4,8
|
||||
5,9
|
||||
6,10
|
||||
7,11
|
||||
8,12
|
||||
10,13
|
||||
11,13
|
||||
12,14
|
||||
12,15
|
||||
13,16
|
||||
13,17
|
||||
13,18
|
||||
14,20
|
||||
15,19
|
||||
|
||||
<end>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,37 +1,37 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26124.0
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.OrTools.runtime.linux-x64", "Google.OrTools.runtime.linux-x64\Google.OrTools.runtime.linux-x64.csproj", "{FC646C34-8541-427D-B9F6-1247798F4574}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.OrTools.runtime.osx-x64", "Google.OrTools.runtime.osx-x64\Google.OrTools.runtime.osx-x64.csproj", "{FC646C34-8541-427D-B9F6-1247798F4574}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.OrTools.runtime.win-x64", "Google.OrTools.runtime.win-x64\Google.OrTools.runtime.win-x64.csproj", "{FC646C34-8541-427D-B9F6-1247798F4574}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.OrTools", "Google.OrTools\Google.OrTools.csproj", "{FC646C34-8541-427D-B9F6-1247798F4574}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|x64.Build.0 = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26124.0
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.OrTools.runtime.linux-x64", "Google.OrTools.runtime.linux-x64\Google.OrTools.runtime.linux-x64.csproj", "{FC646C34-8541-427D-B9F6-1247798F4574}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.OrTools.runtime.osx-x64", "Google.OrTools.runtime.osx-x64\Google.OrTools.runtime.osx-x64.csproj", "{FC646C34-8541-427D-B9F6-1247798F4574}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.OrTools.runtime.win-x64", "Google.OrTools.runtime.win-x64\Google.OrTools.runtime.win-x64.csproj", "{FC646C34-8541-427D-B9F6-1247798F4574}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.OrTools", "Google.OrTools\Google.OrTools.csproj", "{FC646C34-8541-427D-B9F6-1247798F4574}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|x64.Build.0 = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{FC646C34-8541-427D-B9F6-1247798F4574}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
21
|
||||
1 682 266
|
||||
2 129 265 0 12
|
||||
3 298 495 0 13
|
||||
4 720 160 0 14
|
||||
5 93 10 0 15
|
||||
6 891 782 0 16
|
||||
7 888 533 0 17
|
||||
8 414 290 0 18
|
||||
9 61 22 0 19
|
||||
10 485 352 0 20
|
||||
11 817 619 0 21
|
||||
12 669 775 1 2
|
||||
13 628 117 1 3
|
||||
14 178 31 1 4
|
||||
15 733 97 1 5
|
||||
16 985 320 1 6
|
||||
17 319 0 1 7
|
||||
18 545 283 1 8
|
||||
19 331 664 1 9
|
||||
20 598 785 1 10
|
||||
21 245 810 1 11
|
||||
-999
|
||||
21
|
||||
1 682 266
|
||||
2 129 265 0 12
|
||||
3 298 495 0 13
|
||||
4 720 160 0 14
|
||||
5 93 10 0 15
|
||||
6 891 782 0 16
|
||||
7 888 533 0 17
|
||||
8 414 290 0 18
|
||||
9 61 22 0 19
|
||||
10 485 352 0 20
|
||||
11 817 619 0 21
|
||||
12 669 775 1 2
|
||||
13 628 117 1 3
|
||||
14 178 31 1 4
|
||||
15 733 97 1 5
|
||||
16 985 320 1 6
|
||||
17 319 0 1 7
|
||||
18 545 283 1 8
|
||||
19 331 664 1 9
|
||||
20 598 785 1 10
|
||||
21 245 810 1 11
|
||||
-999
|
||||
|
||||
Reference in New Issue
Block a user