Algorytm kruskala - błąd

0

Witam
Chciałbym przetestować algorytm Kruskala znaleziony w internecie. Dopiero uczę się programowania i nie wiem jak poradzić sobie z tym błędem.

The type or namespace name 'Point' could not be found (are you missing a using directive or an assembly reference?)

Znajduję sie on w linijce :

public Kruskal(Point[] points)

Kod:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication12
{
    public class Edge
    {
        public double Length { get; private set; }
        public int Point1 { get; private set; }
        public int Point2 { get; private set; }

        public Edge(int pt1, int pt2, double length)
        {
            Point1 = pt1;
            Point2 = pt2;
            Length = length;
        }

        public override string ToString()
        {
            return String.Format("({0}-{1})={2:0.00}", Point1, Point2, Length);
        }
    }
    public class Kruskal
    {
        public Edge[] Result { get; private set; }
        public double Span { get; private set; }
        public Kruskal(Point[] points)
        {
            int edgesArrayLength = 0;
            
            for (int i = points.Length - 1; i > 0; i--)
                edgesArrayLength += i;
            Edge[] edges = new Edge[edgesArrayLength];

            
            for (int i = 0, index = 0; i < points.Length; i++)
                for (int j = i + 1; j < points.Length; j++)
                {
                    int dx = points[i].X - points[j].X;
                    int dy = points[i].Y - points[j].Y;
                    edges[index] = new Edge(i, j, Math.Sqrt(dx * dx + dy * dy));
                    index++;
                }

            var sortEdges = edges.OrderBy(a => a.Length);
          
            int[] sets = new int[points.Length];
            Result = new Edge[points.Length - 1];
            int processedEdges = 0;
            foreach (var edge in sortEdges)
            {
               
                if (processedEdges == points.Length - 1)
                    break;

               
                if (sets[edge.Point1] == 0 || sets[edge.Point1] != sets[edge.Point2])
                {
                    Result[processedEdges] = edge;
                    Span += edge.Length;
                    processedEdges++;
                  
                    if (sets[edge.Point1] != 0 || sets[edge.Point2] != 0)
                    {
                        //To te zbiory będą łączone w jeden
                        int set1 = sets[edge.Point1];
                        int set2 = sets[edge.Point2];
                        
                        for (int i = 0; i < points.Length; i++)
                            if (sets[i] != 0 && (sets[i] == set1 || sets[i] == set2))
                                sets[i] = processedEdges;
                    }
                 
                    sets[edge.Point1] = processedEdges;
                    sets[edge.Point2] = processedEdges;
                }
            }
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            Point[] points = new Point[]
        {
            new Point(0,0),
            new Point(3,0),
            new Point(5,0),
            new Point(0,1),
            new Point(2,1),
            new Point(5,1),
            new Point(1,2),
            new Point(3,2),
            new Point(2,4),
            new Point(6,4)
        };

            var kruskal = new Kruskal(points);
            Console.WriteLine(String.Format("Rozpiętość {0:0.00}", kruskal.Span));
            for (int i = 0; i < kruskal.Result.Length; i++)
                Console.WriteLine(kruskal.Result[i]);
        }
    } 
}


Z góry dziękuję za pomoc.
Pozdrawiam

0

Hint: gdzie jest Point ?

0

Chodzi o użycie biblioteki? Znalazłem, że Point znajduje się w bibliotece System.Drawing ale w dalszym ciągu wyskakuje ten sam błąd.

0
Zorro123 napisał(a):

Chodzi o użycie biblioteki? Znalazłem, że Point znajduje się w bibliotece System.Drawing ale w dalszym ciągu wyskakuje ten sam błąd.

To dodaj tę bibliotekę do referencji...

0

czyli dopisz na początku

using System.Drawing;
0
MarcoDeMarco napisał(a):

czyli dopisz na początku

using System.Drawing;

To już zrobił, ale pewnie ma wybrany typ aplikacji konsolowej i automatycznie mu się referencje do dll-ki nie podpięły dla tego system.drawing.

0

Sprawdź, czy masz tak (jeśli nie, prawym myszki na References -> Add reference -> .NET i szukasz System.Drawing):

user image

0

Działa. Nauczyłem się czegoś nowego. Dziękuje za pomoc :)

0
struct Point {
  public int X;
  public int Y;
}
0

No a kolega wyżej podał najprostsze rozwiązanie :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1