Typesystem and profile updates
This commit is contained in:
parent
537fb2c613
commit
173756818e
17 changed files with 189 additions and 69 deletions
|
@ -322,9 +322,19 @@ namespace AspectedRouting.Test
|
||||||
new Curry(Typs.String, Typs.String));
|
new Curry(Typs.String, Typs.String));
|
||||||
|
|
||||||
var f1 = f.Specialize(strstrstr);
|
var f1 = f.Specialize(strstrstr);
|
||||||
|
|
||||||
Assert.Equal(new[] {strstrb, strstrstr}, f1.Types);
|
|
||||||
|
|
||||||
|
Assert.Equal(new[] {strstrb, strstrstr}, f1.Types);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SpecializeToCommonType()
|
||||||
|
{
|
||||||
|
var p0 = Funcs.Parse;
|
||||||
|
var p1 = Funcs.Const.Apply(new Constant(1.0));
|
||||||
|
|
||||||
|
var exprs = new[] {p0, p1};
|
||||||
|
var newTypes = exprs.SpecializeToCommonTypes(out var specializedExpressions);
|
||||||
|
Assert.Single(newTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,13 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using AspectedRouting.Language;
|
|
||||||
using AspectedRouting.Language.Functions;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace AspectedRouting.Test
|
|
||||||
{
|
|
||||||
public class TestAnalysis
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
9
AspectedRouting.sln.DotSettings.user
Normal file
9
AspectedRouting.sln.DotSettings.user
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=af5d2251_002D713d_002D473f_002D9157_002D89c9d06216e5/@EntryIndexedValue"><SessionState ContinuousTestingIsOn="False" ContinuousTestingMode="0" FrameworkVersion="{x:Null}" IsLocked="False" Name="All tests from &lt;AspectedRouting.Test&gt;" 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="&lt;AspectedRouting.Test&gt;" />
|
||||||
|
</SessionState></s:String>
|
||||||
|
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=bad1d05d_002Df895_002D4e7d_002Da6e2_002Dede32f077b26/@EntryIndexedValue"><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></s:String></wpf:ResourceDictionary>
|
|
@ -27,7 +27,7 @@ namespace AspectedRouting.IO.itinero1
|
||||||
"end"
|
"end"
|
||||||
};
|
};
|
||||||
|
|
||||||
return string.Join("\n",impl);
|
return string.Join("\n", impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -56,7 +56,11 @@ namespace AspectedRouting.IO.itinero1
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl += $" parameters.{paramName.TrimStart('#').AsLuaIdentifier()} = {_skeleton.ToLua(value)}\n";
|
var paramNameTrimmed = paramName.TrimStart('#').AsLuaIdentifier();
|
||||||
|
if (!string.IsNullOrEmpty(paramNameTrimmed))
|
||||||
|
{
|
||||||
|
impl += $" parameters.{paramNameTrimmed} = {_skeleton.ToLua(value)}\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return impl;
|
return impl;
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
function as_number(a)
|
function atleast(a, b)
|
||||||
|
if(a <= b) then
|
||||||
|
return "yes"
|
||||||
|
end
|
||||||
|
return "no"
|
||||||
|
|
||||||
end
|
end
|
0
AspectedRouting/IO/lua/atleast.lua
Normal file
0
AspectedRouting/IO/lua/atleast.lua
Normal file
|
@ -30,7 +30,13 @@ function unit_test_profile(profile_function, profile_name, index, expected, tags
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local actualOneway = result.direction;
|
local actualOneway = result.direction
|
||||||
|
|
||||||
|
if(actualOneway == nil) then
|
||||||
|
print("Fail: result.direction is nil")
|
||||||
|
profile_failed = true;
|
||||||
|
end
|
||||||
|
|
||||||
if (result.direction == 0) then
|
if (result.direction == 0) then
|
||||||
actualOneway = "both"
|
actualOneway = "both"
|
||||||
elseif (result.direction == 1) then
|
elseif (result.direction == 1) then
|
||||||
|
@ -40,7 +46,7 @@ function unit_test_profile(profile_function, profile_name, index, expected, tags
|
||||||
end
|
end
|
||||||
|
|
||||||
if (expected.oneway ~= actualOneway) then
|
if (expected.oneway ~= actualOneway) then
|
||||||
print("Test " .. tostring(index) .. " failed for " .. profile_name .. ".oneway: expected " .. expected.direction .. " but got " .. actualOneway)
|
print("Test " .. tostring(index) .. " failed for " .. profile_name .. ".oneway: expected " .. expected.oneway .. " but got " .. actualOneway)
|
||||||
failed_profile_tests = true
|
failed_profile_tests = true
|
||||||
profile_failed = true
|
profile_failed = true
|
||||||
end
|
end
|
||||||
|
|
|
@ -237,7 +237,7 @@ namespace AspectedRouting.Language
|
||||||
var unused = defaultParameters.Except(usedParameters);
|
var unused = defaultParameters.Except(usedParameters);
|
||||||
if (unused.Any())
|
if (unused.Any())
|
||||||
{
|
{
|
||||||
throw new ArgumentException("A default value is set for parameter, but it is unused: " +
|
Console.WriteLine("[WARNING] A default value is set for parameter, but it is unused: " +
|
||||||
string.Join(", ", unused));
|
string.Join(", ", unused));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using AspectedRouting.Language.Expression;
|
using AspectedRouting.Language.Expression;
|
||||||
|
@ -32,6 +33,7 @@ namespace AspectedRouting.Language
|
||||||
public static readonly Function Multiply = new Multiply();
|
public static readonly Function Multiply = new Multiply();
|
||||||
|
|
||||||
|
|
||||||
|
public static readonly Function AtLeast = new AtLeast();
|
||||||
public static readonly Function FirstOf = new FirstMatchOf();
|
public static readonly Function FirstOf = new FirstMatchOf();
|
||||||
public static readonly Function MustMatch = new MustMatch();
|
public static readonly Function MustMatch = new MustMatch();
|
||||||
|
|
||||||
|
@ -79,13 +81,35 @@ namespace AspectedRouting.Language
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
e = e.SpecializeToSmallestType();
|
if (e.Types.Count() == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Expression has no valid types:\n" + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
var eSmallest = e.SpecializeToSmallestType();
|
||||||
|
if (eSmallest == null || eSmallest.Types.Count() == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Could not specialize " + e);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO FIX THIS so that it works
|
// TODO FIX THIS so that it works
|
||||||
// An argument 'optimizes' it's types from 'string -> bool' to 'string -> string'
|
// An argument 'optimizes' it's types from 'string -> bool' to 'string -> string'
|
||||||
e = e.Optimize();
|
try
|
||||||
//
|
{
|
||||||
e.SanityCheck();
|
var eOpt = eSmallest.Optimize(); if (eOpt == null || eOpt.Types.Count() == 0)
|
||||||
return e;
|
{
|
||||||
|
throw new Exception("Could not optimize " + eSmallest);
|
||||||
|
}
|
||||||
|
eOpt.SanityCheck();
|
||||||
|
return eOpt;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Console.WriteLine("Optimalization failed for "+eSmallest);
|
||||||
|
return eSmallest;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IExpression SpecializeToSmallestType(this IExpression e)
|
public static IExpression SpecializeToSmallestType(this IExpression e)
|
||||||
|
|
84
AspectedRouting/Language/Functions/AtLeast.cs
Normal file
84
AspectedRouting/Language/Functions/AtLeast.cs
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using AspectedRouting.Language.Expression;
|
||||||
|
using AspectedRouting.Language.Typ;
|
||||||
|
using Type = AspectedRouting.Language.Typ.Type;
|
||||||
|
|
||||||
|
namespace AspectedRouting.Language.Functions
|
||||||
|
{
|
||||||
|
public class AtLeast : Function
|
||||||
|
{
|
||||||
|
public override string Description { get; } =
|
||||||
|
"Returns 'yes' if the second argument is bigger then the first argument. (Works great in combination with $dot)";
|
||||||
|
|
||||||
|
public override List<string> ArgNames { get; } = new List<string> {"minimum", "f", "then","else"};
|
||||||
|
|
||||||
|
private static Type a = new Var("a");
|
||||||
|
private static Type b = new Var("b");
|
||||||
|
|
||||||
|
public AtLeast() : base("atleast", true,
|
||||||
|
new[]
|
||||||
|
{
|
||||||
|
Curry.ConstructFrom(a,
|
||||||
|
Typs.Double,
|
||||||
|
new Curry(b,Typs.Double),
|
||||||
|
a, a, b),
|
||||||
|
})
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private AtLeast(IEnumerable<Type> types) : base("atleast", types)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IExpression Specialize(IEnumerable<Type> allowedTypes)
|
||||||
|
{
|
||||||
|
var unified = Types.SpecializeTo(allowedTypes);
|
||||||
|
if (unified == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AtLeast(unified);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (minimum == null || arg1 == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minimum is int i0)
|
||||||
|
{
|
||||||
|
minimum = (double) i0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg1 is int i1)
|
||||||
|
{
|
||||||
|
arg1 = (double) i1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minimum is double d0 && arg1 is double d1)
|
||||||
|
{
|
||||||
|
if (d0 <= d1)
|
||||||
|
{
|
||||||
|
return then;
|
||||||
|
}
|
||||||
|
|
||||||
|
return @else;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidCastException("One of the arguments is not a number: "+minimum+", "+arg1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,8 +39,8 @@
|
||||||
"pedestrian": "dismount",
|
"pedestrian": "dismount",
|
||||||
"corridor": "dismount",
|
"corridor": "dismount",
|
||||||
"path": "yes",
|
"path": "yes",
|
||||||
"primary": "no",
|
"primary": "yes",
|
||||||
"primary_link": "no",
|
"primary_link": "yes",
|
||||||
"secondary": "yes",
|
"secondary": "yes",
|
||||||
"secondary_link": "yes",
|
"secondary_link": "yes",
|
||||||
"tertiary": "yes",
|
"tertiary": "yes",
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"#": "access=no and access 'destination' implies this access for cars too and is a bonus!",
|
"#": "access=no and access 'destination' implies this access for cars too and is a bonus!",
|
||||||
"no": 1.5,
|
"no": 1.5,
|
||||||
"destination": 1.4,
|
"destination": 1.4,
|
||||||
"dismount": 0.01,
|
"dismount": 0.2,
|
||||||
"designated": 1.5
|
"designated": 1.5
|
||||||
},
|
},
|
||||||
"motor_vehicle": {
|
"motor_vehicle": {
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
},
|
},
|
||||||
"highway": {
|
"highway": {
|
||||||
"cycleway": 1.0,
|
"cycleway": 1.0,
|
||||||
"primary": 0.3,
|
"primary": 0.1,
|
||||||
"secondary": 0.4,
|
"secondary": 0.4,
|
||||||
"tertiary": 0.5,
|
"tertiary": 0.5,
|
||||||
"unclassified": 0.8,
|
"unclassified": 0.8,
|
||||||
|
@ -44,31 +44,28 @@
|
||||||
"path": 0.9
|
"path": 0.9
|
||||||
},
|
},
|
||||||
"cycleway": {
|
"cycleway": {
|
||||||
"yes": 0.95,
|
"#": "A distinct cycleway _always_ makes the road safer for cyclists, even if it is but a small lane. The default assumption is 'no', no cycleway, in which case the safety feeling is not improved",
|
||||||
"#": "TODO: the implied value for quite a bit of roads (residential, unclassified) is 'no', so this is a bit weird",
|
"yes": 1.15,
|
||||||
"no": 0.5,
|
"lane": 1.15,
|
||||||
"lane": 1,
|
"shared": 1.03,
|
||||||
"shared": 0.8,
|
"shared_lane": 1.03,
|
||||||
"shared_lane": 0.8,
|
"share_busway": 1.05,
|
||||||
"share_busway": 0.9,
|
|
||||||
"track": 1.5
|
"track": 1.5
|
||||||
},
|
},
|
||||||
"cycleway:left": {
|
"cycleway:left": {
|
||||||
"yes": 0.95,
|
"yes": 1.15,
|
||||||
"no": 0.5,
|
"lane": 1.15,
|
||||||
"lane": 1,
|
"shared": 1.03,
|
||||||
"shared": 0.8,
|
"shared_lane": 1.03,
|
||||||
"shared_lane": 0.8,
|
"share_busway": 1.05,
|
||||||
"share_busway": 0.9,
|
|
||||||
"track": 1.5
|
"track": 1.5
|
||||||
},
|
},
|
||||||
"cycleway:right": {
|
"cycleway:right": {
|
||||||
"yes": 0.95,
|
"yes": 1.15,
|
||||||
"no": 0.5,
|
"lane": 1.15,
|
||||||
"lane": 1,
|
"shared": 1.03,
|
||||||
"shared": 0.8,
|
"shared_lane": 1.03,
|
||||||
"shared_lane": 0.8,
|
"share_busway": 1.05,
|
||||||
"share_busway": 0.9,
|
|
||||||
"track": 1.5
|
"track": 1.5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,15 +15,7 @@
|
||||||
"status",
|
"status",
|
||||||
"network"
|
"network"
|
||||||
],
|
],
|
||||||
"access": {
|
"access": "$bicycle.legal_access",
|
||||||
"$ifDotted": {
|
|
||||||
"$dot": {"$notEq": "no"},
|
|
||||||
"f": "$bicycle.legal_access"
|
|
||||||
},
|
|
||||||
|
|
||||||
"then": "$bicycle.legal_access",
|
|
||||||
"else": "$bicycle.network_is_bicycle_network"
|
|
||||||
},
|
|
||||||
"oneway": "$bicycle.oneway",
|
"oneway": "$bicycle.oneway",
|
||||||
"speed": {
|
"speed": {
|
||||||
"$min": [
|
"$min": [
|
||||||
|
@ -46,7 +38,8 @@
|
||||||
"#bicycleNetworkScore": "$bicycle.network_is_bicycle_network",
|
"#bicycleNetworkScore": "$bicycle.network_is_bicycle_network",
|
||||||
"#timeNeeded": "$speed",
|
"#timeNeeded": "$speed",
|
||||||
"#distance": "$distance",
|
"#distance": "$distance",
|
||||||
"#trespassingPenalty":"$clean_permission_score"
|
"#trespassingPenalty": "$clean_permission_score",
|
||||||
|
"#leastSafetyPenalty": 0
|
||||||
},
|
},
|
||||||
"defaults": {
|
"defaults": {
|
||||||
"#defaultSpeed": 15,
|
"#defaultSpeed": 15,
|
||||||
|
@ -60,7 +53,10 @@
|
||||||
"#cycleHighwayNetworkScore": 0,
|
"#cycleHighwayNetworkScore": 0,
|
||||||
"#nodeNetworkScore": 0,
|
"#nodeNetworkScore": 0,
|
||||||
"#bicycleNetworkScore": 0,
|
"#bicycleNetworkScore": 0,
|
||||||
"#trespassingPenalty": 15
|
"#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
|
||||||
},
|
},
|
||||||
"behaviours": {
|
"behaviours": {
|
||||||
"fastest": {
|
"fastest": {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
access,oneway,speed,priority,highway,bicycle,surface,cycleway:left,oneway,oneway:bicycle,access,maxspeed,junction
|
access,oneway,speed,priority,highway,bicycle,surface,cycleway:left,oneway,oneway:bicycle,access,maxspeed,junction
|
||||||
no,both,0,0,,,,,,,,,
|
no,both,0,0,,,,,,,,,
|
||||||
designated,both,15,15,cycleway,,,,,,,,
|
designated,both,15,15,cycleway,,,,,,,,
|
||||||
no,both,0,0,primary,,,,,,,,
|
yes,both,15,15,primary,,,,,,,,
|
||||||
yes,both,15,15,primary,yes,,,,,,,
|
yes,both,15,15,primary,yes,,,,,,,
|
||||||
yes,both,15,15,residential,,,,,,,,
|
yes,both,15,15,residential,,,,,,,,
|
||||||
yes,both,13.5,13.5,residential,yes,sett,,,,,,
|
yes,both,13.5,13.5,residential,yes,sett,,,,,,
|
||||||
|
|
|
|
@ -12,7 +12,7 @@ designated,residential,designated,,,,
|
||||||
designated,motorway,designated,,,,
|
designated,motorway,designated,,,,
|
||||||
no,residential,use_sidepath,,,,
|
no,residential,use_sidepath,,,,
|
||||||
yes,residential,,no,yes,,
|
yes,residential,,no,yes,,
|
||||||
no,primary,,,,,
|
yes,primary,,,,,
|
||||||
yes,primary,,,,yes,
|
yes,primary,,,,yes,
|
||||||
yes,primary,,,,,yes
|
yes,primary,,,,,yes
|
||||||
yes,secondary,,,,track,
|
yes,secondary,,,,track,
|
||||||
|
|
|
|
@ -1,8 +1,8 @@
|
||||||
expected,highway,cycleway,cyclestreet,foot,bicycle,cycleway:right,access
|
expected,highway,cycleway,cyclestreet,foot,bicycle,cycleway:right,access
|
||||||
0.15,primary,no,,,,,
|
0.1,primary,no,,,,,
|
||||||
0.285,primary,yes,,,,,
|
0.115,primary,yes,,,,,
|
||||||
0.45,primary,track,,,,,
|
0.15,primary,track,,,,,
|
||||||
0.4,secondary,lane,,,,,
|
0.46,secondary,lane,,,,,
|
||||||
0.9,residential,,,,,,
|
0.9,residential,,,,,,
|
||||||
1.5,cycleway,,,,,,designated
|
1.5,cycleway,,,,,,designated
|
||||||
1.35,residential,,yes,,,,
|
1.35,residential,,yes,,,,
|
||||||
|
@ -10,4 +10,4 @@ expected,highway,cycleway,cyclestreet,foot,bicycle,cycleway:right,access
|
||||||
0.9025,footway,,,designated,,,
|
0.9025,footway,,,designated,,,
|
||||||
1.2825,path,,,designated,designated,,
|
1.2825,path,,,designated,designated,,
|
||||||
1.35,path,,,,designated,,
|
1.35,path,,,,designated,,
|
||||||
0.4,secondary,,,,,lane,
|
0.46,secondary,,,,,lane,
|
||||||
|
|
|
|
@ -2,4 +2,4 @@ access,oneway,speed,priority,highway,surface
|
||||||
no,both,0,0,,
|
no,both,0,0,,
|
||||||
designated,both,15,1,cycleway,
|
designated,both,15,1,cycleway,
|
||||||
yes,both,5.25,1,path,ground
|
yes,both,5.25,1,path,ground
|
||||||
no,both,15,0,primary,
|
yes,both,15,1,primary,
|
||||||
|
|
|
Loading…
Add table
Add a link
Reference in a new issue