cloudflight
2023-12-16 ee714f35348c909d5843093fa80bd82d2bbf0184
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using Hydro.CommonBase;
using Hydro.Core.Model;
using Hydro.HydraulicOptimizer;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using TimePoint = Hydro.CommonBase.TimePoint;
 
namespace Hydro.MapView
{
    public class calc
    {
        public WDNModelOptimizer wdo;
 
        public DateTime time = DateTime.Now;
        public DateTime T_time = DateTime.Now;
        public WdnmoParam wParam = null;
        public List<TimePoint> GetCalcResult(string InpPath, WdnmoParam wP, string configPath = null)
        {
 
            string result = null;
 
            Console.Write("请输入重复计算次数:(默认:1)");
            string sr;
            T_time = DateTime.Now;
            GeneticParams gparam = new GeneticParams(0);
 
            var wdo = new WDNModelOptimizer(gparam);
            WdnmoParam param;
 
            #region bak1
 
            wParam = wP;
 
            param = wParam;
 
 
 
 
            #endregion bak1
 
 
 
            time = DateTime.Now;
            if (configPath == null) configPath = System.IO.Directory.GetCurrentDirectory() + "\\" + "config_calc.wdb"; ;
            string path = configPath;
            result = wdo.Init(path, InpPath, onFinish, onError, null, param, false);
            if (result != null)
            {
                wdo.Close();
                throw new Exception(result);
 
                //return null;
                //return;
            }
 
            result = wdo.Run(param, false);
 
            while (true)
            {
                lock (lockobj)
                {
                    if (isFinished)
                    {
                        if (wdo != null)
                            wdo.Close();
                        break;
 
                    }
                }
 
            }
            //wParam.ResultPoints.ForEach(p => p.Value = num);
            return wParam.ResultPoints;
 
        }
        object lockobj = new object();
        public string getStringByJson(string path)
        {
            StreamReader sr = new StreamReader(path);
            string s = sr.ReadToEnd();
            sr.Close();
            return s;
        }
 
        public bool isFinished = false;
        public object FOBJ = new object();
        public void onFinish(dynamic modelParams)
        {
 
            var param = modelParams as WdnmoParam;
 
 
 
 
            new Thread(() =>
            {
                Thread.Sleep(100);
                if (wdo != null)
                    wdo.Close();
            }).Start();
            this.wParam = param;
            lock (lockobj)
            {
                isFinished = true;
            }
 
        }
        public void onError(dynamic result)
        {
 
 
            //MessageBox.Show("原因:" + result, "计算失败");
            new Thread(() =>
            {
                Thread.Sleep(1000);
                if (wdo != null)
                    wdo.Close();
            }).Start();
            lock (lockobj)
            {
                isFinished = true;
            }
            throw new Exception("计算失败,原因:" + result);
        }
 
    }
}