「日記2010年8月その2」の編集履歴(バックアップ)一覧に戻る
日記2010年8月その2」を以下のとおり復元します。
2010/8/5
架空鉄道
柏鉄鉄道という路線の設定を作っているテツオタの方がいまして。
http://www.pixiv.net/member_illust.php?mode=medium&illust_id=8264767
http://www.pixiv.net/member_illust.php?mode=medium&illust_id=11922112

このデータから下記リンク先のような運賃表を完成させたいそうなのです。
http://www.pixiv.net/member_illust.php?mode=medium&illust_id=12044821



なんだか手作業で大変そうなので。
コメントをやり取りしてみるとデータは静的、信頼できないデータは来ないし外部センサーが不調になる可能性も考えなくていい、ユーザーがでたらめな操作もしない。
プログラムとしてはとても楽な話のようです。

私C#の勉強もかねて運賃表を作成することにしてみました。





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;

namespace 架空鉄道柏鉄運賃表計算プログラム
{
    public partial class Form1 : Form
    {

        Hashtable ht = new Hashtable();
        List<double> lenSums = new List<double>();  
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            StreamReader sr = new StreamReader(
                            "D:/色々/架空鉄道運賃表/柏鉄路線データ.txt", Encoding.GetEncoding("Shift_JIS"));
            char[] delimiterChars = {'\t'};

            while (!sr.EndOfStream)
            {
                string s=sr.ReadLine();
                string[] row = s.Split(delimiterChars);
                setStationDate(row[0],row[1],double.Parse(row[2])); 
            }
            sr.Close();
            sr = new StreamReader(
                           "D:/色々/架空鉄道運賃表/柏鉄路線データ駅名一覧.txt", Encoding.GetEncoding("Shift_JIS"));
            List<string> stationNames = new List<string>();
            while (!sr.EndOfStream)
            {
                stationNames.Add ( sr.ReadLine());
            }
            sr.Close();

            int count =stationNames.Count;  
            string [,] sUntinDate=new string [count+1,count+1];
            sUntinDate[0, 0] = "";
            for (int i = 1; i < count+1; i++)
            {
                sUntinDate[0, i] = stationNames[i];
                sUntinDate[i, 0] = stationNames[i];  
            }

                for (int i = 0; i < count; i++)
                {
                    for (int j = 0; j < count; j++)
                    {
                        search_root(stationNames[i], stationNames[j], 0.0d);
                        lenSums.Sort();
                        sUntinDate[i + 1, j + 1] = lenSums[0].ToString();
                        lenSums.Clear();
                    }
                }
             

        }

        


        internal void search_root(string sNowStation,string sGoalStation,double sumKm)
        {
            
            

            if(sNowStation==sGoalStation){
                lenSums.Add(sumKm);  
            }else{
                stationDate sd = (stationDate)ht[sNowStation];

                if (sd != null && sd.stampGoOk==true )
                {
                    sd.stampGoOk = false;
                    ht[sNowStation] = sd;
                    for (int i = 0; i < sd.nextStation.Count; i++)
                    {
                        search_root(sd.nextStation[i], sGoalStation, sumKm + sd.nextLen[i]);
                    }
                    sd.stampGoOk = true;
                    ht[sNowStation] = sd;
                }
                
            }
        }


        public void setStationDate(string sStation1,string sStation2,double len){

            stationDate SD; 

            if (ht[sStation1] == null)
            {
                ht[sStation1] = new stationDate();
            }
            SD=(stationDate)ht[sStation1];
            SD.set_StationDate(sStation2 ,len);
            ht[sStation1] = SD;


            if (ht[sStation2] == null)
            {
                ht[sStation2] = new stationDate();
            }
            SD = (stationDate)ht[sStation2];
            SD.set_StationDate(sStation1, len);
            ht[sStation2] = SD;
        }



    }
    public class stationDate
    {
        internal List<string> nextStation = new List<string>();
        internal List<double> nextLen = new List<double>();
        internal bool stampGoOk = true;//駅間の経路探索のとき一度通った駅か記録するため、 通ってないならtrue
        public void set_StationDate(string sNextStation, double dLen)
        {
            nextStation.Add(sNextStation);
            nextLen.Add(dLen);
        }
    }
}

復元してよろしいですか?