csucs class

This commit is contained in:
2025-03-10 10:38:51 +01:00
parent f7d7206f10
commit 2915fec180
6 changed files with 92 additions and 20 deletions

View File

@@ -2,29 +2,87 @@ using System;
using System.Collections.Generic;
using System.Linq;
namespace Keres{
abstract class Feladat<T> {
namespace Keres
{
public class Feladat<T>
{
public T Kezdo { get; }
public T Cel{ get; protected set;}
public T Cel { get; protected set; }
public Feladat(T kezdo, T cel){
public Feladat(T kezdo, T cel)
{
Kezdo = kezdo;
Cel = cel;
}
public virtual bool Celteszt(T allapot){
public virtual bool Celteszt(T allapot)
{
return EqualityComparer<T>.Default.Equals(allapot, Cel);
}
public abstract IEnumerable<(string, T)> Rakovetkezo(T allapot);
public virtual IEnumerable<(string, T)> Rakovetkezo(T allapot){
throw new NotImplementedException();
}
public virtual int Utkoltseg(int c, T allapot1, string lepes, T allapot2){
return c+1;
public virtual int Utkoltseg(int c, T allapot1, string lepes, T allapot2)
{
return c + 1;
}
}
public class Csucs<T>{
public class Csucs<T>
{
public T Allapot { get; } // The state of this node
public Csucs<T>? Szulo { get; } // Parent node
public string? Lepes { get; } // Action taken to reach this node
public int Utkoltseg { get; } // Path cost (g(n))
public int Melyseg { get; } // Depth in the tree
public Csucs(T allapot, Csucs<T>? szulo = null, string? lepes = null, int utkoltseg = 0)
{
Allapot = allapot;
Szulo = szulo;
Lepes = lepes;
Utkoltseg = utkoltseg;
Melyseg = szulo?.Melyseg + 1 ?? 0;
}
public override string ToString()
{
return $"<Csucs: {Allapot}>";
}
/// <summary>
/// Returns the path from the root to this node.
/// </summary>
public List<Csucs<T>> Ut(){
List<Csucs<T>> valasz = new List<Csucs<T>>();
for(Csucs<T>? x = this; x != null; x = x.Szulo){
valasz.Add(x);
}
valasz.Reverse();
return valasz;
}
/// <summary>
/// Returns the sequence of steps taken to reach this node.
/// </summary>
public List<string?> Megoldas(){
return Ut().Skip(1).Select(csucs => csucs.Lepes).ToList();
}
public IEnumerable<Csucs<T>> Kiterjeszt(Feladat<T> feladat){
foreach(var (muvelet, kovetkezo) in feladat.Rakovetkezo(Allapot)){
if(!Ut().Select(csucs => csucs.Allapot).Contains(kovetkezo)){
yield return new Csucs<T>(kovetkezo, this, muvelet, feladat.Utkoltseg(Utkoltseg, Allapot, muvelet, kovetkezo));
}
}
}
}
}

View File

@@ -0,0 +1,14 @@
/home/tom/Dev/MestInt/ora1gyak/obj/Debug/net8.0/ora1gyak.GeneratedMSBuildEditorConfig.editorconfig
/home/tom/Dev/MestInt/ora1gyak/obj/Debug/net8.0/ora1gyak.AssemblyInfoInputs.cache
/home/tom/Dev/MestInt/ora1gyak/obj/Debug/net8.0/ora1gyak.AssemblyInfo.cs
/home/tom/Dev/MestInt/ora1gyak/obj/Debug/net8.0/ora1gyak.csproj.CoreCompileInputs.cache
/home/tom/Dev/MestInt/ora1gyak/bin/Debug/net8.0/ora1gyak
/home/tom/Dev/MestInt/ora1gyak/bin/Debug/net8.0/ora1gyak.deps.json
/home/tom/Dev/MestInt/ora1gyak/bin/Debug/net8.0/ora1gyak.runtimeconfig.json
/home/tom/Dev/MestInt/ora1gyak/bin/Debug/net8.0/ora1gyak.dll
/home/tom/Dev/MestInt/ora1gyak/bin/Debug/net8.0/ora1gyak.pdb
/home/tom/Dev/MestInt/ora1gyak/obj/Debug/net8.0/ora1gyak.dll
/home/tom/Dev/MestInt/ora1gyak/obj/Debug/net8.0/refint/ora1gyak.dll
/home/tom/Dev/MestInt/ora1gyak/obj/Debug/net8.0/ora1gyak.pdb
/home/tom/Dev/MestInt/ora1gyak/obj/Debug/net8.0/ora1gyak.genruntimeconfig.cache
/home/tom/Dev/MestInt/ora1gyak/obj/Debug/net8.0/ref/ora1gyak.dll

View File

@@ -1,17 +1,17 @@
{
"format": 1,
"restore": {
"/home/tom/Dev/mestint/ora1gyak/ora1gyak.csproj": {}
"/home/tom/Dev/MestInt/ora1gyak/ora1gyak.csproj": {}
},
"projects": {
"/home/tom/Dev/mestint/ora1gyak/ora1gyak.csproj": {
"/home/tom/Dev/MestInt/ora1gyak/ora1gyak.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/tom/Dev/mestint/ora1gyak/ora1gyak.csproj",
"projectUniqueName": "/home/tom/Dev/MestInt/ora1gyak/ora1gyak.csproj",
"projectName": "ora1gyak",
"projectPath": "/home/tom/Dev/mestint/ora1gyak/ora1gyak.csproj",
"projectPath": "/home/tom/Dev/MestInt/ora1gyak/ora1gyak.csproj",
"packagesPath": "/home/tom/.nuget/packages/",
"outputPath": "/home/tom/Dev/mestint/ora1gyak/obj/",
"outputPath": "/home/tom/Dev/MestInt/ora1gyak/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/tom/.nuget/NuGet/NuGet.Config"

View File

@@ -13,11 +13,11 @@
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/tom/Dev/mestint/ora1gyak/ora1gyak.csproj",
"projectUniqueName": "/home/tom/Dev/MestInt/ora1gyak/ora1gyak.csproj",
"projectName": "ora1gyak",
"projectPath": "/home/tom/Dev/mestint/ora1gyak/ora1gyak.csproj",
"projectPath": "/home/tom/Dev/MestInt/ora1gyak/ora1gyak.csproj",
"packagesPath": "/home/tom/.nuget/packages/",
"outputPath": "/home/tom/Dev/mestint/ora1gyak/obj/",
"outputPath": "/home/tom/Dev/MestInt/ora1gyak/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/tom/.nuget/NuGet/NuGet.Config"

View File

@@ -1,8 +1,8 @@
{
"version": 2,
"dgSpecHash": "6++IdPzGwkAIg/uzl5ldolEqJu61iAjLnWh+qV2PgIiRbX9Ix9XOBePbaLs9qaF5jyMOOgmAOXn3h9eMTkHlaA==",
"dgSpecHash": "TmB9rBKg2O3dJIEyjAoFHeHzE4yeHzDGtzDXp6FD5dgvRPnHhiiDl3UcbmoJRuK4sHRdNFwixioP5NT+dLYafw==",
"success": true,
"projectFilePath": "/home/tom/Dev/mestint/ora1gyak/ora1gyak.csproj",
"projectFilePath": "/home/tom/Dev/MestInt/ora1gyak/ora1gyak.csproj",
"expectedPackageFiles": [],
"logs": []
}