Discussions related to Visual Prolog
HW
Posts: 1
Joined: 20 May 2015 11:15

Implementation of a distance matrix

Unread post by HW »

I am looking at implementing a distance matrix (see https://en.wikipedia.org/wiki/Distance_matrix for an example) and was wondering how to implement a GUI representation with edit functionality. I had a look at the grid control but unless I have overlooked something this control seems to be based on columns and rows which does not exactly correspond to the structure of a matrix. A workaround I was thinking of would be to have the first column in the grid control to hold the column names one per row but maybe there is a smarter way than this?
Holger
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Is your distance matrix symmetric?

Unread post by Ferenc Nagy »

Is your distance matrix symmetric?
Is d(I,J)=d(J,I) ?
Is d(I,J)>=0 always?

Internal storage
If they are symmetric then you can use a binary array of N*(N-1) div 2 unsigned real elements.
You can easily construct a function calculating the position of D(I,J), I>J in this array.
If J<I then the position is the same.

GUI surface
I had some trials with grid controls in the version 5 of Visual Prolog.
It was cumbersome. When I finally understood how its Grid Tool works I saw the contents of the edited cell becomes invisible.
I have the Personal Edition of VIP 7.5 so I do not have grid control.
I have developed, however four techniques for handing matrices which I can recommend you
I)
1) Plan a dialog without frame for editing a single row of your matrix. This dialog may contain each kinds of basic built-in controls.
2) Construct a large holder dialog with OK, Cancel, Help, and row navigation buttons. Place as much instances of the row editing dialog as its height and the height of the holder without the buttons allows.
3) You have to write the procedures for navigation, loading from the distance matrix to the dialog corresponding a row and back from the dialog to the matrix.

II)
1) Place list boxes on the main dialog showing the identifiers and labels of the points and their distances.
2) Write onSelectionChanged event handler which synchronize the list boxes. See my contribution "My Dialog Tricks"
3) Place a Modify button on the dialog which moves the data of the selected item to separate editable fields.
4) You need Replace, Insert and Delete buttons, too.

III) Same as II) but
1) One list box using tabulators is used instead of more synchronized.
2) It needs string concatenation and splitting.
3) It fails when more than the last field has high maximal length.

IV) If the number of rows is below 50.
1) You may use the Task Window itself as parent window of row handling dialogs.
2) In this case you have to program yourself the size and position of them, the built-in Tile and Cascade Window handling is not enough. May be that some windows are hidden and the user has to use the dynamic part of the Window menu to bring them into front.
TIA, Regards,
Frank Nagy
Post Reply