public void addPoint(CTSPPoint point) { if (mPoints.length() == 0) { mTourLength = 0; } else { CTSPPoint lastPointInList = mPoints.getPoint(mPoints.length() - 1); CConnection additinalConnection = CConnectionList.getInstance().getConnection(lastPointInList, point); mTourLength += additinalConnection.getDistance(); } mPoints.addPoint(point); }
/// <summary> /// erstellt die Liste aller Verbindungen, anhand aller Einträge /// in der CTSPPointList /// </summary> public void generateFromPointList(CTSPLibFileParser.E_EDGE_WEIGHT_TYPE edgeWeightType) { if (edgeWeightType == CTSPLibFileParser.E_EDGE_WEIGHT_TYPE.E_EXPLICIT) { throw new Exception("Unbekannter Fehler in der Verarbeitung."); } // jetzt kann die Liste neu gefüllt werden CTSPPointList pointList = CTSPPointList.getInstance(); // die Liste neu initialiseren initList(pointList.length()); for (int originCityIndex = 0; originCityIndex < pointList.length(); originCityIndex++) { for (int destinationCityIndex = originCityIndex + 1; destinationCityIndex < pointList.length(); destinationCityIndex++) { addConnection(new CConnection(pointList.getPoint(originCityIndex), pointList.getPoint(destinationCityIndex), edgeWeightType)); Debug.WriteLineIf(length() % 100000 == 0, length()); } // Zeit für die GC lassen // Sonst gibt es Fehler, weil diese nicht genug Zeit bekommt ihr Ding zu machen System.Threading.Thread.Sleep(1); } Debug.WriteLine("Verbindungen erstellt: " + length()); }
private void drawPoints() { Gl.glPointSize(5); Gl.glColor3f(1.0f, 0f, 0f); // Städte Zeichnen CTSPPointList pointList = CTSPPointList.getInstance(); for (int pointIndex = 0; pointIndex < pointList.length(); pointIndex++) { CTSPPoint point = pointList.getPoint(pointIndex); Gl.glBegin(Gl.GL_POINTS); Gl.glVertex3d(point.x, point.y, POINT_DRAW_LAYER); Gl.glEnd(); } }
protected T_BOUNDS getBounds(CTSPPointList citys) { T_BOUNDS ret = new T_BOUNDS(); if (citys.length() > 0) { ret.left = double.MaxValue; ret.bottom = double.MaxValue; for (int cityIndex = 0; cityIndex < citys.length(); cityIndex++) { CTSPPoint city = citys.getPoint(cityIndex); if (city.x < ret.left) { ret.left = city.x; } if (city.y < ret.bottom) { ret.bottom = city.y; } if (city.x > ret.right) { ret.right = city.x; } if (city.y > ret.top) { ret.top = city.y; } } } else { ret.left = 0; ret.bottom = 0; ret.right = this.Width; ret.top = this.Height; } return(ret); }
private void handleEdgeWeightElement(string element, int elementIndex) { CTSPPointList pointList = CTSPPointList.getInstance(); CConnectionList connList = CConnectionList.getInstance(); float distance = float.Parse(element); switch (mFileHeader.edgeWeightFormat) { case E_EDGE_WEIGHT_FORMAT.E_FULL_MATRIX: { int row = elementIndex / mFileHeader.dimension; int pointIndex = elementIndex % mFileHeader.dimension; // Es werden nur die Punkte unter der Diagonalen betrachtet. // damit werden keine Verbindungen Doppelt eingefügt und Verbindungen // auf den gleichen Punkt, also Distanz = 0, vermieden if (pointIndex < row) { CTSPPoint point1 = pointList.getPoint(row); CTSPPoint point2 = pointList.getPoint(pointIndex); connList.addConnection(new CConnection(point1, point2, distance, CAntAlgorithmParameters.getInstance().initialPheromone)); } break; } case E_EDGE_WEIGHT_FORMAT.E_UPPER_ROW: { int row = 0; while ((elementIndex / (mFileHeader.dimension - 1 - row)) > 0) { elementIndex -= (mFileHeader.dimension - 1 - row); row++; } // Index des Punktes ist der Offset bis zur Diagonalen + den Index des Elementes int pointIndex = row + 1 + elementIndex; CTSPPoint point1 = pointList.getPoint(row); CTSPPoint point2 = pointList.getPoint(pointIndex); connList.addConnection(new CConnection(point1, point2, distance, CAntAlgorithmParameters.getInstance().initialPheromone)); break; } case E_EDGE_WEIGHT_FORMAT.E_UPPER_DIAG_ROW: { int row = 0; while ((elementIndex / (mFileHeader.dimension - row)) > 0) { elementIndex -= (mFileHeader.dimension - row); row++; } // Index des Punktes ist der Offset bis zur Diagonalen + den Index des Elementes int pointIndex = row + elementIndex; if (pointIndex != row) { CTSPPoint point1 = pointList.getPoint(row); CTSPPoint point2 = pointList.getPoint(pointIndex); connList.addConnection(new CConnection(point1, point2, distance, CAntAlgorithmParameters.getInstance().initialPheromone)); } break; } case E_EDGE_WEIGHT_FORMAT.E_LOWER_DIAG_ROW: { int row = 0; int pointIndex = elementIndex; while ((pointIndex / (row + 1)) > 0) { pointIndex -= row + 1; row++; } if (pointIndex != row) { CTSPPoint point1 = pointList.getPoint(pointIndex); CTSPPoint point2 = pointList.getPoint(row); connList.addConnection(new CConnection(point1, point2, distance, CAntAlgorithmParameters.getInstance().initialPheromone)); } break; } } }