Newer
Older
using System.Linq;
Marco Zimmer
committed
using System.Collections.Generic;
using UnityEngine;
MaZiFAU
committed
using static CanonBallProblemCalculator2D;
MaZiFAU
committed
using MoreLinq;
Marco Zimmer
committed
public class GenerateDemoFiles
{
public static void GenerateAll()
{
if (UnityEngine.Object.FindObjectOfType<GadgetBehaviour>(true) == null)
Debug.LogError("Cannot GenerateDemoFiles without populated GadgetManager");
return;
}
Marco Zimmer
committed
Debug.LogWarning("Generating and Overwriting Stage Files");
Action[] DemoGeneration = new Action[]{
GenerateTreeStage,
GenerateRiverStage,
MaZiFAU
committed
GenerateCanonBallStage2D,
GenerateCanonBallStage3D,
};
foreach (Action action in DemoGeneration)
try
{
action();
Debug.Log("Successfully executed " + action.Method.Name);
}
catch (Exception ex)
{
Debug.LogError("Exception while executing " + action.Method.Name);
Debug.LogException(ex);
}
StageStatic.StageOfficial = null;
StageStatic.StageLocal = null;
Marco Zimmer
committed
}
Marco Zimmer
committed
{
// Params
float minimalSolutionHight = 6;
// Generate Stage
(
number: 1,
category: "Demo Category",
name: "TechDemo A",
scene: "RiverWorld",
description: "Tree Stage",
local: false
);
Marco Zimmer
committed
// needed to generate facts
Marco Zimmer
committed
StageStatic.StageOfficial = new Dictionary<string, Stage>
Marco Zimmer
committed
{
{ demo.name, demo },
};
Marco Zimmer
committed
StageStatic.SetStage(demo.name, false);
Marco Zimmer
committed
// Populate Solution
PointFact
Marco Zimmer
committed
buttom = new PointFact(Vector3.zero, Vector3.up, StageStatic.stage.solution),
top = new PointFact(Vector3.zero + Vector3.up * minimalSolutionHight, Vector3.up, StageStatic.stage.solution);
Marco Zimmer
committed
StageStatic.stage.solution.Add(buttom, out _, false, null, null);
StageStatic.stage.solution.Add(top, out _, true, null, null);
Marco Zimmer
committed
Marco Zimmer
committed
LineFact target = new LineFact(buttom.Id, top.Id, StageStatic.stage.solution);
var target_Id = StageStatic.stage.solution.Add(target, out _, true, null, null);
Marco Zimmer
committed
// Set Solution
Marco Zimmer
committed
StageStatic.stage.solution.ValidationSet =
new List<SolutionRecorder.SubSolution>
{ new SolutionRecorder.SubSolution(new HashSet<string> { target_Id }, null, null, new LineFactHightDirectionComparer()) };
Marco Zimmer
committed
StageStatic.stage.AllowedGadgets = null;
Marco Zimmer
committed
// Save
Marco Zimmer
committed
StageStatic.SetMode(StageStatic.Mode.Create);
StageStatic.stage.store(false, true);
Marco Zimmer
committed
}
{
// Params
float minimalSolutionHight = 6;
// Generate Stage
Stage demo = new Stage
(
number: 2,
category: "Demo Category",
name: "TechDemo B",
scene: "RiverWorld",
description: "River Stage",
local: false
);
// needed to generate facts
StageStatic.StageOfficial = new Dictionary<string, Stage>
{
{ demo.name, demo },
};
StageStatic.SetStage(demo.name, false);
// Populate Solution
PointFact
buttom = new PointFact(Vector3.zero, Vector3.up, StageStatic.stage.solution),
top = new PointFact(Vector3.zero + Vector3.up * minimalSolutionHight, Vector3.up, StageStatic.stage.solution);
StageStatic.stage.solution.Add(buttom, out _, false, null, null);
StageStatic.stage.solution.Add(top, out _, true, null, null);
LineFact target = new LineFact(buttom.Id, top.Id, StageStatic.stage.solution);
var target_Id = StageStatic.stage.solution.Add(target, out _, true, null, null);
// Set Solution
StageStatic.stage.solution.ValidationSet =
new List<SolutionRecorder.SubSolution> {
new SolutionRecorder.SubSolution(new HashSet<string> { target_Id }, null, null, new LineFactHightDirectionComparer()),
new SolutionRecorder.SubSolution(new HashSet<string> { target_Id }, null, null, new LineSpanningOverRiverWorldComparer()),
new SolutionRecorder.SubSolution(null, new List<int> { 1 }, new List<int> { 0 }, new LineFactHightComparer()),
StageStatic.stage.AllowedGadgets = new() { new Pointer(), new Tape(), new AngleTool(), new LineTool(), new LotTool(), new Pendulum(), new Remover() }; //, new EqualCircleGadget(), new TestMiddlePoint() };
StageStatic.stage.AllowedScrolls = new() {
"http://mathhub.info/FrameIT/frameworld?OppositeLen",
//"http://mathhub.info/FrameIT/frameworld?SupplementaryAngles",
//"http://mathhub.info/FrameIT/frameworld?AngleSum",
//"http://mathhub.info/FrameIT/frameworld?Pythagoras",
//"http://mathhub.info/FrameIT/frameworld?CylinderVolumeScroll",
//"http://mathhub.info/FrameIT/frameworld?CircleLineAngleToAngleScroll",
//"http://mathhub.info/FrameIT/frameworld?Midpoint",
//"http://mathhub.info/FrameIT/frameworld?CircleScroll",
//"http://mathhub.info/FrameIT/frameworld?CircleLineAngleScroll",
//"http://mathhub.info/FrameIT/frameworld?CircleAreaScroll",
//"http://mathhub.info/FrameIT/frameworld?ConeVolumeScroll",
//"http://mathhub.info/FrameIT/frameworld?TruncatedConeVolumeScroll",
};
Marco Zimmer
committed
StageStatic.SetMode(StageStatic.Mode.Create);
StageStatic.stage.store(false, true);
MaZiFAU
committed
public static void GenerateCanonBallStage2D()
{
// Params //List<Wall> walls, T starPos, T starVec, T gravity, int dimension
int
dim_const = 0,
MaZiFAU
committed
dim_A = 1,
dim_B = 2;
float Py_factor = 0.04905f;
float Py_bounce = 0.8f;
MaZiFAU
committed
float3 StartPos_py = new(0.0f, 300.0f, 380.0f);
float3 StartVec_py = new(0.0f, 150.0f, -490.0f);
float3 Gravity_py = new(0.0f, -200f, 0.0f);
(double x1, double x2, double y1, double y2)[] PythonParams = {
(-1.0, 0.0, 401.0, 0.0 ),
(0.0, -1.0, 0.01, 401.0 ),
(400.0, -1.0, 400.01, 401.0),
(-1.0, 400.0, 401.0, 400.0),
(50.0, 200.0, 120.0, 270.0),
(150.0, 100.0, 200.0, 100.0),
(150.0, 285.0, 200.0, 200.0),
(230.0, 360.0, 300.0, 300.0),
(300.0, 100.0, 385.0, 150.0),
(50.0, 50.0, 100.0, 135.0),
};
//Parse PythonParams
Vector3
StartPos = Vector3.zero,
StartVec = Vector3.zero,
Gravity = Vector3.zero;
MaZiFAU
committed
StartPos[0] = StartPos_py[0] * Py_factor;
StartPos[1] = StartPos_py[1] * Py_factor;
StartPos[2] = StartPos_py[2] * Py_factor;
MaZiFAU
committed
StartVec[0] = StartVec_py[0] * Py_factor;
StartVec[1] = StartVec_py[1] * Py_factor;
StartVec[2] = StartVec_py[2] * Py_factor;
MaZiFAU
committed
Gravity[0] = Gravity_py[0] * Py_factor;
Gravity[1] = Gravity_py[1] * Py_factor;
Gravity[2] = Gravity_py[2] * Py_factor;
float[,,] Wall_parameter = new float[PythonParams.Length, 2, 2];
for (uint i = 0; i < PythonParams.Length; i++)
{
MaZiFAU
committed
Wall_parameter[i, 0, 0] = (float)(Py_factor * (PythonParams[i].x1));
Wall_parameter[i, 0, 1] = (float)(Py_factor * (PythonParams[i].x2));
MaZiFAU
committed
Wall_parameter[i, 1, 0] = (float)(Py_factor * (PythonParams[i].y1));
Wall_parameter[i, 1, 1] = (float)(Py_factor * (PythonParams[i].y2));
}
// Generate Stage
Stage demo = new Stage
(
MaZiFAU
committed
number: 1,
category: "CanonBall",
name: "CanonBall 2D",
MaZiFAU
committed
description: "CanonBall 2D Test",
local: false
);
// needed to generate facts
StageStatic.StageOfficial = new Dictionary<string, Stage>
{
{ demo.name, demo },
};
StageStatic.SetStage(demo.name, false);
// Populate Solution
MaZiFAU
committed
string BallURI = StageStatic.stage.solution.Add(
new PointFact(StartPos, Vector3.up, StageStatic.stage.solution),
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(BallURI);
string VecURI = StageStatic.stage.solution.Add(
new PointFact(StartVec, StartVec.normalized, StageStatic.stage.solution),
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(VecURI);
string GravURI = StageStatic.stage.solution.Add(
new PointFact(Gravity, Gravity.normalized, StageStatic.stage.solution),
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(GravURI);
string BounceURI = StageStatic.stage.solution.Add(
new RealLitFact(Py_bounce, StageStatic.stage.solution),
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(BounceURI);
List<LineFact> Walls = new();
for (int i = 0; i < PythonParams.Length; i++)
{
Vector3 tmpVec = Vector3.zero;
MaZiFAU
committed
tmpVec[dim_A] = Wall_parameter[i, 0, 1];
tmpVec[dim_B] = Wall_parameter[i, 0, 0];
PointFact topA = new(tmpVec, Vector3.up, StageStatic.stage.solution);
string topAURI = StageStatic.stage.solution.Add(topA, out _, false, null, null);
MaZiFAU
committed
tmpVec[dim_A] = Wall_parameter[i, 1, 1];
tmpVec[dim_B] = Wall_parameter[i, 1, 0];
PointFact topB = new(tmpVec, Vector3.up, StageStatic.stage.solution);
string topBURI = StageStatic.stage.solution.Add(topB, out _, true, null, null);
LineFact topology = new(topAURI, topBURI, StageStatic.stage.solution);
MaZiFAU
committed
string lineURI = StageStatic.stage.solution.Add(topology, out _, true, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(lineURI);
MaZiFAU
committed
Walls.Add(topology);
MaZiFAU
committed
//StageStatic.stage.solution.Add( // for CannonBallScroll
// new ListFact(Walls.Select(w => w.Topology.Id).ToArray(), null, new OMS(MMTConstants.TYPE_TO_OMS[typeof(LineFact)]), StageStatic.stage.solution),
// out bool _, true, null, null
//);
SOMDoc[] RRRRTupel = new SOMDoc[Walls.Count];
RRRRTupel[i] =
SOMDoc.MakeTupel(
SOMDoc.MakeTupel(new OMLIT<float>[] { new((float)PythonParams[i].x1), new((float)PythonParams[i].x2) }),
SOMDoc.MakeTupel(new OMLIT<float>[] { new((float)PythonParams[i].y1), new((float)PythonParams[i].y2) }),
new ListFact(null, RRRRTupel, null, StageStatic.stage.solution),
out bool _, true, null, null
);
#endregion CannonBallScroll
MaZiFAU
committed
CanonBallProblemCalculator2D calc = new(Walls, StartPos, StartVec, Gravity, Py_bounce, dim_const, dim_A, dim_B, StageStatic.stage.solution);
StageStatic.stage.solution.ExposedSolutionFacts.AddRange(calc.Result_FuncCall_Id);
MaZiFAU
committed
//string attacheFactURI = StageStatic.stage.solution.Add(
// new AttachedPositionFunction(BallURI, calc.Result_FuncCall_Id.ToArray(), StageStatic.stage.solution),
// out _, true, null, null);
//StageStatic.stage.solution.ExposedSolutionFacts.Add(attacheFactURI);
MaZiFAU
committed
//TODO: ~attach funcs + ~cheat?
//StageStatic.stage.solution.ValidationSet =
// new List<SolutionOrganizer.SubSolution> {
// new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineFactHightDirectionComparer()),
// new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineSpanningOverRiverWorldComparer()),
// new SolutionOrganizer.SubSolution(null, new List<int> { 1 }, new List<int> { 0 }, new LineFactHightComparer()),
// };
// Set Gadgets/ Scrolls
StageStatic.stage.AllowedGadgets = null;
StageStatic.stage.AllowedScrolls = new() { MMTConstants.ScrollCannonBall2D };
MaZiFAU
committed
// Save
StageStatic.SetMode(StageStatic.Mode.Create);
StageStatic.stage.store(false, true);
}
public static void GenerateCanonBallStage3D()
{
// Params //List<Wall> walls, T starPos, T starVec, T gravity, int dimension
int
dim_G = 1,
dim_A = 2,
dim_B = 0;
float Py_factor = 0.04905f;
float Py_bounce = 0.8f;
MaZiFAU
committed
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
float3 StartPos_py = new(380, 0, 300);
float3 StartVec_py = new(-490, 100, 150);
float3 Gravity_py = new(0, 0, -200);
double[,,] PythonWalls = new double[,,] {
{
{ 0, 0, 0 },
{ 400, 0, 0 },
{ 400, 0, 400 },
{ 0, 0, 400 },
},{
{ 0, 400, 0 },
{ 400, 400, 0 },
{ 400, 400, 400 },
{ 0, 400, 400 },
},{
{ 250, 0, 0 },
{ 300, 0, 0 },
{ 300, 400, 0 },
{ 250, 400, 0 },
},{
{ 0, 0, 0 },
{ 0, 0, 400 },
{ 0, 400, 400 },
{ 0, 400, 0 },
},{
{ 400, 0, 0 },
{ 400, 0, 400 },
{ 400, 400, 400 },
{ 400, 400, 0 },
},{
{ 0, 0, 400 },
{ 400, 0, 400 },
{ 400, 400, 400 },
{ 0, 400, 400 },
},{
{ 300, 0, 0 },
{ 400, 0, 0 },
{ 400, 400, 0},
{ 300, 400, 0},
},{
{ 0, 0, 0 },
{ 250, 0, 0 },
{ 250, 400, 0 },
{ 0, 400, 0 },
},{
{ 50, 0, 200 },
{ 120.7, 0, 270.7 },
{ 120.7, 200, 270.7 },
{ 50, 200, 200 },
},{
{ 150, 0, 100 },
{ 200, 0, 100 },
{ 200, 200, 100 },
{ 150, 200, 100 },
},{
{ 150, 0, 286.6 },
{ 200, 0, 200 },
{ 200, 200, 200 },
{ 150, 200, 286.6 },
},{
{ 230.7, 0, 340 },
{ 300, 0, 300 },
{ 300, 200, 300 },
{ 230.7, 200, 340 },
},{
{ 300, 0, 100 },
{ 386.6, 0, 150 },
{ 386.6, 200, 150 },
{ 300, 200, 100 },
},{
{ 50, 0, 50 },
{ 100, 0, 136.6 },
{ 100, 200, 136.6 },
{ 50, 200, 50 },
}};
//Parse PythonParams
Vector3
StartPos = Vector3.zero,
StartVec = Vector3.zero,
Gravity = Vector3.zero;
StartPos[dim_A] = StartPos_py[0] * Py_factor;
StartPos[dim_B] = StartPos_py[1] * Py_factor;
StartPos[dim_G] = StartPos_py[2] * Py_factor;
StartVec[dim_A] = StartVec_py[0] * Py_factor;
StartVec[dim_B] = StartVec_py[1] * Py_factor;
StartVec[dim_G] = StartVec_py[2] * Py_factor;
Gravity[dim_A] = Gravity_py[0] * Py_factor;
Gravity[dim_B] = Gravity_py[1] * Py_factor;
Gravity[dim_G] = Gravity_py[2] * Py_factor;
float[,,] Wall_parameter = new float[PythonWalls.GetLength(0), PythonWalls.GetLength(1), PythonWalls.GetLength(2)];
for (int i = 0; i < PythonWalls.GetLength(0); i++)
for (int j = 0; j < PythonWalls.GetLength(1); j++)
for (int k = 0; k < PythonWalls.GetLength(2); k++)
Wall_parameter[i, j, k] = (float)(PythonWalls[i, j, k] * Py_factor);
// Generate Stage
Stage demo = new Stage
(
number: 2,
category: "CanonBall",
name: "CanonBall 3D",
scene: "RiverWorld",
description: "CanonBall 3D Test",
local: false
);
// needed to generate facts
StageStatic.StageOfficial = new Dictionary<string, Stage>
{
{ demo.name, demo },
};
StageStatic.SetStage(demo.name, false);
// Populate Solution
string BallURI = StageStatic.stage.solution.Add(
new PointFact(StartPos, Vector3.up, StageStatic.stage.solution),
out _, false, null, null);
MaZiFAU
committed
StageStatic.stage.solution.ExposedSolutionFacts.Add(BallURI);
string VecURI = StageStatic.stage.solution.Add(
new PointFact(StartVec, StartVec.normalized, StageStatic.stage.solution),
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(VecURI);
MaZiFAU
committed
string GravURI = StageStatic.stage.solution.Add(
new PointFact(Gravity, Gravity.normalized, StageStatic.stage.solution),
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(GravURI);
string BounceURI = StageStatic.stage.solution.Add(
new RealLitFact(Py_bounce, StageStatic.stage.solution),
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(BounceURI);
List<QuadFact> Walls = new();
List<TriangleFact> Trieangles = new();
MaZiFAU
committed
for (int i = 0; i < Wall_parameter.GetLength(0); i++)
{
Vector3[] corners = new Vector3[4];
MaZiFAU
committed
string[] edge = new string[4];
for (int j = 0; j < Wall_parameter.GetLength(1); j++)
{
MaZiFAU
committed
tmpVec[dim_A] = Wall_parameter[i, j, 0];
tmpVec[dim_B] = Wall_parameter[i, j, 1];
tmpVec[dim_G] = Wall_parameter[i, j, 2];
MaZiFAU
committed
PointFact edge_point = new(tmpVec, Vector3.up, StageStatic.stage.solution);
edge[j] = StageStatic.stage.solution.Add(edge_point, out _, false, null, null);
}
QuadFact topology = new(edge, StageStatic.stage.solution);
string quadURI = StageStatic.stage.solution.Add(topology, out _, true, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(quadURI);
TriangleFact top0 = new(new[] { corners[0], corners[1], corners[2] }, StageStatic.stage.solution);
string top0URI = StageStatic.stage.solution.Add(top0, out _, true, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(top0URI);
TriangleFact top1 = new(new[] { corners[2], corners[3], corners[0] }, StageStatic.stage.solution);
string top1URI = StageStatic.stage.solution.Add(top1, out _, true, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(top1URI);
MaZiFAU
committed
Walls.Add(topology);
Trieangles.Add(top0);
Trieangles.Add(top1);
MaZiFAU
committed
}
// Set Solution
#region CannonBallScroll
StageStatic.stage.solution.Add( // for CannonBallScroll
new ListFact(Trieangles.Select(q => q.Id).ToArray(), null, new OMS(MMTConstants.TYPE_TO_OMS[typeof(TriangleFact)]), StageStatic.stage.solution),
out bool _, true, null, null
);
MaZiFAU
committed
// special case for Prototype
SOMDoc[] RRRRTupel = new SOMDoc[Walls.Count];
for (int i = 0; i < Walls.Count; i++)
{
RRRRTupel[i] = SOMDoc.MakeTupel(
Walls[i].Pids.Select(p => new OMS(p)).ToArray()
);
}
StageStatic.stage.solution.Add(
new ListFact(null, RRRRTupel, null, StageStatic.stage.solution),
out bool _, true, null, null
);
#endregion CannonBallScroll
CanonBallProblemCalculator3D calc = new(Walls, StartPos, StartVec, Gravity, Py_bounce, dim_G, dim_A, dim_B, StageStatic.stage.solution);
//StageStatic.stage.solution.Add( // for reference
// new ListFact(calc.Result_FuncCall_Id.ToArray(), null, new OMS("Tuple((txt)x(t->t^)x(t^->fact))"), StageStatic.stage.solution),
// out bool _, true, null, null
//);
StageStatic.stage.solution.ExposedSolutionFacts.AddRange(calc.Result_FuncCall_Id);
//string attacheFactURI = StageStatic.stage.solution.Add(
// new AttachedPositionFunction(BallURI, calc.Result_FuncCall_Id.ToArray(), StageStatic.stage.solution),
// out _, true, null, null);
//StageStatic.stage.solution.ExposedSolutionFacts.Add(attacheFactURI);
//StageStatic.stage.solution.ValidationSet =
// new List<SolutionOrganizer.SubSolution> {
// new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineFactHightDirectionComparer()),
// new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineSpanningOverRiverWorldComparer()),
// new SolutionOrganizer.SubSolution(null, new List<int> { 1 }, new List<int> { 0 }, new LineFactHightComparer()),
// };
// Set Gadgets/ Scrolls
StageStatic.stage.AllowedGadgets = null;
StageStatic.stage.AllowedScrolls = new() { MMTConstants.ScrollCannonBall3D, MMTConstants.ScrollCannonBallT3D };
// Save
StageStatic.SetMode(StageStatic.Mode.Create);
StageStatic.stage.store(false, true);
}