uitsp.pas

来自「这是一道很基本的程序」· PAS 代码 · 共 96 行

PAS
96
字号
{ interface-based implementation of
  Dan Taylor's (dan@logicalgenetics.com)
  Evolutionary TSP Algorithm demo program
Modified: September 2002
  by Nikolai Shokhirev (nikolai@u.arizona.edu)
  http://www.chem.arizona.edu/~shokhirn/index.html) }
{ TSP-specific Interfaces }
unit uITSP;

interface
uses
  uUtilsEA, uIEA, Windows, Classes, controls;

type

  ITSPController = interface;

  ITSPIndividual = interface(IIndividual)
  ['{BD6061CA-8529-11D6-8252-00C04F2859BF}']
    function GetRouteArray(I: Integer): Integer;
    procedure SetRouteArray(I: Integer; const Value: Integer);
    procedure SetSteps(const Value: Integer);
    function GetSteps: Integer;
    property RouteArray[I : Integer] : Integer read GetRouteArray write SetRouteArray;
    property Steps : Integer read GetSteps write SetSteps;
//    property Fitness : TFloat read GetFitness write SetFitness;
  end;

  ITSPController = interface
  ['{BD6061CB-8529-11D6-8252-00C04F2859BF}']
    function GetXmax: TFloat;
    function GetXmin: TFloat;
    function GetYmax: TFloat;
    function GetYmin: TFloat;
    procedure SetXmax(const Value: TFloat);
    procedure SetXmin(const Value: TFloat);
    procedure SetYmax(const Value: TFloat);
    procedure SetYmin(const Value: TFloat);
    function GetCity(I: Integer): TPoint2D;
    procedure SetCityCount(const Value: Integer);
    function GetCityCount: Integer;
    {  Get the distance between two cities }
    function DistanceBetween(C1, C2 : Integer) : TFloat;
    {  Places the cities at random points }
    procedure RandomCities;
    {  Area limits }
    property Xmin: TFloat read GetXmin write SetXmin;
    property Xmax: TFloat read GetXmax write SetXmax;
    property Ymin: TFloat read GetYmin write SetYmin;
    property Ymax: TFloat read GetYmax write SetYmax;
    {  Access to the cities array }
    property Cities[I: Integer] : TPoint2D read GetCity;
    {  Properties... }
    property CityCount: Integer read GetCityCount write SetCityCount;
  end;

  ITSPDisplay = interface
  ['{BD6061CC-8529-11D6-8252-00C04F2859BF}']
    {  Call this to draw the map }
    procedure DrawMap;
    {  Draw the map with a route  }
    procedure DrawMapWithRoute(Individual : ITSPIndividual);
  end;

  ITSPCreator = interface(ICreator)
  ['{BD6061CD-8529-11D6-8252-00C04F2859BF}']
    function GetController: ITSPController;
    procedure SetController(const Value: ITSPController);
    function CreateIndividual : IIndividual;
    property Controller : ITSPController read GetController write SetController;
  end;

  ITSPMutator = interface(IMutator)
  ['{BD6061CE-8529-11D6-8252-00C04F2859BF}']
    procedure SetInv(const Value: TFloat);
    procedure SetTrans(const Value: TFloat);
    function GetInv: TFloat;
    function GetTrans: TFloat;
    // Probability of doing a transposition
    property Transposition : TFloat read GetTrans write SetTrans;
    // Probability of doing an inversion
    property Inversion : TFloat read GetInv write SetInv;
  end;

  ITSPExaminer = interface(IExaminer)
  ['{BD6061CF-8529-11D6-8252-00C04F2859BF}']
    function GetController: ITSPController;
    procedure SetController(const Value: ITSPController);
    // Returns the fitness of an individual as a real number where 0 => best
    property Controller : ITSPController read GetController write SetController;
  end;

implementation

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?