Графы, мультиграфы, молекулярные графы: Delphi-классы
Программы на Delphi могут использовать библиотеку для работы с графами mathgrph.dll (© Захаров С.В, 2002), написанную на C++. Для удобства её использования Вы можете скачать набор классов Delphi для работы с mathgrph.dll (не забудьте разместить mathgrph.dll в системном каталоге Вашего компьютера перед запуском Delphi-программы). Библиотека mathgrph.dll и модули на Delphi, обеспечивающие интерфейс с ней для программ, написанных на Delphi, являются свободным программным обеспечением с открытым исходным кодом. При этом mathgrph.dll распространяется в рамках GNU Library General Public License, а интерфейсный модуль на Delphi, представляющий собой часть программы-примера для Delphi, в рамках обычной GNU General Public License. Набор содержит следующие классы:
TMathGraph = class(TObject) // Простой граф (с координатами вершин). protected G: IVGraph; C: IVCoordGraph; procedure InitGraph; virtual; function GetTopCount: Integer; procedure SetTopCount(ATopCount: Integer); function GetConnected(Index1, Index2: Integer): Boolean; procedure SetConnected(Index1, Index2: Integer; Conn: Boolean); public constructor Create; procedure AddTop; // Добавить вершину в граф. procedure Clear; // Удалить все вершины из графа. procedure DeleteTop(Index: Integer); // Удалить вершину с индексом Index. procedure GetCoord(Index: Integer; var x: Double; var y: Double; var z: Double); // Получить координаты вершины Index. procedure SetCoord(Index: Integer; x,y,z: Double); // Задать координаты вершины Index. property Connected[Index1: Integer; Index2: Integer]: Boolean read GetConnected write SetConnected; // Связаны ли вершины Index1 и Index2. property TopCount: Integer read GetTopCount write SetTopCount; // Кол-во вершин в графе. end; TMultiGraph = class(TMathGraph) // Мультиграф. protected MG: IVMultiGraph; procedure InitGraph; override; function GetBondRange(Index1, Index2: Integer): Integer; procedure SetBondRange(Index1, Index2: Integer; ABondRange: Integer); public // Кратность связи между вершинами Index1 и Index2. property BondRange[Index1, Index2: Integer]: Integer read GetBondRange write SetBondRange; end; // Молекулярный граф. TMolecularGraph = class(TMultiGraph) protected Mol: IVMolecularGraph; procedure InitGraph; override; function GetElement(Index: Integer): string; procedure SetElement(Index: Integer; AElement: string); public procedure AddAtom(El: string); // Добавить атом. // Одинаковы ли атомы в вершинах Index1 и Index2. // Обычно атомы считаются одинаковыми, если они принадлежат одному // и тому же хим. элементу. Но в производных классах могут быть заданы // более строгие условия, например, что должны совпадать и изотопы. function Same(Index1, Index2: Integer): Boolean; virtual; // Хим. символ элемента в вершине Index. property Element[Index: Integer]: string read GetElement write SetElement; end;