diff --git a/AspectedRouting.Test/FunctionsTest.cs b/AspectedRouting.Test/FunctionsTest.cs
index 8f32bd2..6893597 100644
--- a/AspectedRouting.Test/FunctionsTest.cs
+++ b/AspectedRouting.Test/FunctionsTest.cs
@@ -329,12 +329,17 @@ namespace AspectedRouting.Test
[Fact]
public void SpecializeToCommonType()
{
- var p0 = Funcs.Parse;
- var p1 = Funcs.Const.Apply(new Constant(1.0));
+ var p0 = Funcs.Parse.Specialize(new Curry(Typs.String, Typs.PDouble));
+ var p1 = Funcs.Const.Apply(new Constant(1.0)).Specialize(
+ new Curry(new Var("a"), Typs.Double));
var exprs = new[] {p0, p1};
- var newTypes = exprs.SpecializeToCommonTypes(out var specializedExpressions);
- Assert.Single(newTypes);
+ var newTypes = exprs.SpecializeToCommonTypes(out var _);
+ Assert.Single( newTypes);
+
+ exprs = new[] {p1, p0};
+ newTypes = exprs.SpecializeToCommonTypes(out var _);
+ Assert.Single( newTypes);
}
}
}
\ No newline at end of file
diff --git a/AspectedRouting.Test/TestInterpreter.cs b/AspectedRouting.Test/TestInterpreter.cs
index 1a3012b..3980c94 100644
--- a/AspectedRouting.Test/TestInterpreter.cs
+++ b/AspectedRouting.Test/TestInterpreter.cs
@@ -25,7 +25,7 @@ namespace AspectedRouting.Test
{"ferry", "yes"}
};
- Assert.Equal("tags -> double", string.Join(", ", aspect.Types));
+ Assert.Equal("tags -> pdouble", string.Join(", ", aspect.Types));
Assert.Equal(42d, new Apply(aspect, new Constant(tags)).Evaluate(null));
}
diff --git a/AspectedRouting.sln.DotSettings.user b/AspectedRouting.sln.DotSettings.user
index 4fccd45..be5cd77 100644
--- a/AspectedRouting.sln.DotSettings.user
+++ b/AspectedRouting.sln.DotSettings.user
@@ -1,9 +1,4 @@
- <SessionState ContinuousTestingIsOn="False" ContinuousTestingMode="0" FrameworkVersion="{x:Null}" IsLocked="False" Name="All tests from <AspectedRouting.Test>" PlatformMonoPreference="{x:Null}" PlatformType="{x:Null}" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+ <SessionState ContinuousTestingIsOn="False" ContinuousTestingMode="0" FrameworkVersion="{x:Null}" IsLocked="False" Name="All tests from <AspectedRouting.Test>" PlatformMonoPreference="{x:Null}" PlatformType="{x:Null}" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Project Location="/home/pietervdvn/werk/AspectedRouting/AspectedRouting.Test" Presentation="<AspectedRouting.Test>" />
-</SessionState>
- <SessionState ContinuousTestingIsOn="False" ContinuousTestingMode="0" FrameworkVersion="{x:Null}" IsLocked="False" Name="SpecializeToCommonType" PlatformMonoPreference="{x:Null}" PlatformType="{x:Null}" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
- <TestAncestor>
- <TestId>xUnit::A1309041-8AAE-42D7-A886-94C9FFC6A28C::.NETCoreApp,Version=v3.1::AspectedRouting.Test.FunctionsTest.SpecializeToCommonType</TestId>
- </TestAncestor>
</SessionState>
\ No newline at end of file
diff --git a/AspectedRouting/IO/LuaSkeleton/LuaSkeleton.Expressions.cs b/AspectedRouting/IO/LuaSkeleton/LuaSkeleton.Expressions.cs
index e8a1056..3087c36 100644
--- a/AspectedRouting/IO/LuaSkeleton/LuaSkeleton.Expressions.cs
+++ b/AspectedRouting/IO/LuaSkeleton/LuaSkeleton.Expressions.cs
@@ -169,6 +169,7 @@ namespace AspectedRouting.IO.LuaSkeleton
return called.Name;
}
+ AddDependenciesFor(called);
AddFunction(called);
return $"{fc.CalledFunctionName.AsLuaIdentifier()}(parameters, tags, result)";
case Constant c:
diff --git a/AspectedRouting/IO/itinero1/LuaPrinter1.MainFunction.cs b/AspectedRouting/IO/itinero1/LuaPrinter1.MainFunction.cs
index cd41ac3..6438230 100644
--- a/AspectedRouting/IO/itinero1/LuaPrinter1.MainFunction.cs
+++ b/AspectedRouting/IO/itinero1/LuaPrinter1.MainFunction.cs
@@ -60,9 +60,8 @@ namespace AspectedRouting.IO.itinero1
var exprInLua = _skeleton.ToLua(expression.Optimize());
- var subs = new Curry(Typs.Tags, new Var(("a"))).UnificationTable(expression.Types.First());
- if (subs != null && subs.TryGetValue("$a", out var resultType) &&
- (resultType.Equals(Typs.Bool) || resultType.Equals(Typs.String)))
+ var resultTypes = expression.Types.Select(t => t.Uncurry().Last());
+ if (resultTypes.Any(t => t.Name.Equals(Typs.Bool.Name)))
{
_skeleton. AddDep("parse");
exprInLua = "parse(" + exprInLua + ")";
diff --git a/AspectedRouting/IO/lua/atleast.lua b/AspectedRouting/IO/lua/atleast.lua
index e69de29..f23f9af 100644
--- a/AspectedRouting/IO/lua/atleast.lua
+++ b/AspectedRouting/IO/lua/atleast.lua
@@ -0,0 +1,6 @@
+function atleast(minimumExpected, actual, thn, els)
+ if (minimumExpected <= actual) then
+ return thn;
+ end
+ return els
+end
\ No newline at end of file
diff --git a/AspectedRouting/Language/Analysis.cs b/AspectedRouting/Language/Analysis.cs
index 008442b..8cbb0bd 100644
--- a/AspectedRouting/Language/Analysis.cs
+++ b/AspectedRouting/Language/Analysis.cs
@@ -197,13 +197,8 @@ namespace AspectedRouting.Language
public static string TypeBreakdown(this IExpression e)
{
- var text = "";
- e.Visit(x =>
- {
- text += $"\n\n{x}\n : {string.Join("\n : ", x.Types)}";
- return true;
- });
- return text;
+
+ return e.ToString() + " : "+string.Join(" ; ", e.Types);
}
public static void SanityCheckProfile(this ProfileMetaData pmd, Context context)
diff --git a/AspectedRouting/Language/Expression/Apply.cs b/AspectedRouting/Language/Expression/Apply.cs
index a13a072..945f0a3 100644
--- a/AspectedRouting/Language/Expression/Apply.cs
+++ b/AspectedRouting/Language/Expression/Apply.cs
@@ -83,14 +83,15 @@ namespace AspectedRouting.Language.Expression
{
try
{
- _debugInfo = $"\n{f.Optimize().TypeBreakdown()}\n" +
- $"is applied on an argument with types:" +
- $"{string.Join(", ", argument.Optimize().Types)}";
+ _debugInfo = $"\n{f.Optimize().TypeBreakdown().Indent()}\n" +
+ $"is given the argument: " +
+ "(" + argument.Optimize().TypeBreakdown() + ")";
}
catch (Exception)
{
- _debugInfo = $"\n{f.TypeBreakdown()}\n" +
- $"{argument.TypeBreakdown()}";
+ _debugInfo =$"\n (NO OPT) {f.TypeBreakdown().Indent()}\n" +
+ $"is given the argument: " +
+ "(" + argument.TypeBreakdown() + ")";
}
}
}
@@ -197,6 +198,7 @@ namespace AspectedRouting.Language.Expression
if (Types.Count() > 1)
{
+ // Too much types to optimize
var optimized = new Dictionary();
foreach (var (resultType, (f, a)) in FunctionApplications)
{
@@ -209,6 +211,7 @@ namespace AspectedRouting.Language.Expression
}
{
+ // id a => a
var arg = new List();
if (
Deconstruct.UnApplyAny(
@@ -220,6 +223,37 @@ namespace AspectedRouting.Language.Expression
}
}
+
+ {
+ // ifdotted fcondition fthen felse arg => if (fcondition arg) (fthen arg) (felse arg)
+ var fcondition = new List();
+ var fthen = new List();
+ var felse = new List();
+ var arg = new List();
+
+ if (
+ Deconstruct.UnApplyAny(
+ Deconstruct.UnApply(
+ Deconstruct.UnApply(
+ Deconstruct.UnApply(
+ Deconstruct.IsFunc(Funcs.IfDotted),
+ Deconstruct.Assign(fcondition)),
+ Deconstruct.Assign(fthen)),
+ Deconstruct.Assign(felse)),
+ Deconstruct.Assign(arg)
+ ).Invoke(this))
+ {
+ var a = arg.First();
+ return
+ Funcs.If.Apply(
+ fcondition.First().Apply(a),
+ fthen.First().Apply(a),
+ felse.First().Apply(a)
+ );
+ }
+ }
+
+
{
var (f, a) = FunctionApplications.Values.First();
diff --git a/AspectedRouting/Language/Expression/ProfileMetaData.cs b/AspectedRouting/Language/Expression/ProfileMetaData.cs
index 20e80b5..7f4adfc 100644
--- a/AspectedRouting/Language/Expression/ProfileMetaData.cs
+++ b/AspectedRouting/Language/Expression/ProfileMetaData.cs
@@ -158,6 +158,11 @@ namespace AspectedRouting.Language.Expression
priority += aspectInfluence * aspectWeight;
}
+ if (priority <= 0)
+ {
+ canAccess = "no";
+ }
+
return new ProfileResult((string) canAccess, (string) oneway, speed, priority,
string.Join("\n ", weightExplanation));
}
diff --git a/AspectedRouting/Language/Functions/AtLeast.cs b/AspectedRouting/Language/Functions/AtLeast.cs
index 5e1c683..b02110f 100644
--- a/AspectedRouting/Language/Functions/AtLeast.cs
+++ b/AspectedRouting/Language/Functions/AtLeast.cs
@@ -45,18 +45,27 @@ namespace AspectedRouting.Language.Functions
public override object Evaluate(Context c, params IExpression[] arguments)
{
var minimum = arguments[0].Evaluate(c);
- var f = (IExpression) arguments[1].Evaluate(c);
var then = arguments[2].Evaluate(c);
var @else = arguments[3].Evaluate(c);
var x = arguments[4];
- var arg1 = f.Evaluate(c, x);
+ var arg1 = arguments[1].Evaluate(c, x);
if (minimum == null || arg1 == null)
{
return null;
}
+ if (minimum is IExpression e)
+ {
+ minimum = e.Evaluate(c);
+ }
+
+ if (arg1 is IExpression e1)
+ {
+ arg1 = e1.Evaluate(c);
+ }
+
if (minimum is int i0)
{
minimum = (double) i0;
diff --git a/AspectedRouting/Language/Functions/Constant.cs b/AspectedRouting/Language/Functions/Constant.cs
index a1e0b66..85239f2 100644
--- a/AspectedRouting/Language/Functions/Constant.cs
+++ b/AspectedRouting/Language/Functions/Constant.cs
@@ -18,6 +18,10 @@ namespace AspectedRouting.Language.Functions
if (o is IEnumerable enumerable)
{
o = enumerable.ToList();
+ if (enumerable.Any(x => x == null))
+ {
+ throw new NullReferenceException("Some subexpression is null");
+ }
}
_o = o;
@@ -29,6 +33,10 @@ namespace AspectedRouting.Language.Functions
if (o is IEnumerable enumerable)
{
o = enumerable.ToList();
+ if (enumerable.Any(x => x == null))
+ {
+ throw new NullReferenceException("Some subexpression is null");
+ }
}
_o = o;
@@ -39,6 +47,10 @@ namespace AspectedRouting.Language.Functions
var tps = exprs
.SpecializeToCommonTypes(out var specializedVersions)
.Select(t => new ListType(t));
+ if(specializedVersions.Any(x => x == null))
+ {
+ throw new Exception("Specializing to common types failed for "+string.Join("," ,exprs.Select(e => e.ToString())));
+ }
Types = tps.ToList();
_o = specializedVersions;
}
@@ -49,6 +61,10 @@ namespace AspectedRouting.Language.Functions
{
Types = exprs
.SpecializeToCommonTypes(out var specializedVersions).Select(t => new ListType(t)).ToList();
+ if (specializedVersions.Any(x => x == null))
+ {
+ throw new NullReferenceException("Some subexpression is null");
+ }
_o = specializedVersions.ToList();
}
catch (Exception e)
diff --git a/AspectedRouting/Language/Functions/Dot.cs b/AspectedRouting/Language/Functions/Dot.cs
index d966bda..9c79eba 100644
--- a/AspectedRouting/Language/Functions/Dot.cs
+++ b/AspectedRouting/Language/Functions/Dot.cs
@@ -8,9 +8,10 @@ namespace AspectedRouting.Language.Functions
{
public class Dot : Function
{
- public override string Description { get; } = "Higher order function: converts `f (g a)` into `(dot f g) a`. In other words, this fuses `f` and `g` in a new function, which allows the argument to be lifted out of the expression ";
+ public override string Description { get; } =
+ "Higher order function: converts `f (g a)` into `(dot f g) a`. In other words, this fuses `f` and `g` in a new function, which allows the argument to be lifted out of the expression ";
- public override List ArgNames { get; } = new List{"f","g","a"};
+ public override List ArgNames { get; } = new List {"f", "g", "a"};
public static readonly Var A = new Var("a");
public static readonly Var B = new Var("b");
public static readonly Var C = new Var("c");
@@ -33,6 +34,10 @@ namespace AspectedRouting.Language.Functions
public override object Evaluate(Context c, params IExpression[] arguments)
{
+ if (arguments.Count() <= 2)
+ {
+ }
+
var f0 = arguments[0];
var f1 = arguments[1];
var resultType = ((Curry) f1.Types.First()).ResultType;
diff --git a/AspectedRouting/Language/IExpression.cs b/AspectedRouting/Language/IExpression.cs
index 22dfe30..3828a64 100644
--- a/AspectedRouting/Language/IExpression.cs
+++ b/AspectedRouting/Language/IExpression.cs
@@ -38,8 +38,7 @@ namespace AspectedRouting.Language
///
///
///
- // IExpression OptimizeWithArgument(IExpression argument);
-
+ // IExpression OptimizeWithArgument(IExpression argument);
void Visit(Func f);
}
@@ -47,7 +46,7 @@ namespace AspectedRouting.Language
{
public static object Run(this IExpression e, Context c, Dictionary tags)
{
- return e.Apply(new []{new Constant(tags)}).Evaluate(c);
+ return e.Apply(new[] {new Constant(tags)}).Evaluate(c);
}
public static IExpression Specialize(this IExpression e, Type t)
@@ -101,8 +100,11 @@ namespace AspectedRouting.Language
out IEnumerable specializedTypes, out IEnumerable specializedExpressions)
{
specializedTypes = null;
- var expressions = exprs.ToList();
- foreach (var f in expressions)
+ var exprsForTypes = exprs.SortWidestToSmallest();
+ exprsForTypes.Reverse();
+
+
+ foreach (var f in exprsForTypes)
{
if (specializedTypes == null)
{
@@ -110,9 +112,7 @@ namespace AspectedRouting.Language
continue;
}
- // TODO FIXME
- // EITHER THE TYPES HAVE TO BE FROM SPECIFIC TO NON-SPECIFIC ORDER OR VICE VERSA
- var specialized = f.Types.RenameVars(specializedTypes).SpecializeTo(specializedTypes);
+ var specialized = f.Types.RenameVars(specializedTypes).SpecializeTo(specializedTypes, false);
// ReSharper disable once JoinNullCheckWithUsage
if (specialized == null)
{
@@ -126,7 +126,15 @@ namespace AspectedRouting.Language
}
var tps = specializedTypes;
- return specializedExpressions = expressions.Select(expr => expr.Specialize(tps));
+
+ var optExprs = new List();
+ foreach (var expr in exprs)
+ {
+ var exprOpt = expr.Specialize(tps);
+ optExprs.Add(exprOpt);
+ }
+
+ return specializedExpressions = optExprs;
}
}
}
\ No newline at end of file
diff --git a/AspectedRouting/Language/Typ/Typs.cs b/AspectedRouting/Language/Typ/Typs.cs
index 66572b0..941d1f3 100644
--- a/AspectedRouting/Language/Typ/Typs.cs
+++ b/AspectedRouting/Language/Typ/Typs.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.Linq;
@@ -23,7 +24,7 @@ namespace AspectedRouting.Language.Typ
}
- public static HashSet SpecializeTo(this IEnumerable types0, IEnumerable allowedTypes)
+ public static HashSet SpecializeTo(this IEnumerable types0, IEnumerable allowedTypes, bool reverseSuperSet = true)
{
var results = new HashSet();
@@ -32,7 +33,7 @@ namespace AspectedRouting.Language.Typ
{
foreach (var allowed in allowedTypes)
{
- var unified = t0.Unify(allowed, true);
+ var unified = t0.Unify(allowed, reverseSuperSet);
if (unified != null)
{
results.Add(unified);
@@ -70,9 +71,10 @@ namespace AspectedRouting.Language.Typ
{
return SelectSmallestUnion(t1, subbed);
}
+
return SelectSmallestUnion(subbed, t1);
}
-
+
private static Type SelectSmallestUnion(this Type wider, Type smaller, bool reverse = false)
{
switch (wider)
@@ -99,6 +101,81 @@ namespace AspectedRouting.Language.Typ
}
}
+ public static List SortWidestToSmallest(this IEnumerable expressions)
+ {
+ var all = expressions.ToHashSet();
+ var sorted = new List();
+ while (all.Any())
+ {
+ var widest = SelectWidestType(all);
+ if (widest == null)
+ {
+ throw new ArgumentException("Can not sort widest to smallest");
+ }
+ all.Remove(widest);
+ sorted.Add(widest);
+ }
+
+ return sorted;
+ }
+
+ public static IExpression SelectSmallestType(IEnumerable expressions)
+ {
+ IExpression smallest = null;
+ foreach (var current in expressions)
+ {
+ if (smallest == null)
+ {
+ smallest = current;
+ continue;
+ }
+ if (smallest.Types.AllAreSuperset(current.Types))
+ {
+ smallest = current;
+ }
+ }
+
+
+
+ return smallest;
+ }
+
+ public static IExpression SelectWidestType(IEnumerable expressions)
+ {
+ IExpression widest = null;
+ foreach (var current in expressions)
+ {
+ if (widest == null)
+ {
+ widest = current;
+ continue;
+ }
+
+ if (current.Types.AllAreSuperset(widest.Types))
+ {
+ widest = current;
+ }
+ }
+
+ return widest;
+ }
+
+ public static bool AllAreSuperset(this IEnumerable shouldBeSuper, IEnumerable shouldBeSmaller)
+ {
+ foreach (var super in shouldBeSuper)
+ {
+ foreach (var smaller in shouldBeSmaller)
+ {
+ if (!super.IsSuperSet(smaller))
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
///
/// Tries to unify t0 with all t1's.
/// Every match is returned
@@ -136,7 +213,6 @@ namespace AspectedRouting.Language.Typ
}
-
public static Type Substitute(this Type t0, Dictionary substitutions)
{
switch (t0)
@@ -161,7 +237,8 @@ namespace AspectedRouting.Language.Typ
///
///
///
- public static Dictionary UnificationTable(this Type t0, Type t1, bool reverseSupersetRelation = false)
+ public static Dictionary UnificationTable(this Type t0, Type t1,
+ bool reverseSupersetRelation = false)
{
var substitutionsOn0 = new Dictionary();
@@ -235,7 +312,7 @@ namespace AspectedRouting.Language.Typ
AddSubs(v.Name, t0);
break;
}
-
+
if (!reverseSupersetRelation && !t0.IsSuperSet(t1))
{
return null;
@@ -281,6 +358,11 @@ namespace AspectedRouting.Language.Typ
public static bool IsSuperSet(this Type t0, Type t1)
{
+ if (t0 is Var || t1 is Var)
+ {
+ return true;
+ }
+
switch (t0)
{
case StringType _ when t1 is BoolType _:
diff --git a/AspectedRouting/Program.cs b/AspectedRouting/Program.cs
index 9ac6756..7d6f431 100644
--- a/AspectedRouting/Program.cs
+++ b/AspectedRouting/Program.cs
@@ -21,7 +21,7 @@ namespace AspectedRouting
foreach (var file in jsonFileNames)
{
var fi = new FileInfo(file);
-
+
var aspect = JsonParser.AspectFromJson(context, File.ReadAllText(file), fi.Name);
if (aspect == null) continue;
@@ -63,11 +63,6 @@ namespace AspectedRouting
var result = new List<(ProfileMetaData profile, List profileTests)>();
foreach (var jsonFile in jsonFiles)
{
- if (!jsonFile.Contains("bicycle"))
- {
- continue;
- }
-
try
{
var profile =
@@ -227,6 +222,7 @@ namespace AspectedRouting
// With everything parsed and typechecked, time for tests
+ var testsOk = true;
foreach (var (aspect, t) in aspects)
{
if (t == null)
@@ -235,18 +231,27 @@ namespace AspectedRouting
}
else
{
- t.Run();
+ testsOk &= t.Run();
}
}
+
foreach (var (profile, profileTests) in profiles)
{
foreach (var test in profileTests)
{
- test.Run(context);
+ testsOk &= test.Run(context);
}
+ }
+ if (!testsOk)
+ {
+ Console.WriteLine("Some tests failed, quitting now without generating output");
+ return;
+ }
+ foreach (var (profile, profileTests) in profiles)
+ {
PrintUsedTags(profile, context);
var aspectTests = aspects.Select(a => a.tests).ToList();
diff --git a/AspectedRouting/Tests/FunctionTestSuite.cs b/AspectedRouting/Tests/FunctionTestSuite.cs
index 942346d..7c21412 100644
--- a/AspectedRouting/Tests/FunctionTestSuite.cs
+++ b/AspectedRouting/Tests/FunctionTestSuite.cs
@@ -61,7 +61,7 @@ namespace AspectedRouting.Tests
- public void Run()
+ public bool Run()
{
var failed = false;
var testCase = 0;
@@ -88,12 +88,9 @@ namespace AspectedRouting.Tests
}
}
- if (failed)
- {
- throw new ArgumentException("Some test failed");
- }
- Console.WriteLine($"[{FunctionToApply.Name}] {testCase} tests successful");
+ Console.WriteLine($"[{FunctionToApply.Name}] {testCase} tests " + (failed ? "failed" : "successful"));
+ return !failed;
}
}
}
\ No newline at end of file
diff --git a/AspectedRouting/Tests/ProfileTestSuite.cs b/AspectedRouting/Tests/ProfileTestSuite.cs
index 9da3385..325034a 100644
--- a/AspectedRouting/Tests/ProfileTestSuite.cs
+++ b/AspectedRouting/Tests/ProfileTestSuite.cs
@@ -77,8 +77,7 @@ namespace AspectedRouting.Tests
weight = double.Parse(testData[3]);
}
-
-
+
var expected = new ProfileResult(
testData[0],
testData[1],
@@ -88,9 +87,10 @@ namespace AspectedRouting.Tests
if (expected.Priority == 0 && expected.Access != "no")
{
- throw new ArgumentException("A priority of zero is interpreted as 'no access' - don't use it");
+ throw new ArgumentException(
+ "A priority of zero is interpreted as 'no access' - don't use it");
}
-
+
var vals = testData.GetRange(4, testData.Count - 4);
var tags = new Dictionary();
for (int i = 0; i < keys.Count; i++)
@@ -192,11 +192,8 @@ namespace AspectedRouting.Tests
return success;
}
- public void Run(Context c)
-
+ public bool Run(Context c)
{
-
-
var allOk = true;
var i = 1;
foreach (var (expected, tags) in Tests)
@@ -213,14 +210,9 @@ namespace AspectedRouting.Tests
i++;
}
- if (!allOk)
- {
- throw new ArgumentException("Some tests failed for " + BehaviourName);
- }
- else
- {
- Console.WriteLine($"[{Profile.Name}] {Tests.Count()} tests successful for behaviour {BehaviourName}");
- }
+ Console.WriteLine($"[{Profile.Name}] {Tests.Count()} tests " + (allOk ? "successfull" : "executed, some failed") +
+ $" for behaviour {BehaviourName}");
+ return allOk;
}
}
}
\ No newline at end of file
diff --git a/Profiles/bicycle/bicycle.json b/Profiles/bicycle/bicycle.json
index 117e143..7f24d5d 100644
--- a/Profiles/bicycle/bicycle.json
+++ b/Profiles/bicycle/bicycle.json
@@ -39,7 +39,17 @@
"#timeNeeded": "$speed",
"#distance": "$distance",
"#trespassingPenalty": "$clean_permission_score",
- "#leastSafetyPenalty": 0
+ "#leastSafetyPenalty": {
+ "$multiply": [
+ "$speed",
+ {
+ "$atleast": "#leastSafetyRequired",
+ "f": "$bicycle.safety",
+ "then": 0,
+ "else": -1
+ }
+ ]
+ }
},
"defaults": {
"#defaultSpeed": 15,
@@ -56,16 +66,18 @@
"#trespassingPenalty": 15,
"#": "This is not a priority weight, but rather a kind of access restriction. If 'leastafety' is not met, a huge penalty is applied, namely #leastSafetyPenalty. Note: 0.1 is the safety level of a primary without cycle highway",
"#leastSafetyRequired": 0.11,
- "#leastSafetyPenalty": 2
+ "#leastSafetyPenalty": 0
},
"behaviours": {
"fastest": {
"description": "The fastest route to your destination",
- "#timeNeeded": 1
+ "#timeNeeded": 1,
+ "#leastSafetyPenalty": 2
},
"shortest": {
"description": "The shortest route, independent of of speed",
- "#distance": 1
+ "#distance": 1,
+ "#leastSafetyPenalty": 2
},
"safety": {
"description": "A defensive route shying away from big roads with lots of cars",
@@ -73,7 +85,8 @@
},
"comfort": {
"description": "A comfortable route preferring well-paved roads, smaller roads and a bit of scenery at the cost of speed",
- "#comfort": 1
+ "#comfort": 1,
+ "#leastSafetyPenalty": 2
},
"comfort_safety": {
"description": "A route which aims to be both safe and comfortable at the cost of speed",
@@ -84,7 +97,8 @@
"description": "A profile for a bike with an electrical motor where the engine doesn't go faster then 25km/h (thus NOT the speed-pedelec). This is a variation of the normal fastest, but with a faster default speed. As the maxspeed is 30, it'll resemble shortest a bit more on 'normal' streets and will penalize slower roads more",
"#defaultSpeed": 23,
"#maxspeed": 30,
- "#timeNeeded": 1
+ "#timeNeeded": 1,
+ "#leastSafetyPenalty": 2
},
"networks": {
"description": "A recreative route following any existing cycling network. Might make a few detours",
@@ -111,7 +125,8 @@
"cycle_highway": {
"description": "A route preferring the 'cycle-highways'. On non-cycleways, fastest is used (with a very low factor) in order to make sure the behaviour there is defined ",
"#cycleHighwayNetworkScore": 20,
- "#timeNeeded": 0.1
+ "#timeNeeded": 0.1,
+ "#leastSafetyPenalty": 2
},
"node_network": {
"description": "A route following the recreational node network. Might make detours",
diff --git a/Profiles/bicycle/speedPedelec.json b/Profiles/bicycle/speedPedelec.json
index 1a3b96c..71a441b 100644
--- a/Profiles/bicycle/speedPedelec.json
+++ b/Profiles/bicycle/speedPedelec.json
@@ -27,9 +27,14 @@
"speed":{
"$min":
[
- {"$multiply":["#defaultSpeed", "$bicycle.speed_factor"]},
- "$legal_maxspeed_be",
- "#maxspeed"
+ "#maxspeed",
+ "$legal_maxspeed_be",
+ {
+ "$multiply": [
+ "#defaultSpeed",
+ "$bicycle.speed_factor"
+ ]
+ }
]
},
"access":"$speedPedelec.access_be",
diff --git a/Profiles/bicycle/tests/bicycle.fastest.behaviour_test.csv b/Profiles/bicycle/tests/bicycle.fastest.behaviour_test.csv
index e7bdb6a..a96d215 100644
--- a/Profiles/bicycle/tests/bicycle.fastest.behaviour_test.csv
+++ b/Profiles/bicycle/tests/bicycle.fastest.behaviour_test.csv
@@ -1,8 +1,8 @@
access,oneway,speed,priority,highway,bicycle,surface,cycleway:left,oneway,oneway:bicycle,access,maxspeed,junction
no,both,0,0,,,,,,,,,
designated,both,15,15,cycleway,,,,,,,,
-yes,both,15,15,primary,,,,,,,,
-yes,both,15,15,primary,yes,,,,,,,
+no,both,15,-15,primary,,,,,,,,
+no,both,15,-15,primary,yes,,,,,,,
yes,both,15,15,residential,,,,,,,,
yes,both,13.5,13.5,residential,yes,sett,,,,,,
dismount,both,2.25,2.25,pedestrian,,,,,,,,
diff --git a/Profiles/bicycle/tests/bicycle.shortest.behaviour_test.csv b/Profiles/bicycle/tests/bicycle.shortest.behaviour_test.csv
index c868087..fa37c20 100644
--- a/Profiles/bicycle/tests/bicycle.shortest.behaviour_test.csv
+++ b/Profiles/bicycle/tests/bicycle.shortest.behaviour_test.csv
@@ -2,4 +2,4 @@ access,oneway,speed,priority,highway,surface
no,both,0,0,,
designated,both,15,1,cycleway,
yes,both,5.25,1,path,ground
-yes,both,15,1,primary,
+no,both,15,-29,primary,