| | |
| | | return false; |
| | | |
| | | Type[] types = new Type[] { |
| | | // typeof(Entity.ScheduleCombine), |
| | | // typeof(Entity.ScheduleCombine), |
| | | // typeof(Entity.ScheduleCombineLog), |
| | | typeof(Entity.ScheduleAnaLog), |
| | | |
| | |
| | | return $"{_tableNamePrefix}{runFlag}"; |
| | | } |
| | | |
| | | private readonly string _createTable = "(\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n RunFlag VARCHAR (255),\r\n RunCount INTEGER,\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n CurveQH VARCHAR (255),\r\n CurveQP VARCHAR (255),\r\n MaxFlow REAL,\r\n MinFlow REAL,\r\n MaxHead REAL,\r\n MinHead REAL,\r\n AnaStatus BIT\r\n);"; |
| | | |
| | | /// <summary> |
| | | /// è·åå
¨é¨è¡¨å |
| | | /// </summary> |
| | |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public bool BulkInserts_SplitTable(List<Entity.ScheduleCombine> list) |
| | | { |
| | | if (list == null || list.Count < 1) |
| | | return default; |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | ///èªå·±æ¥å¶å®å®ä¹çè§å |
| | | db.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = new Entity.ScheduleCombineSubTableService(); |
| | | db.CodeFirst |
| | | .SplitTables()//æ è¯å表 |
| | | .InitTables<Entity.ScheduleCombine>(); //ç¨åºå¯å¨æ¶å è¿ä¸è¡,妿ä¸å¼ 表没æä¼åå§åä¸å¼ |
| | | |
| | | //å¤§æ°æ®åå
¥+表ä¸åå¨ä¼å»ºè¡¨ |
| | | //èªå¨æ¾è¡¨å¤§æ°æ®åå
¥ |
| | | return db.Fastest<Entity.ScheduleCombine>().SplitTable().BulkCopy(list) > 0; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public async Task<bool> BulkInserts_Create_Async(string runFlag, List<Entity.ScheduleCombine> list) |
| | | { |
| | | if (list == null || list.Count < 1) |
| | | return default; |
| | | var tableName = GetTableName(runFlag); |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var exist_sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}' ;"; |
| | | if (db.Ado.GetInt(exist_sql) < 1) |
| | | { |
| | | var sql_create_table = $"CREATE TABLE {tableName} (\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n RunFlag VARCHAR (255),\r\n RunCount INTEGER,\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n CurveQH VARCHAR (255),\r\n CurveQP VARCHAR (255),\r\n AnaStatus BIT\r\n);"; |
| | | if (db.Ado.ExecuteCommand(sql_create_table) < 1) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | return await db.Fastest<Entity.ScheduleCombine>().AS(tableName).BulkCopyAsync(list) > 0; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var exist_sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; |
| | | if (db.Ado.ExecuteCommand(exist_sql) < 1) |
| | | if (db.Ado.GetInt(exist_sql) < 1) |
| | | { |
| | | var sql_create_table = $"CREATE TABLE {tableName} (\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n RunFlag VARCHAR (255),\r\n RunCount INTEGER,\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n CurveQH VARCHAR (255),\r\n CurveQP VARCHAR (255),\r\n AnaStatus BIT\r\n);"; |
| | | var sql_create_table = $"CREATE TABLE {tableName} {_createTable}"; |
| | | db.Ado.ExecuteCommand(sql_create_table); |
| | | } |
| | | //å¤§æ°æ®åå
¥ |
| | | return db.Fastest<Entity.ScheduleCombine>().AS(tableName).BulkCopy(list) > 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public bool BulkInserts_NativeSql(string runFlag, List<Entity.ScheduleCombine> list) |
| | | { |
| | | var tableName = GetTableName(runFlag); |
| | | var connect = ConfigHelper.ConnectionString; |
| | | SQLiteConnection connection = new SQLiteConnection(connect);//è¿æ¥å¯¹è±¡åå§å |
| | | connection.Open();//æå¼è¿æ¥ |
| | | |
| | | SQLiteCommand command = new SQLiteCommand(connection);//å½ä»¤å¯¹è±¡åå§å |
| | | command.CommandText = $"VACUUM;";//æ§è¡VACUUMå½ä»¤æ¶ç¼©æ°æ®åº |
| | | command.ExecuteNonQuery(); |
| | | |
| | | SQLiteTransaction transaction = connection.BeginTransaction();//å¼å§äºå¡ |
| | | var sql_exist_table = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; |
| | | command.CommandText = sql_exist_table; |
| | | if (command.ExecuteNonQuery() < 1)//没æè¡¨å°±å建表 |
| | | { |
| | | var sql_create_table = $"CREATE TABLE {tableName} (\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n RunFlag VARCHAR (255),\r\n RunCount INTEGER,\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n CurveQH VARCHAR (255),\r\n CurveQP VARCHAR (255),\r\n AnaStatus BIT\r\n);"; |
| | | command.CommandText = sql_create_table; |
| | | command.ExecuteNonQuery(); |
| | | } |
| | | |
| | | var group = list.GroupBy(x => x.ID).Where(x => x.Count() > 1).Count(); |
| | | |
| | | for (int i = 0; i < list.Count; i++) //[---使ç¨äºå¡---]æ§è¡INSERTå½ä»¤ |
| | | { |
| | | var item = list[i]; |
| | | var sql_insert = $"INSERT INTO {tableName}(ID, RunFlag, RunCount, Pump1, Pump2, Pump3, CurveQH, CurveQP, AnaStatus) " + |
| | | $"VALUES ('{item.ID}','{item.RunFlag}','{item.RunCount}','{item.Pump1}','{item.Pump2}','{item.Pump3}','{item.CurveQH}','{item.CurveQP}','{item.AnaStatus}')"; |
| | | command.CommandText = sql_insert; |
| | | command.ExecuteNonQuery(); |
| | | } |
| | | // var result = command.ExecuteScalar(); |
| | | transaction.Commit();//æäº¤äºå¡ |
| | | connection.Close();//å
³éè¿æ¥ |
| | | return true; |
| | | } |
| | | |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System.Threading.Tasks; |
| | | using System.Xml.Linq; |
| | | |
| | | namespace IStation.DAL |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public class ScheduleCombine_bak |
| | | { |
| | | public SqlSugarClient Connection |
| | | { |
| | | get { return ConfigHelper.GetSqlSugarClient(); } |
| | | } |
| | | |
| | | private readonly string _tableNamePrefix = "ScheduleCombine_Cb_"; |
| | | |
| | | private string GetTableName(string runFlag) |
| | | { |
| | | return $"{_tableNamePrefix}{runFlag}"; |
| | | } |
| | | |
| | | private readonly string _createTable = "(\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n RunFlag VARCHAR (255),\r\n RunCount INTEGER,\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n CurveQH VARCHAR (255),\r\n CurveQP VARCHAR (255),\r\n MaxFlow REAL,\r\n MinFlow REAL,\r\n MaxHead REAL,\r\n MinHead REAL,\r\n AnaStatus BIT\r\n);"; |
| | | |
| | | /// <summary> |
| | | /// è·åå
¨é¨è¡¨å |
| | | /// </summary> |
| | | public List<string> GetAllTableName() |
| | | { |
| | | var tables = new List<string>(); |
| | | using (var connection = new SQLiteConnection(ConfigHelper.ConnectionString)) |
| | | { |
| | | connection.Open(); |
| | | var sql = $"select name from sqlite_master where type='table' and name like '%{_tableNamePrefix}%';"; |
| | | using (var command = new SQLiteCommand(sql, connection)) |
| | | { |
| | | using (var reader = command.ExecuteReader()) |
| | | { |
| | | while (reader.Read()) |
| | | { |
| | | var tableName = reader["name"].ToString(); |
| | | tables.Add(tableName); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return tables; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// éè¿è¡¨åè·åæææªåæç»å |
| | | /// </summary> |
| | | public List<Entity.ScheduleCombine> GetAllUnanalyzedAnaByTableName(string tableName) |
| | | { |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var sql = $"select * from {tableName} where AnaStatus=False"; |
| | | var list = db.Ado.SqlQuery<Entity.ScheduleCombine>(sql); |
| | | return list; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public bool BulkInserts_SplitTable(List<Entity.ScheduleCombine> list) |
| | | { |
| | | if (list == null || list.Count < 1) |
| | | return default; |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | ///èªå·±æ¥å¶å®å®ä¹çè§å |
| | | db.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = new Entity.ScheduleCombineSubTableService(); |
| | | db.CodeFirst |
| | | .SplitTables()//æ è¯å表 |
| | | .InitTables<Entity.ScheduleCombine>(); //ç¨åºå¯å¨æ¶å è¿ä¸è¡,妿ä¸å¼ 表没æä¼åå§åä¸å¼ |
| | | |
| | | //å¤§æ°æ®åå
¥+表ä¸åå¨ä¼å»ºè¡¨ |
| | | //èªå¨æ¾è¡¨å¤§æ°æ®åå
¥ |
| | | return db.Fastest<Entity.ScheduleCombine>().SplitTable().BulkCopy(list) > 0; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public async Task<bool> BulkInserts_Create_Async(string runFlag, List<Entity.ScheduleCombine> list) |
| | | { |
| | | if (list == null || list.Count < 1) |
| | | return default; |
| | | var tableName = GetTableName(runFlag); |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var exist_sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}' ;"; |
| | | if (db.Ado.GetInt(exist_sql) < 1) |
| | | { |
| | | var sql_create_table = $"CREATE TABLE {tableName} {_createTable}"; |
| | | if (db.Ado.ExecuteCommand(sql_create_table) < 1) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | return await db.Fastest<Entity.ScheduleCombine>().AS(tableName).BulkCopyAsync(list) > 0; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public bool BulkInserts_Create(string runFlag, List<Entity.ScheduleCombine> list) |
| | | { |
| | | if (list == null || list.Count < 1) |
| | | return default; |
| | | var tableName = GetTableName(runFlag); |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var exist_sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; |
| | | if (db.Ado.ExecuteCommand(exist_sql) < 1) |
| | | { |
| | | var sql_create_table = $"CREATE TABLE {tableName} {_createTable}"; |
| | | db.Ado.ExecuteCommand(sql_create_table); |
| | | } |
| | | //å¤§æ°æ®åå
¥ |
| | | return db.Fastest<Entity.ScheduleCombine>().AS(tableName).BulkCopy(list) > 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public bool BulkInserts_NativeSql(string runFlag, List<Entity.ScheduleCombine> list) |
| | | { |
| | | var tableName = GetTableName(runFlag); |
| | | var connect = ConfigHelper.ConnectionString; |
| | | SQLiteConnection connection = new SQLiteConnection(connect);//è¿æ¥å¯¹è±¡åå§å |
| | | connection.Open();//æå¼è¿æ¥ |
| | | |
| | | SQLiteCommand command = new SQLiteCommand(connection);//å½ä»¤å¯¹è±¡åå§å |
| | | command.CommandText = $"VACUUM;";//æ§è¡VACUUMå½ä»¤æ¶ç¼©æ°æ®åº |
| | | command.ExecuteNonQuery(); |
| | | |
| | | SQLiteTransaction transaction = connection.BeginTransaction();//å¼å§äºå¡ |
| | | var sql_exist_table = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; |
| | | command.CommandText = sql_exist_table; |
| | | if (command.ExecuteNonQuery() < 1)//没æè¡¨å°±å建表 |
| | | { |
| | | var sql_create_table = $"CREATE TABLE {tableName} (\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n RunFlag VARCHAR (255),\r\n RunCount INTEGER,\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n CurveQH VARCHAR (255),\r\n CurveQP VARCHAR (255),\r\n AnaStatus BIT\r\n);"; |
| | | command.CommandText = sql_create_table; |
| | | command.ExecuteNonQuery(); |
| | | } |
| | | |
| | | var group = list.GroupBy(x => x.ID).Where(x => x.Count() > 1).Count(); |
| | | |
| | | for (int i = 0; i < list.Count; i++) //[---使ç¨äºå¡---]æ§è¡INSERTå½ä»¤ |
| | | { |
| | | var item = list[i]; |
| | | var sql_insert = $"INSERT INTO {tableName}(ID, RunFlag, RunCount, Pump1, Pump2, Pump3, CurveQH, CurveQP, AnaStatus) " + |
| | | $"VALUES ('{item.ID}','{item.RunFlag}','{item.RunCount}','{item.Pump1}','{item.Pump2}','{item.Pump3}','{item.CurveQH}','{item.CurveQP}','{item.AnaStatus}')"; |
| | | command.CommandText = sql_insert; |
| | | command.ExecuteNonQuery(); |
| | | } |
| | | // var result = command.ExecuteScalar(); |
| | | transaction.Commit();//æäº¤äºå¡ |
| | | connection.Close();//å
³éè¿æ¥ |
| | | return true; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 设置已åæç¶æ |
| | | /// </summary> |
| | | public bool SetAnaStatus(string tableName, long id) |
| | | { |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var sql = $"update {tableName} set AnaStatus=True where ID={id}"; |
| | | var bol = db.Ado.ExecuteCommand(sql) > 0; |
| | | return bol; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 设置已åæç¶æ |
| | | /// </summary> |
| | | public bool SetAnaStatus(string tableName, List<long> ids) |
| | | { |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var sql = $"update {tableName} set AnaStatus=True where ID in(@ids)"; |
| | | var obj = new { ids = ids.ToArray() }; |
| | | var bol = db.Ado.ExecuteCommand(sql, obj) > 0; |
| | | return bol; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// å¤ææ°æ®åºæ¯å¦åå¨è¡¨ |
| | | /// </summary> |
| | | public bool ExistTable(string runFlag) |
| | | { |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var sql = $"select count(*) from sqlite_master where type = 'table' and name = '{GetTableName(runFlag)}';"; |
| | | var bol = db.Ado.ExecuteCommand(sql) > 0; |
| | | return bol; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åå
¨é¨è¡¨å |
| | | /// </summary> |
| | | public bool DeleteAllTable() |
| | | { |
| | | var tables = GetAllTableName(); |
| | | if (tables == null || !tables.Any()) |
| | | return false; |
| | | |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | db.BeginTran(); |
| | | |
| | | foreach (var table in tables) |
| | | { |
| | | var sql = $"drop table {table};"; |
| | | db.Ado.ExecuteCommand(sql); |
| | | } |
| | | db.CommitTran(); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | |
| | | |
| | | #endregion |
| | | |
| | | #region BulkInserts |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public bool BulkInserts(string runFlag, List<Entity.ScheduleConclusion> list) |
| | | { |
| | | if (list == null || list.Count < 1) |
| | | return default; |
| | | var tableName = GetTableName(runFlag); |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | return db.Fastest<Entity.ScheduleConclusion>().AS(tableName).BulkCopy(list) > 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public async Task<bool> BulkInserts_Create_Async(string runFlag, List<Entity.ScheduleConclusion> list) |
| | | { |
| | | if (list == null || list.Count < 1) |
| | | return default; |
| | | var tableName = GetTableName(runFlag); |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var exist_sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}' ;"; |
| | | if (db.Ado.GetInt(exist_sql) < 1) |
| | | { |
| | | var sql_create_table = $"CREATE TABLE {tableName} (\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n ScheduleCombineID BIGINT,\r\n RunFlag VARCHAR (255),\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n Head REAL,\r\n Flow REAL,\r\n Power REAL,\r\n WP REAL,\r\n UWP REAL\r\n);"; |
| | | if (db.Ado.ExecuteCommand(sql_create_table) < 1) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | return await db.Fastest<Entity.ScheduleConclusion>().AS(tableName).BulkCopyAsync(list) > 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public bool BulkInserts_SplitTable(List<Entity.ScheduleConclusion> list) |
| | | { |
| | | if (list == null || list.Count < 1) |
| | | return default; |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | ///èªå·±æ¥å¶å®å®ä¹çè§å |
| | | db.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = new Entity.ScheduleConclusionSubTableService(); |
| | | db.CodeFirst |
| | | .SplitTables()//æ è¯å表 |
| | | .InitTables<Entity.ScheduleConclusion>(); //ç¨åºå¯å¨æ¶å è¿ä¸è¡,妿ä¸å¼ 表没æä¼åå§åä¸å¼ |
| | | |
| | | //å¤§æ°æ®åå
¥+表ä¸åå¨ä¼å»ºè¡¨ |
| | | //èªå¨æ¾è¡¨å¤§æ°æ®åå
¥ |
| | | return db.Fastest<Entity.ScheduleConclusion>().SplitTable().BulkCopy(list) > 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public bool BulkInserts_NativeSql(string runFlag, List<Entity.ScheduleConclusion> list) |
| | | { |
| | | var tableName = GetTableName(runFlag); |
| | | var connect = ConfigHelper.ConnectionString; |
| | | SQLiteConnection connection = new SQLiteConnection(connect);//è¿æ¥å¯¹è±¡åå§å |
| | | connection.Open();//æå¼è¿æ¥ |
| | | |
| | | SQLiteCommand command = new SQLiteCommand(connection);//å½ä»¤å¯¹è±¡åå§å |
| | | command.CommandText = $"VACUUM;";//æ§è¡VACUUMå½ä»¤æ¶ç¼©æ°æ®åº |
| | | command.ExecuteNonQuery(); |
| | | |
| | | SQLiteTransaction transaction = connection.BeginTransaction();//å¼å§äºå¡ |
| | | |
| | | var sql_exist_table = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; |
| | | command.CommandText = sql_exist_table; |
| | | if (command.ExecuteNonQuery() < 1)//没æè¡¨å°±å建表 |
| | | { |
| | | var sql_create_table = $"CREATE TABLE {tableName} (\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n ScheduleCombineID BIGINT,\r\n RunFlag VARCHAR (255),\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n Head REAL,\r\n Flow REAL,\r\n Power REAL,\r\n WP REAL,\r\n UWP REAL\r\n);\r\n"; |
| | | command.CommandText = sql_create_table; |
| | | command.ExecuteNonQuery(); |
| | | } |
| | | |
| | | for (int i = 0; i < list.Count; i++) //[---使ç¨äºå¡---]æ§è¡INSERTå½ä»¤ |
| | | { |
| | | var sql_insert = $"INSERT INTO {tableName}(ID, ScheduleCombineID, RunFlag, Pump1, Pump2, Pump3, Head, Flow, Power, WP, UWP) " + |
| | | $"VALUES ('{list[i].ID}','{list[i].ScheduleCombineID}','{list[i].RunFlag}','{list[i].Pump1}','{list[i].Pump2}','{list[i].Pump3}','{list[i].Head}','{list[i].Flow}','{list[i].Power}','{list[i].WP}','{list[i].UWP}')"; |
| | | command.CommandText = sql_insert; |
| | | command.ExecuteNonQuery(); |
| | | } |
| | | command.ExecuteScalar(); |
| | | transaction.Commit();//æäº¤äºå¡ |
| | | connection.Close();//å
³éè¿æ¥ |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢ |
| | |
| | | var list = db.Queryable<Entity.ScheduleConclusion>().AS(tableName) |
| | | .Where(x => x.Head == targetHead) |
| | | .OrderBy(x => x.Power) |
| | | .ToList(); |
| | | return list; |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢ |
| | | /// </summary> |
| | | public List<Entity.ScheduleConclusion> GetList(string runFlag, double targetFlow, double targetHead, int takeCount) |
| | | { |
| | | var tableName = GetTableName(runFlag); |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; |
| | | if (db.Ado.GetInt(sql) < 1) |
| | | { |
| | | return default; |
| | | } |
| | | var list = db.Queryable<Entity.ScheduleConclusion>().AS(tableName) |
| | | .Where(x => x.Head >= targetHead && x.Head <= targetHead * 1.01 && x.Flow > targetFlow) |
| | | .OrderBy(x => x.Power) |
| | | .Take(takeCount) |
| | | .ToList(); |
| | | return list; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace IStation.DAL |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public class ScheduleConclusion_bak |
| | | { |
| | | public SqlSugarClient Connection |
| | | { |
| | | get { return ConfigHelper.GetSqlSugarClient(); } |
| | | } |
| | | |
| | | private readonly string _tableNamePrefix = "ScheduleConclusion_Cl_"; |
| | | |
| | | private string GetTableName(string runFlag) |
| | | { |
| | | return $"{_tableNamePrefix}{runFlag}"; |
| | | } |
| | | |
| | | #region Table |
| | | |
| | | /// <summary> |
| | | /// è·åå
¨é¨è¡¨å |
| | | /// </summary> |
| | | public List<string> GetAllTableName() |
| | | { |
| | | var tables = new List<string>(); |
| | | using (var connection = new SQLiteConnection(ConfigHelper.ConnectionString)) |
| | | { |
| | | connection.Open(); |
| | | var sql = $"select name from sqlite_master where type='table' and name like '%{_tableNamePrefix}%';"; |
| | | using (var command = new SQLiteCommand(sql, connection)) |
| | | { |
| | | using (var reader = command.ExecuteReader()) |
| | | { |
| | | while (reader.Read()) |
| | | { |
| | | var tableName = reader["name"].ToString(); |
| | | tables.Add(tableName); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return tables; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤ææ°æ®åºæ¯å¦åå¨è¡¨ |
| | | /// </summary> |
| | | public bool ExistTable(string runFlag) |
| | | { |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var sql = $"select count(*) from sqlite_master where type = 'table' and name = '{GetTableName(runFlag)}';"; |
| | | var bol = db.Ado.GetInt(sql) > 0; |
| | | return bol; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ°æ®åºå建表 |
| | | /// </summary> |
| | | public bool CreateTable(string runFlag) |
| | | { |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var tableName = GetTableName(runFlag); |
| | | var sql_exist = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; |
| | | if (db.Ado.GetInt(sql_exist) > 0) |
| | | return true; |
| | | var sql_create_table = $"CREATE TABLE {tableName} (\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n ScheduleCombineID BIGINT,\r\n RunFlag VARCHAR (255),\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n Head REAL,\r\n Flow REAL,\r\n Power REAL,\r\n WP REAL,\r\n UWP REAL\r\n);"; |
| | | var bol = db.Ado.ExecuteCommand(sql_create_table) > 0; |
| | | return bol; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | // å 餿æè¡¨ |
| | | /// </summary> |
| | | public bool DeleteAllTable() |
| | | { |
| | | var tables = GetAllTableName(); |
| | | if (tables == null || !tables.Any()) |
| | | return false; |
| | | |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | db.BeginTran(); |
| | | |
| | | foreach (var table in tables) |
| | | { |
| | | var sql = $"drop table {table};"; |
| | | db.Ado.ExecuteCommand(sql); |
| | | } |
| | | db.CommitTran(); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region BulkInserts |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public bool BulkInserts(string runFlag, List<Entity.ScheduleConclusion> list) |
| | | { |
| | | if (list == null || list.Count < 1) |
| | | return default; |
| | | var tableName = GetTableName(runFlag); |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | return db.Fastest<Entity.ScheduleConclusion>().AS(tableName).BulkCopy(list) > 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public async Task<bool> BulkInserts_Create_Async(string runFlag, List<Entity.ScheduleConclusion> list) |
| | | { |
| | | if (list == null || list.Count < 1) |
| | | return default; |
| | | var tableName = GetTableName(runFlag); |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var exist_sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}' ;"; |
| | | if (db.Ado.GetInt(exist_sql) < 1) |
| | | { |
| | | var sql_create_table = $"CREATE TABLE {tableName} (\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n ScheduleCombineID BIGINT,\r\n RunFlag VARCHAR (255),\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n Head REAL,\r\n Flow REAL,\r\n Power REAL,\r\n WP REAL,\r\n UWP REAL\r\n);"; |
| | | if (db.Ado.ExecuteCommand(sql_create_table) < 1) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | return await db.Fastest<Entity.ScheduleConclusion>().AS(tableName).BulkCopyAsync(list) > 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public bool BulkInserts_SplitTable(List<Entity.ScheduleConclusion> list) |
| | | { |
| | | if (list == null || list.Count < 1) |
| | | return default; |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | ///èªå·±æ¥å¶å®å®ä¹çè§å |
| | | db.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = new Entity.ScheduleConclusionSubTableService(); |
| | | db.CodeFirst |
| | | .SplitTables()//æ è¯å表 |
| | | .InitTables<Entity.ScheduleConclusion>(); //ç¨åºå¯å¨æ¶å è¿ä¸è¡,妿ä¸å¼ 表没æä¼åå§åä¸å¼ |
| | | |
| | | //å¤§æ°æ®åå
¥+表ä¸åå¨ä¼å»ºè¡¨ |
| | | //èªå¨æ¾è¡¨å¤§æ°æ®åå
¥ |
| | | return db.Fastest<Entity.ScheduleConclusion>().SplitTable().BulkCopy(list) > 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public bool BulkInserts_Create(string runFlag, List<Entity.ScheduleConclusion> list) |
| | | { |
| | | if (list == null || list.Count < 1) |
| | | return default; |
| | | var tableName = GetTableName(runFlag); |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var exist_sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}' ;"; |
| | | if (db.Ado.GetInt(exist_sql) < 1) |
| | | { |
| | | var sql_create_table = $"CREATE TABLE {tableName} (\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n ScheduleCombineID BIGINT,\r\n RunFlag VARCHAR (255),\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n Head REAL,\r\n Flow REAL,\r\n Power REAL,\r\n WP REAL,\r\n UWP REAL\r\n);"; |
| | | db.Ado.ExecuteCommand(sql_create_table); |
| | | } |
| | | //å¤§æ°æ®åå
¥ |
| | | return db.Fastest<Entity.ScheduleConclusion>().AS(tableName).BulkCopy(list) > 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 大æ¹éæå
¥ |
| | | /// </summary> |
| | | public bool BulkInserts_NativeSql(string runFlag, List<Entity.ScheduleConclusion> list) |
| | | { |
| | | var tableName = GetTableName(runFlag); |
| | | var connect = ConfigHelper.ConnectionString; |
| | | SQLiteConnection connection = new SQLiteConnection(connect);//è¿æ¥å¯¹è±¡åå§å |
| | | connection.Open();//æå¼è¿æ¥ |
| | | |
| | | SQLiteCommand command = new SQLiteCommand(connection);//å½ä»¤å¯¹è±¡åå§å |
| | | command.CommandText = $"VACUUM;";//æ§è¡VACUUMå½ä»¤æ¶ç¼©æ°æ®åº |
| | | command.ExecuteNonQuery(); |
| | | |
| | | SQLiteTransaction transaction = connection.BeginTransaction();//å¼å§äºå¡ |
| | | |
| | | var sql_exist_table = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; |
| | | command.CommandText = sql_exist_table; |
| | | if (command.ExecuteNonQuery() < 1)//没æè¡¨å°±å建表 |
| | | { |
| | | var sql_create_table = $"CREATE TABLE {tableName} (\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n ScheduleCombineID BIGINT,\r\n RunFlag VARCHAR (255),\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n Head REAL,\r\n Flow REAL,\r\n Power REAL,\r\n WP REAL,\r\n UWP REAL\r\n);\r\n"; |
| | | command.CommandText = sql_create_table; |
| | | command.ExecuteNonQuery(); |
| | | } |
| | | |
| | | for (int i = 0; i < list.Count; i++) //[---使ç¨äºå¡---]æ§è¡INSERTå½ä»¤ |
| | | { |
| | | var sql_insert = $"INSERT INTO {tableName}(ID, ScheduleCombineID, RunFlag, Pump1, Pump2, Pump3, Head, Flow, Power, WP, UWP) " + |
| | | $"VALUES ('{list[i].ID}','{list[i].ScheduleCombineID}','{list[i].RunFlag}','{list[i].Pump1}','{list[i].Pump2}','{list[i].Pump3}','{list[i].Head}','{list[i].Flow}','{list[i].Power}','{list[i].WP}','{list[i].UWP}')"; |
| | | command.CommandText = sql_insert; |
| | | command.ExecuteNonQuery(); |
| | | } |
| | | command.ExecuteScalar(); |
| | | transaction.Commit();//æäº¤äºå¡ |
| | | connection.Close();//å
³éè¿æ¥ |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢ |
| | | /// </summary> |
| | | public List<Entity.ScheduleConclusion> GetList(string runFlag, double targetHead) |
| | | { |
| | | var tableName = GetTableName(runFlag); |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; |
| | | if (db.Ado.GetInt(sql) < 1) |
| | | { |
| | | return default; |
| | | } |
| | | var list = db.Queryable<Entity.ScheduleConclusion>().AS(tableName) |
| | | .Where(x => x.Head == targetHead) |
| | | .OrderBy(x => x.Power) |
| | | .ToList(); |
| | | return list; |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢ |
| | | /// </summary> |
| | | public List<Entity.ScheduleConclusion> GetList(string runFlag, double targetFlow, double targetHead, int takeCount) |
| | | { |
| | | var tableName = GetTableName(runFlag); |
| | | using (SqlSugarClient db = Connection) |
| | | { |
| | | var sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; |
| | | if (db.Ado.GetInt(sql) < 1) |
| | | { |
| | | return default; |
| | | } |
| | | var list = db.Queryable<Entity.ScheduleConclusion>().AS(tableName) |
| | | .Where(x => x.Head >= targetHead && x.Head <= targetHead * 1.01 && x.Flow > targetFlow) |
| | | .OrderBy(x => x.Power) |
| | | .Take(takeCount) |
| | | .ToList(); |
| | | return list; |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | |
| | | { |
| | | /// <summary> |
| | | /// è°åº¦ç»å |
| | | /// </summary> |
| | | [SplitTable(SplitType._Custom01)] |
| | | /// </summary> |
| | | public class ScheduleCombine |
| | | { |
| | | public ScheduleCombine() |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace IStation |
| | | { |
| | | public static class ListExpand |
| | | { |
| | | /// <summary> |
| | | /// å¤æä¸¤ä¸ªé忝妿¯ç¸çç(ææçå
ç´ åæ°éé½ç¸ç) |
| | | /// </summary> |
| | | /// <typeparam name="T">éåå
ç´ ç±»å</typeparam> |
| | | /// <param name="sourceCollection">æºéåå表</param> |
| | | /// <param name="targetCollection">ç®æ éåå表</param> |
| | | /// <returns>两个éåç¸çåè¿åTrue,å¦åè¿åFalse</returns> |
| | | public static bool EqualList<T>(this IList<T> sourceCollection, IList<T> targetCollection) where T : IEquatable<T> |
| | | { |
| | | //空éåç´æ¥è¿åFalse,å³ä½¿æ¯ä¸¤ä¸ªé½æ¯ç©ºéå,ä¹è¿åFalse |
| | | if (sourceCollection == null || targetCollection == null) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if (object.ReferenceEquals(sourceCollection, targetCollection)) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | if (sourceCollection.Count != targetCollection.Count) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | var sourceCollectionStaticsDict = sourceCollection.StatisticRepetition(); |
| | | var targetCollectionStaticsDict = targetCollection.StatisticRepetition(); |
| | | |
| | | return sourceCollectionStaticsDict.EqualDictionary(targetCollectionStaticsDict); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤æä¸¤ä¸ªåå
¸æ¯å¦æ¯ç¸çç(ææçåå
¸é¡¹å¯¹åºçå¼é½ç¸ç) |
| | | /// </summary> |
| | | /// <typeparam name="TKey">åå
¸é¡¹ç±»å</typeparam> |
| | | /// <typeparam name="TValue">åå
¸å¼ç±»å</typeparam> |
| | | /// <param name="sourceDictionary">æºåå
¸</param> |
| | | /// <param name="targetDictionary">ç®æ åå
¸</param> |
| | | /// <returns>两个åå
¸ç¸çåè¿åTrue,å¦åè¿åFalse</returns> |
| | | public static bool EqualDictionary<TKey, TValue>(this Dictionary<TKey, TValue> sourceDictionary, Dictionary<TKey, TValue> targetDictionary) |
| | | where TKey : IEquatable<TKey> |
| | | where TValue : IEquatable<TValue> |
| | | { |
| | | //空åå
¸ç´æ¥è¿åFalse,å³ä½¿æ¯ä¸¤ä¸ªé½æ¯ç©ºåå
¸,ä¹è¿åFalse |
| | | if (sourceDictionary == null || targetDictionary == null) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if (object.ReferenceEquals(sourceDictionary, targetDictionary)) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | if (sourceDictionary.Count != targetDictionary.Count) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | //æ¯è¾ä¸¤ä¸ªåå
¸çKeyä¸Value |
| | | foreach (KeyValuePair<TKey, TValue> item in sourceDictionary) |
| | | { |
| | | //å¦æç®æ åå
¸ä¸å
嫿ºåå
¸ä»»æä¸é¡¹,åä¸ç¸ç |
| | | if (!targetDictionary.ContainsKey(item.Key)) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | //妿åä¸ä¸ªåå
¸é¡¹çå¼ä¸ç¸ç,åä¸ç¸ç |
| | | if (!targetDictionary[item.Key].Equals(item.Value)) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç»è®¡éåçéå¤é¡¹,å¹¶è¿åä¸ä¸ªåå
¸ |
| | | /// </summary> |
| | | /// <typeparam name="T">éåå
ç´ ç±»å</typeparam> |
| | | /// <param name="sourceCollection">ç»è®¡éåå表</param> |
| | | /// <returns>è¿åä¸ä¸ªéåå
ç´ åé夿°éçåå
¸</returns> |
| | | private static Dictionary<T, int> StatisticRepetition<T>(this IEnumerable<T> sourceCollection) where T : IEquatable<T> |
| | | { |
| | | var collectionStaticsDict = new Dictionary<T, int>(); |
| | | foreach (var item in sourceCollection) |
| | | { |
| | | if (collectionStaticsDict.ContainsKey(item)) |
| | | { |
| | | collectionStaticsDict[item]++; |
| | | } |
| | | else |
| | | { |
| | | collectionStaticsDict.Add(item, 1); |
| | | } |
| | | } |
| | | |
| | | return collectionStaticsDict; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace IStation |
| | | { |
| | | /// <summary> |
| | | /// å符å表è¾
å©ç±» |
| | | /// </summary> |
| | | public class StringListHelper |
| | | { |
| | | //åå²å符 |
| | | private const string _split = ","; |
| | | |
| | | /// <summary> |
| | | /// 转å为å符串 |
| | | /// </summary> |
| | | public static string ToString(IEnumerable<string> list) |
| | | { |
| | | if (list == null || list.Count() < 1) |
| | | return string.Empty; |
| | | return string.Join(_split, list); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 转å为å表 |
| | | /// </summary> |
| | | /// <param name="str"></param> |
| | | /// <returns></returns> |
| | | public static List<string> ToList(string str) |
| | | { |
| | | if (string.IsNullOrEmpty(str)) |
| | | return new List<string>(); |
| | | try |
| | | { |
| | | var list = str.Split(new string[] { _split }, StringSplitOptions.RemoveEmptyEntries); |
| | | if (list.Count() < 1) |
| | | return new List<string>(); |
| | | return list.Select(x => x).ToList(); |
| | | } |
| | | catch |
| | | { |
| | | return new List<string>(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | |
| | | <Compile Remove="Schedule\SchedulingHelper - å¤å¶%283%29.cs" /> |
| | | <Compile Remove="Schedule\SchedulingHelper - å¤å¶%284%29.cs" /> |
| | | <Compile Remove="Schedule\SchedulingHelper - å¤å¶%285%29.cs" /> |
| | | <Compile Remove="Schedule\SchedulingHelper - å¤å¶%286%29.cs" /> |
| | | <Compile Remove="Schedule\SchedulingHelper - å¤å¶%287%29.cs" /> |
| | | <Compile Remove="Schedule\SchedulingHelper - å¤å¶.cs" /> |
| | | </ItemGroup> |
| | | |
| | |
| | | |
| | | string runFlag; |
| | | List<AnaPumpFreItem> pump1, pump2, pump3; |
| | | var maxPumpCount = 2; |
| | | var maxPumpCount = 1; |
| | | var anaPumpItemsArray = anaPumpItems.ToArray(); |
| | | var parallelHelper = new ParallelConnectionHelper(); |
| | | for (int pumpCount = 1; pumpCount <= maxPumpCount; pumpCount++) |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace IStation.Algorithm |
| | | { |
| | | |
| | | #region ViewModel |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public class FreCombine |
| | | { |
| | | public FreCombine() { } |
| | | public List<int> Flags { get; set; } |
| | | public int RunCount { get; set; } |
| | | public double Frequency { get; set; } |
| | | public double Flow { get; set; } |
| | | public double Power { get; set; } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// åææ³µé¡¹ |
| | | /// </summary> |
| | | public class OptimalCombine |
| | | { |
| | | public OptimalCombine() { } |
| | | public List<int> Flags { get; set; } |
| | | public double Flow { get; set; } |
| | | public double Head { get; set; } |
| | | public double Power { get; set; } |
| | | public List<FreCombine> Combines { get; set; } |
| | | public string Remark { get; set; } |
| | | public double Scale { get; set; } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// è°åº¦åæè¾
å©ç±» |
| | | /// </summary> |
| | | public class SchedulingHelper |
| | | { |
| | | double _frequency_def = 50; |
| | | decimal _frequency_min = 25; |
| | | decimal _frequency_max = 50; |
| | | decimal _frequency_space = 0.1m;//é¢çé´é |
| | | |
| | | double _head_space = 0.1;//æ¬ç¨é´é |
| | | |
| | | #region RunFlag |
| | | string _falgFrePumpTag = "B"; |
| | | string _falgFixPumpTag = "G"; |
| | | string _falgSpaceMark = "_"; |
| | | |
| | | |
| | | string GetRunFlag(int[] flags) |
| | | { |
| | | var runFlag = string.Empty; |
| | | var index = 0; |
| | | var count = flags.Length; |
| | | foreach (var flag in flags) |
| | | { |
| | | runFlag += GetGFlag(flag); |
| | | index++; |
| | | if (index != count) |
| | | { |
| | | runFlag += _falgSpaceMark; |
| | | } |
| | | } |
| | | return runFlag; |
| | | } |
| | | |
| | | string GetRunFlag(List<int> flags) |
| | | { |
| | | var runFlag = string.Empty; |
| | | var index = 0; |
| | | var count = flags.Count; |
| | | foreach (var flag in flags) |
| | | { |
| | | runFlag += GetGFlag(flag); |
| | | index++; |
| | | if (index != count) |
| | | { |
| | | runFlag += _falgSpaceMark; |
| | | } |
| | | } |
| | | return runFlag; |
| | | } |
| | | |
| | | string GetGFlag(int flag) |
| | | { |
| | | return _falgFrePumpTag + flag; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | DAL.ScheduleCombine _dal = new DAL.ScheduleCombine(); |
| | | DAL.ScheduleConclusion _dalScheduleConclusion = new DAL.ScheduleConclusion(); |
| | | DAL.ScheduleAnaLog _dalAnaLog = new DAL.ScheduleAnaLog(); |
| | | |
| | | |
| | | private List<int> _combineFlags1 = new List<int>() { 11, 12, 13, 14, 16, 17, 18 }; |
| | | private List<int> _combineFlags2 = new List<int>() { 15 }; |
| | | |
| | | public string Ana(List<Pump> pumps, double taget_flow, double taget_head, List<int> must_open_pump_flags, List<int> must_not_open_pump_flags) |
| | | { |
| | | taget_flow = Math.Round(taget_head, 1); |
| | | taget_head = Math.Round(taget_head, 1); |
| | | |
| | | #region å¿
弿³µå表 |
| | | var must_open_pump_flags_remark = string.Empty; |
| | | var exist_must_open_pump_flags = must_open_pump_flags != null && must_open_pump_flags.Count > 0; |
| | | if (exist_must_open_pump_flags) |
| | | { |
| | | must_open_pump_flags = must_open_pump_flags.OrderBy(x => x).ToList(); |
| | | must_open_pump_flags_remark = IntListHelper.ToString(must_open_pump_flags); |
| | | } |
| | | #endregion |
| | | |
| | | #region å¿
ä¸è½å¼æ³µå表 |
| | | |
| | | var exist_must_not_open_pump_flags = must_not_open_pump_flags != null && must_not_open_pump_flags.Count > 0; |
| | | |
| | | #endregion |
| | | |
| | | var pump_flag_list = pumps.Select(x => x.ID).ToList(); |
| | | var optimal_combine_list = new List<OptimalCombine>(); |
| | | for (int pumpCount = 1; pumpCount <= pumps.Count; pumpCount++) |
| | | { |
| | | var combine_list = PermutationAndCombination<int>.GetCombination(pump_flag_list.ToArray(), pumpCount); |
| | | foreach (var combine in combine_list) |
| | | { |
| | | List<int> combine_flag_list_part1 = new List<int>(); |
| | | List<int> combine_flag_list_part2 = new List<int>(); |
| | | |
| | | foreach (var pump in combine) |
| | | { |
| | | if (_combineFlags1.Contains(pump)) |
| | | { |
| | | combine_flag_list_part1.Add(pump); |
| | | } |
| | | else |
| | | { |
| | | combine_flag_list_part2.Add(pump); |
| | | } |
| | | } |
| | | |
| | | List<FreCombine> fre_combine_list_part1 = new List<FreCombine>(); |
| | | List<FreCombine> fre_combine_list_part2 = new List<FreCombine>(); |
| | | |
| | | if (combine_flag_list_part1.Count > 0) |
| | | { |
| | | var conclusion_list_dic = new Dictionary<int, List<Entity.ScheduleConclusion>>(); |
| | | foreach (var flag in combine_flag_list_part1) |
| | | { |
| | | var runFlag = GetGFlag(flag); |
| | | if (conclusion_list_dic.ContainsKey(flag)) |
| | | continue; |
| | | var conclusionList = _dalScheduleConclusion.GetList(runFlag, taget_head); |
| | | conclusion_list_dic[flag] = conclusionList; |
| | | } |
| | | |
| | | if (conclusion_list_dic.Count < 1) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | for (decimal fre = _frequency_max; fre >= _frequency_min; fre -= _frequency_space) |
| | | { |
| | | var freCombine = new FreCombine(); |
| | | freCombine.Frequency = (double)fre; |
| | | freCombine.Flags = new List<int>(); |
| | | foreach (var item in conclusion_list_dic) |
| | | { |
| | | var conclusion = item.Value.Find(x => x.Pump1 == (double)fre); |
| | | if (conclusion != null) |
| | | { |
| | | freCombine.Flags.Add(item.Key); |
| | | freCombine.Flow += conclusion.Flow; |
| | | freCombine.Power += conclusion.Power; |
| | | freCombine.RunCount++; |
| | | } |
| | | } |
| | | if (freCombine.Flags.Count < 1) |
| | | continue; |
| | | fre_combine_list_part1.Add(freCombine); |
| | | } |
| | | } |
| | | if (combine_flag_list_part2.Count > 0) |
| | | { |
| | | var conclusion_list_dic = new Dictionary<int, List<Entity.ScheduleConclusion>>(); |
| | | foreach (var flag in combine_flag_list_part2) |
| | | { |
| | | var runFlag = GetGFlag(flag); |
| | | if (conclusion_list_dic.ContainsKey(flag)) |
| | | continue; |
| | | var conclusionList = _dalScheduleConclusion.GetList(runFlag, taget_head); |
| | | conclusion_list_dic[flag] = conclusionList; |
| | | } |
| | | |
| | | if (conclusion_list_dic.Count < 1) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | for (decimal fre = _frequency_max; fre >= _frequency_min; fre -= _frequency_space) |
| | | { |
| | | var freCombine = new FreCombine(); |
| | | freCombine.Frequency = (double)fre; |
| | | freCombine.Flags = new List<int>(); |
| | | foreach (var item in conclusion_list_dic) |
| | | { |
| | | var conclusion = item.Value.Find(x => x.Pump1 == (double)fre); |
| | | if (conclusion != null) |
| | | { |
| | | freCombine.Flags.Add(item.Key); |
| | | freCombine.Flow += conclusion.Flow; |
| | | freCombine.Power += conclusion.Power; |
| | | freCombine.RunCount++; |
| | | } |
| | | } |
| | | if (freCombine.Flags.Count < 1) |
| | | continue; |
| | | fre_combine_list_part2.Add(freCombine); |
| | | } |
| | | } |
| | | |
| | | if (fre_combine_list_part1.Count == 0 && fre_combine_list_part2.Count == 0) |
| | | continue; |
| | | |
| | | var optimal_combine = AnaOptimalCombine(taget_flow, fre_combine_list_part1, fre_combine_list_part2, must_open_pump_flags, must_not_open_pump_flags); |
| | | if (optimal_combine == null) |
| | | continue; |
| | | if (exist_must_open_pump_flags) |
| | | { |
| | | if (!optimal_combine.Remark.Contains(must_open_pump_flags_remark)) |
| | | { |
| | | optimal_combine.Scale *= 0.8; |
| | | } |
| | | else |
| | | { |
| | | if (optimal_combine.Flags.Count == must_open_pump_flags.Count) |
| | | { |
| | | optimal_combine.Scale *= 1.1; |
| | | } |
| | | } |
| | | } |
| | | optimal_combine.Head = taget_head; |
| | | optimal_combine_list.Add(optimal_combine); |
| | | } |
| | | } |
| | | |
| | | if (optimal_combine_list.Count < 1) |
| | | return "æ æ¹æ¡"; |
| | | |
| | | var sb = new StringBuilder(); |
| | | optimal_combine_list = optimal_combine_list.OrderByDescending(x => x.Scale).ToList(); |
| | | foreach (var opt in optimal_combine_list) |
| | | { |
| | | sb.AppendLine($"Scale:{opt.Scale},Flow:{opt.Flow.ToString("N1")},Power:{opt.Power.ToString("N1")}," + |
| | | $"Flags:{opt.Remark};FlowDeviation:{(opt.Flow - taget_flow).ToString("N1")}"); |
| | | } |
| | | return sb.ToString(); |
| | | |
| | | } |
| | | |
| | | |
| | | private OptimalCombine AnaOptimalCombine(double target_flow, List<FreCombine> fre_combine_list_part1, List<FreCombine> fre_combine_list_part2, List<int> must_open_pump_flags, List<int> must_not_open_pump_flags) |
| | | { |
| | | double flow_deviation = target_flow; |
| | | double total_power = double.MaxValue; |
| | | double total_flow = double.MaxValue; |
| | | |
| | | FreCombine optimal_combine_part1 = null; |
| | | FreCombine optimal_combine_part2 = null; |
| | | if (fre_combine_list_part1.Count < 1 || fre_combine_list_part2.Count < 1) |
| | | { |
| | | for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++) |
| | | { |
| | | var fre_combine1 = fre_combine_list_part1[Index_part1]; |
| | | |
| | | var current_flow = fre_combine1.Flow; |
| | | var current_power = fre_combine1.Power; |
| | | |
| | | var diff_flow = Math.Abs(current_flow - target_flow); |
| | | if (diff_flow < flow_deviation) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | total_power = fre_combine1.Power; |
| | | total_flow = current_flow; |
| | | flow_deviation = diff_flow; |
| | | } |
| | | |
| | | if (diff_flow < target_flow * 0.01 && current_power < total_power) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | total_power = fre_combine1.Power; |
| | | total_flow = current_flow; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++) |
| | | { |
| | | for (int Index_part2 = 0; Index_part2 < fre_combine_list_part2.Count; Index_part2++) |
| | | { |
| | | var fre_combine1 = fre_combine_list_part1[Index_part1]; |
| | | var fre_combine2 = fre_combine_list_part2[Index_part2]; |
| | | |
| | | var current_flow = fre_combine1.Flow + fre_combine2.Flow; |
| | | var current_power = fre_combine1.Power + fre_combine2.Power; |
| | | |
| | | var diff_flow = Math.Abs(current_flow - target_flow); |
| | | if (diff_flow < flow_deviation) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | optimal_combine_part2 = fre_combine2; |
| | | total_power = fre_combine1.Power + fre_combine2.Power; |
| | | total_flow = current_flow; |
| | | flow_deviation = diff_flow; |
| | | } |
| | | |
| | | if (diff_flow < target_flow * 0.01 && current_power < total_power) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | optimal_combine_part2 = fre_combine2; |
| | | total_power = fre_combine1.Power + fre_combine2.Power; |
| | | total_flow = current_flow; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (optimal_combine_part1 == null && optimal_combine_part2 == null) |
| | | return default; |
| | | |
| | | var optimal_combine = new OptimalCombine(); |
| | | optimal_combine.Combines = new List<FreCombine>(); |
| | | optimal_combine.Flags = new List<int>(); |
| | | if (optimal_combine_part1 != null) |
| | | { |
| | | optimal_combine.Combines.Add(optimal_combine_part1); |
| | | optimal_combine.Flags.AddRange(optimal_combine_part1.Flags); |
| | | } |
| | | if (optimal_combine_part2 != null) |
| | | { |
| | | optimal_combine.Combines.Add(optimal_combine_part2); |
| | | optimal_combine.Flags.AddRange(optimal_combine_part2.Flags); |
| | | } |
| | | |
| | | optimal_combine.Flow = total_flow; |
| | | optimal_combine.Power = total_power; |
| | | optimal_combine.Flags = optimal_combine.Flags.OrderBy(x => x).ToList(); |
| | | optimal_combine.Remark = IntListHelper.ToString(optimal_combine.Flags); |
| | | optimal_combine.Scale = 1 * Math.Abs((total_flow / target_flow)); |
| | | return optimal_combine; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå
¥åææ¥å¿ |
| | | /// </summary> |
| | | private void InsertAnaLog(string info) |
| | | { |
| | | var entity = new Entity.ScheduleAnaLog(info); |
| | | _dalAnaLog.Insert(entity); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// å¤æè¡¨æ¯å¦åå¨ |
| | | /// </summary> |
| | | public bool ExistTable(string runFlag) |
| | | { |
| | | return _dal.ExistTable(runFlag); |
| | | } |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace IStation.Algorithm |
| | | { |
| | | |
| | | #region ViewModel |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public class FreCombine |
| | | { |
| | | public FreCombine() { } |
| | | public List<int> Flags { get; set; } |
| | | public int RunCount { get; set; } |
| | | public double Frequency { get; set; } |
| | | public double Flow { get; set; } |
| | | public double Power { get; set; } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// åææ³µé¡¹ |
| | | /// </summary> |
| | | public class OptimalCombine |
| | | { |
| | | public OptimalCombine() { } |
| | | public double Flow { get; set; } |
| | | public double Head { get; set; } |
| | | public double Power { get; set; } |
| | | public List<FreCombine> Combines { get; set; } |
| | | public List<int> Flags { get; set; } |
| | | public int FlagCount { get; set; } |
| | | public string Remark { get; set; } |
| | | public double Scale { get; set; } |
| | | public double OpenPumpRatio { get; set; } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// è°åº¦åæè¾
å©ç±» |
| | | /// </summary> |
| | | public class SchedulingHelper |
| | | { |
| | | decimal _frequency_min = 25; |
| | | decimal _frequency_max = 50; |
| | | decimal _frequency_space = 0.1m;//é¢çé´é |
| | | |
| | | double _start_stop_loss_coefficient = 0.95;//æ³µå¯åæå¤±ç³»æ° |
| | | |
| | | |
| | | #region RunFlag |
| | | string _falgFrePumpTag = "B"; |
| | | string _falgFixPumpTag = "G"; |
| | | string _falgSpaceMark = "_"; |
| | | |
| | | |
| | | string GetRunFlag(int[] flags) |
| | | { |
| | | var runFlag = string.Empty; |
| | | var index = 0; |
| | | var count = flags.Length; |
| | | foreach (var flag in flags) |
| | | { |
| | | runFlag += GetGFlag(flag); |
| | | index++; |
| | | if (index != count) |
| | | { |
| | | runFlag += _falgSpaceMark; |
| | | } |
| | | } |
| | | return runFlag; |
| | | } |
| | | |
| | | string GetRunFlag(List<int> flags) |
| | | { |
| | | var runFlag = string.Empty; |
| | | var index = 0; |
| | | var count = flags.Count; |
| | | foreach (var flag in flags) |
| | | { |
| | | runFlag += GetGFlag(flag); |
| | | index++; |
| | | if (index != count) |
| | | { |
| | | runFlag += _falgSpaceMark; |
| | | } |
| | | } |
| | | return runFlag; |
| | | } |
| | | |
| | | string GetGFlag(int flag) |
| | | { |
| | | return _falgFrePumpTag + flag; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | DAL.ScheduleCombine _dal = new DAL.ScheduleCombine(); |
| | | DAL.ScheduleConclusion _dalScheduleConclusion = new DAL.ScheduleConclusion(); |
| | | DAL.ScheduleAnaLog _dalAnaLog = new DAL.ScheduleAnaLog(); |
| | | |
| | | |
| | | private List<int> _combineFlags1 = new List<int>() { 11, 12, 13, 14, 16, 17, 18 }; |
| | | private List<int> _combineFlags2 = new List<int>() { 15 }; |
| | | |
| | | public string Ana(List<Pump> pumps, double target_flow, double target_head, List<int> current_open_pump_flags, List<int> must_open_pump_flags, List<int> must_not_open_pump_flags) |
| | | { |
| | | if (pumps == null || !pumps.Any()) |
| | | { |
| | | return "æ æ¹æ¡:pumps is null"; |
| | | } |
| | | target_flow = Math.Round(target_flow, 1); |
| | | target_head = Math.Round(target_head, 1); |
| | | |
| | | var open_pump_factor = 1 / pumps.Count; |
| | | |
| | | #region åå¨-å½å弿³µå表 |
| | | |
| | | var exist_current_open_pump_flags = current_open_pump_flags != null && current_open_pump_flags.Count > 0; |
| | | |
| | | #endregion |
| | | |
| | | #region åå¨-å¿
弿³µå表 |
| | | |
| | | var must_open_pump_flags_remark = string.Empty; |
| | | var exist_must_open_pump_flags = must_open_pump_flags != null && must_open_pump_flags.Count > 0; |
| | | if (exist_must_open_pump_flags) |
| | | { |
| | | must_open_pump_flags = must_open_pump_flags.OrderBy(x => x).ToList(); |
| | | must_open_pump_flags_remark = IntListHelper.ToString(must_open_pump_flags); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region åå¨-å¿
ä¸è½å¼æ³µå表 |
| | | |
| | | var exist_must_not_open_pump_flags = must_not_open_pump_flags != null && must_not_open_pump_flags.Count > 0; |
| | | |
| | | #endregion |
| | | |
| | | var pump_flag_list = pumps.Select(x => x.ID).ToList(); |
| | | var optimal_combine_list = new List<OptimalCombine>(); |
| | | for (int pumpCount = 1; pumpCount <= pumps.Count; pumpCount++) |
| | | { |
| | | if (pumpCount == 1) |
| | | { |
| | | var max_total_flow = pumps.Max(x => x.Qr); |
| | | if (max_total_flow < target_flow) |
| | | continue; |
| | | } |
| | | var combine_list = PermutationAndCombination<int>.GetCombination(pump_flag_list.ToArray(), pumpCount);//æåç»å |
| | | foreach (var combine in combine_list) |
| | | { |
| | | double combine_merit_ratio = 1;//ç»åæ©ä¼ç |
| | | if (exist_must_open_pump_flags) |
| | | { |
| | | var combine_remark = IntListHelper.ToString(combine.OrderBy(x => x)); |
| | | if (!combine_remark.Contains(must_open_pump_flags_remark)) |
| | | continue; |
| | | } |
| | | if (exist_must_not_open_pump_flags) |
| | | { |
| | | var exist_intersected = combine.Intersect(must_not_open_pump_flags).Count() > 0; |
| | | if (exist_intersected) |
| | | continue; |
| | | } |
| | | if (exist_current_open_pump_flags) |
| | | { |
| | | var start_pump_count = combine.Except(current_open_pump_flags).Count(); |
| | | var close_pump_count = current_open_pump_flags.Except(combine).Count(); |
| | | var start_stop_count = start_pump_count + close_pump_count;//å¯åæ°é |
| | | var total_loss_ratio = Math.Pow(_start_stop_loss_coefficient, start_stop_count);//å¯å䏿¬¡æå¤±äºè½è |
| | | combine_merit_ratio *= total_loss_ratio; |
| | | } |
| | | |
| | | List<int> combine_flag_list_part1 = new List<int>(); |
| | | List<int> combine_flag_list_part2 = new List<int>(); |
| | | foreach (var pump in combine) |
| | | { |
| | | if (_combineFlags1.Contains(pump)) |
| | | { |
| | | combine_flag_list_part1.Add(pump); |
| | | } |
| | | else |
| | | { |
| | | combine_flag_list_part2.Add(pump); |
| | | } |
| | | } |
| | | |
| | | //åºåååå·æ³µ |
| | | List<FreCombine> fre_combine_list_part1 = new List<FreCombine>(); |
| | | List<FreCombine> fre_combine_list_part2 = new List<FreCombine>(); |
| | | |
| | | if (combine_flag_list_part1.Count > 0) |
| | | { |
| | | var conclusion_list_dic = new Dictionary<int, List<Entity.ScheduleConclusion>>(); |
| | | foreach (var flag in combine_flag_list_part1) |
| | | { |
| | | var runFlag = GetGFlag(flag); |
| | | if (conclusion_list_dic.ContainsKey(flag)) |
| | | continue; |
| | | var conclusionList = _dalScheduleConclusion.GetList(runFlag, target_head); |
| | | conclusion_list_dic[flag] = conclusionList; |
| | | } |
| | | |
| | | if (conclusion_list_dic.Count < 1) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | for (decimal fre = _frequency_max; fre >= _frequency_min; fre -= _frequency_space) |
| | | { |
| | | var freCombine = new FreCombine(); |
| | | freCombine.Frequency = (double)fre; |
| | | freCombine.Flags = new List<int>(); |
| | | foreach (var item in conclusion_list_dic) |
| | | { |
| | | var conclusion = item.Value.Find(x => x.Pump1 == (double)fre); |
| | | if (conclusion != null) |
| | | { |
| | | freCombine.Flags.Add(item.Key); |
| | | freCombine.Flow += conclusion.Flow; |
| | | freCombine.Power += conclusion.Power; |
| | | freCombine.RunCount++; |
| | | } |
| | | } |
| | | if (freCombine.Flags.Count < 1) |
| | | continue; |
| | | fre_combine_list_part1.Add(freCombine); |
| | | } |
| | | } |
| | | if (combine_flag_list_part2.Count > 0) |
| | | { |
| | | var conclusion_list_dic = new Dictionary<int, List<Entity.ScheduleConclusion>>(); |
| | | foreach (var flag in combine_flag_list_part2) |
| | | { |
| | | var runFlag = GetGFlag(flag); |
| | | if (conclusion_list_dic.ContainsKey(flag)) |
| | | continue; |
| | | var conclusionList = _dalScheduleConclusion.GetList(runFlag, target_head); |
| | | conclusion_list_dic[flag] = conclusionList; |
| | | } |
| | | |
| | | if (conclusion_list_dic.Count < 1) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | for (decimal fre = _frequency_max; fre >= _frequency_min; fre -= _frequency_space) |
| | | { |
| | | var freCombine = new FreCombine(); |
| | | freCombine.Frequency = (double)fre; |
| | | freCombine.Flags = new List<int>(); |
| | | foreach (var item in conclusion_list_dic) |
| | | { |
| | | var conclusion = item.Value.Find(x => x.Pump1 == (double)fre); |
| | | if (conclusion != null) |
| | | { |
| | | freCombine.Flags.Add(item.Key); |
| | | freCombine.Flow += conclusion.Flow; |
| | | freCombine.Power += conclusion.Power; |
| | | freCombine.RunCount++; |
| | | } |
| | | } |
| | | if (freCombine.Flags.Count < 1) |
| | | continue; |
| | | fre_combine_list_part2.Add(freCombine); |
| | | } |
| | | } |
| | | |
| | | if (fre_combine_list_part1.Count == 0 && fre_combine_list_part2.Count == 0) |
| | | continue; |
| | | |
| | | double flow_deviation = target_flow;//æµéåå·® |
| | | double total_power = double.MaxValue;//æ»åç |
| | | double total_flow = double.MaxValue;//æ»æµé |
| | | |
| | | FreCombine optimal_combine_part1 = null; |
| | | FreCombine optimal_combine_part2 = null; |
| | | if (fre_combine_list_part1.Count < 1 || fre_combine_list_part2.Count < 1) |
| | | { |
| | | if (fre_combine_list_part1.Count < 1) |
| | | { |
| | | fre_combine_list_part1 = fre_combine_list_part2; |
| | | } |
| | | for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++) |
| | | { |
| | | var fre_combine1 = fre_combine_list_part1[Index_part1]; |
| | | var current_flow = fre_combine1.Flow; |
| | | var current_power = fre_combine1.Power; |
| | | |
| | | var diff_flow = Math.Abs(current_flow - target_flow); |
| | | if (diff_flow < flow_deviation) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | total_power = fre_combine1.Power; |
| | | total_flow = current_flow; |
| | | flow_deviation = diff_flow; |
| | | } |
| | | |
| | | if (diff_flow < target_flow * 0.01 && current_power < total_power) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | total_power = fre_combine1.Power; |
| | | total_flow = current_flow; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++) |
| | | { |
| | | for (int Index_part2 = 0; Index_part2 < fre_combine_list_part2.Count; Index_part2++) |
| | | { |
| | | var fre_combine1 = fre_combine_list_part1[Index_part1]; |
| | | var fre_combine2 = fre_combine_list_part2[Index_part2]; |
| | | |
| | | var current_flow = fre_combine1.Flow + fre_combine2.Flow; |
| | | var current_power = fre_combine1.Power + fre_combine2.Power; |
| | | |
| | | var diff_flow = Math.Abs(current_flow - target_flow); |
| | | if (diff_flow < flow_deviation) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | optimal_combine_part2 = fre_combine2; |
| | | total_power = fre_combine1.Power + fre_combine2.Power; |
| | | total_flow = current_flow; |
| | | flow_deviation = diff_flow; |
| | | } |
| | | |
| | | if (diff_flow < target_flow * 0.01 && current_power < total_power) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | optimal_combine_part2 = fre_combine2; |
| | | total_power = fre_combine1.Power + fre_combine2.Power; |
| | | total_flow = current_flow; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (optimal_combine_part1 == null && optimal_combine_part2 == null) |
| | | return default; |
| | | |
| | | #region åææä¼ç»åæ¹æ¡ |
| | | |
| | | var optimal_combine = new OptimalCombine(); |
| | | optimal_combine.Combines = new List<FreCombine>(); |
| | | optimal_combine.Flags = new List<int>(); |
| | | if (optimal_combine_part1 != null) |
| | | { |
| | | optimal_combine.Combines.Add(optimal_combine_part1); |
| | | optimal_combine.Flags.AddRange(optimal_combine_part1.Flags); |
| | | } |
| | | if (optimal_combine_part2 != null) |
| | | { |
| | | optimal_combine.Combines.Add(optimal_combine_part2); |
| | | optimal_combine.Flags.AddRange(optimal_combine_part2.Flags); |
| | | } |
| | | optimal_combine.OpenPumpRatio = optimal_combine.Flags.Count * open_pump_factor; |
| | | optimal_combine.Flow = total_flow; |
| | | optimal_combine.Power = total_power; |
| | | optimal_combine.Flags = optimal_combine.Flags.OrderBy(x => x).ToList(); |
| | | optimal_combine.FlagCount = optimal_combine.Flags.Count; |
| | | optimal_combine.Remark = IntListHelper.ToString(optimal_combine.Flags); |
| | | optimal_combine.Scale = combine_merit_ratio - Math.Abs((1 - Math.Abs((total_flow / target_flow)))); |
| | | |
| | | //if (exist_must_open_pump_flags) |
| | | //{ |
| | | // var optimal_combine_flag_count = optimal_combine.FlagCount; |
| | | // var must_open_pump_flag_count = must_open_pump_flags.Count; |
| | | |
| | | // var open_pump_excess_count = optimal_combine_flag_count - must_open_pump_flag_count; |
| | | // optimal_combine.Scale *= (1 - (open_pump_excess_count * open_pump_factor)); |
| | | //} |
| | | optimal_combine.Head = target_head; |
| | | optimal_combine_list.Add(optimal_combine); |
| | | |
| | | #endregion |
| | | } |
| | | } |
| | | |
| | | if (optimal_combine_list.Count < 1) |
| | | return "æ æ¹æ¡"; |
| | | |
| | | var sb = new StringBuilder(); |
| | | optimal_combine_list = optimal_combine_list.OrderByDescending(x => x.Scale).ToList(); |
| | | foreach (var opt in optimal_combine_list) |
| | | { |
| | | sb.AppendLine($"Scale:{opt.Scale.ToString("N5")},Flow:{opt.Flow.ToString("N1")},Power:{opt.Power.ToString("N1")}," + |
| | | $"Flags:{opt.Remark};FlowDeviation:{(opt.Flow - target_flow).ToString("N1")}"); |
| | | } |
| | | return sb.ToString(); |
| | | |
| | | } |
| | | |
| | | |
| | | private OptimalCombine AnaOptimalCombine(double target_flow, List<FreCombine> fre_combine_list_part1, List<FreCombine> fre_combine_list_part2, List<int> must_open_pump_flags, List<int> must_not_open_pump_flags) |
| | | { |
| | | double flow_deviation = target_flow; |
| | | double total_power = double.MaxValue; |
| | | double total_flow = double.MaxValue; |
| | | |
| | | FreCombine optimal_combine_part1 = null; |
| | | FreCombine optimal_combine_part2 = null; |
| | | if (fre_combine_list_part1.Count < 1 || fre_combine_list_part2.Count < 1) |
| | | { |
| | | for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++) |
| | | { |
| | | var fre_combine1 = fre_combine_list_part1[Index_part1]; |
| | | |
| | | var current_flow = fre_combine1.Flow; |
| | | var current_power = fre_combine1.Power; |
| | | |
| | | var diff_flow = Math.Abs(current_flow - target_flow); |
| | | if (diff_flow < flow_deviation) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | total_power = fre_combine1.Power; |
| | | total_flow = current_flow; |
| | | flow_deviation = diff_flow; |
| | | } |
| | | |
| | | if (diff_flow < target_flow * 0.01 && current_power < total_power) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | total_power = fre_combine1.Power; |
| | | total_flow = current_flow; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++) |
| | | { |
| | | for (int Index_part2 = 0; Index_part2 < fre_combine_list_part2.Count; Index_part2++) |
| | | { |
| | | var fre_combine1 = fre_combine_list_part1[Index_part1]; |
| | | var fre_combine2 = fre_combine_list_part2[Index_part2]; |
| | | |
| | | var current_flow = fre_combine1.Flow + fre_combine2.Flow; |
| | | var current_power = fre_combine1.Power + fre_combine2.Power; |
| | | |
| | | var diff_flow = Math.Abs(current_flow - target_flow); |
| | | if (diff_flow < flow_deviation) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | optimal_combine_part2 = fre_combine2; |
| | | total_power = fre_combine1.Power + fre_combine2.Power; |
| | | total_flow = current_flow; |
| | | flow_deviation = diff_flow; |
| | | } |
| | | |
| | | if (diff_flow < target_flow * 0.01 && current_power < total_power) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | optimal_combine_part2 = fre_combine2; |
| | | total_power = fre_combine1.Power + fre_combine2.Power; |
| | | total_flow = current_flow; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (optimal_combine_part1 == null && optimal_combine_part2 == null) |
| | | return default; |
| | | |
| | | var optimal_combine = new OptimalCombine(); |
| | | optimal_combine.Combines = new List<FreCombine>(); |
| | | optimal_combine.Flags = new List<int>(); |
| | | if (optimal_combine_part1 != null) |
| | | { |
| | | optimal_combine.Combines.Add(optimal_combine_part1); |
| | | optimal_combine.Flags.AddRange(optimal_combine_part1.Flags); |
| | | } |
| | | if (optimal_combine_part2 != null) |
| | | { |
| | | optimal_combine.Combines.Add(optimal_combine_part2); |
| | | optimal_combine.Flags.AddRange(optimal_combine_part2.Flags); |
| | | } |
| | | |
| | | optimal_combine.Flow = total_flow; |
| | | optimal_combine.Power = total_power; |
| | | optimal_combine.Flags = optimal_combine.Flags.OrderBy(x => x).ToList(); |
| | | optimal_combine.Remark = IntListHelper.ToString(optimal_combine.Flags); |
| | | optimal_combine.Scale = 1 * Math.Abs((total_flow / target_flow)); |
| | | return optimal_combine; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå
¥åææ¥å¿ |
| | | /// </summary> |
| | | private void InsertAnaLog(string info) |
| | | { |
| | | var entity = new Entity.ScheduleAnaLog(info); |
| | | _dalAnaLog.Insert(entity); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// å¤æè¡¨æ¯å¦åå¨ |
| | | /// </summary> |
| | | public bool ExistTable(string runFlag) |
| | | { |
| | | return _dal.ExistTable(runFlag); |
| | | } |
| | | |
| | | } |
| | | } |
| | |
| | | public class OptimalCombine |
| | | { |
| | | public OptimalCombine() { } |
| | | public List<int> Flags { get; set; } |
| | | public double Flow { get; set; } |
| | | public double Head { get; set; } |
| | | public double Power { get; set; } |
| | | public List<FreCombine> Combines { get; set; } |
| | | public List<int> Flags { get; set; } |
| | | public int FlagCount { get; set; } |
| | | public string Remark { get; set; } |
| | | public double MeritRatio { get; set; } |
| | | } |
| | | |
| | | #endregion |
| | |
| | | /// </summary> |
| | | public class SchedulingHelper |
| | | { |
| | | double _frequency_def = 50; |
| | | decimal _frequency_min = 25; |
| | | decimal _frequency_max = 50; |
| | | decimal _frequency_space = 0.1m;//é¢çé´é |
| | | |
| | | double _head_space = 0.1;//æ¬ç¨é´é |
| | | double _start_stop_loss_coefficient = 0.95;//æ³µå¯åæå¤±ç³»æ° |
| | | |
| | | double _sel_opt_flow_deviation_ratio = 0.05;//å¯éæ¹æ¡çæµéåå·®æ¯ |
| | | double _sel_opt_reasonable_flow_deviation_ratio = 0.005;//åççæ¹æ¡çæµéåå·®æ¯ |
| | | |
| | | |
| | | #region RunFlag |
| | | string _falgFrePumpTag = "B"; |
| | |
| | | DAL.ScheduleAnaLog _dalAnaLog = new DAL.ScheduleAnaLog(); |
| | | |
| | | |
| | | private List<int> _combineFlags1 = new List<int>() { 11, 12, 13, 14, 16, 17, 18 }; |
| | | private List<int> _combineFlags2 = new List<int>() { 15 }; |
| | | /* private List<int> _combineFlags1 = new List<int>() { 11, 12, 13, 14, 16, 17, 18 }; |
| | | private List<int> _combineFlags2 = new List<int>() { 15 };*/ |
| | | |
| | | public void Ana(List<Pump> pumps, double taget_flow, double tagetHead) |
| | | public string Ana(List<Pump> pumps, List<int> flags_part1, List<int> flags_part2, double target_flow, double target_head, List<int> current_open_pump_flags, List<int> must_open_pump_flags, List<int> must_not_open_pump_flags) |
| | | { |
| | | tagetHead = Math.Round(tagetHead); |
| | | if (pumps == null || !pumps.Any()) |
| | | { |
| | | return "æ æ¹æ¡:pumps is null"; |
| | | } |
| | | target_flow = Math.Round(target_flow, 1); |
| | | target_head = Math.Round(target_head, 1); |
| | | |
| | | #region åå¨-å½å弿³µå表 |
| | | |
| | | var exist_current_open_pump_flags = current_open_pump_flags != null && current_open_pump_flags.Count > 0; |
| | | |
| | | #endregion |
| | | |
| | | #region åå¨-å¿
弿³µå表 |
| | | |
| | | var must_open_pump_flags_remark = string.Empty; |
| | | var exist_must_open_pump_flags = must_open_pump_flags != null && must_open_pump_flags.Count > 0; |
| | | if (exist_must_open_pump_flags) |
| | | { |
| | | must_open_pump_flags = must_open_pump_flags.OrderBy(x => x).ToList(); |
| | | must_open_pump_flags_remark = IntListHelper.ToString(must_open_pump_flags); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region åå¨-å¿
ä¸è½å¼æ³µå表 |
| | | |
| | | var exist_must_not_open_pump_flags = must_not_open_pump_flags != null && must_not_open_pump_flags.Count > 0; |
| | | |
| | | #endregion |
| | | |
| | | var pump_flag_list = pumps.Select(x => x.ID).ToList(); |
| | | var optimal_combine_list = new List<OptimalCombine>(); |
| | | for (int pumpCount = 1; pumpCount <= pumps.Count; pumpCount++) |
| | | { |
| | | var combine_list = PermutationAndCombination<int>.GetCombination(pump_flag_list.ToArray(), pumpCount); |
| | | if (pumpCount == 1) |
| | | { |
| | | var max_total_flow = pumps.Max(x => x.Qr); |
| | | if (max_total_flow < target_flow) |
| | | continue; |
| | | } |
| | | var combine_list = PermutationAndCombination<int>.GetCombination(pump_flag_list.ToArray(), pumpCount);//æåç»å |
| | | foreach (var combine in combine_list) |
| | | { |
| | | double combine_merit_ratio = 1;//ç»åæ©ä¼ç |
| | | if (exist_must_open_pump_flags) |
| | | { |
| | | var combine_remark = IntListHelper.ToString(combine.OrderBy(x => x)); |
| | | if (!combine_remark.Contains(must_open_pump_flags_remark)) |
| | | continue; |
| | | } |
| | | if (exist_must_not_open_pump_flags) |
| | | { |
| | | var exist_intersected = combine.Intersect(must_not_open_pump_flags).Count() > 0; |
| | | if (exist_intersected) |
| | | continue; |
| | | } |
| | | |
| | | int start_stop_count = 0;//å¯åæ°é |
| | | if (exist_current_open_pump_flags) |
| | | { |
| | | var start_pump_count = combine.Except(current_open_pump_flags).Count(); |
| | | var close_pump_count = current_open_pump_flags.Except(combine).Count(); |
| | | start_stop_count = start_pump_count + close_pump_count;//å¯åæ°é |
| | | } |
| | | else |
| | | { |
| | | start_stop_count = combine.Count(); |
| | | if (exist_must_open_pump_flags) |
| | | { |
| | | start_stop_count = combine.Except(must_open_pump_flags).Count(); |
| | | } |
| | | } |
| | | var total_loss_ratio = Math.Pow(_start_stop_loss_coefficient, start_stop_count);//å¯å䏿¬¡æå¤±äºè½è |
| | | combine_merit_ratio *= total_loss_ratio; |
| | | |
| | | List<int> combine_flag_list_part1 = new List<int>(); |
| | | List<int> combine_flag_list_part2 = new List<int>(); |
| | | |
| | | foreach (var pump in combine) |
| | | { |
| | | if (_combineFlags1.Contains(pump)) |
| | | if (flags_part1.Contains(pump)) |
| | | { |
| | | combine_flag_list_part1.Add(pump); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | //åºåååå·æ³µ |
| | | List<FreCombine> fre_combine_list_part1 = new List<FreCombine>(); |
| | | List<FreCombine> fre_combine_list_part2 = new List<FreCombine>(); |
| | | |
| | |
| | | var runFlag = GetGFlag(flag); |
| | | if (conclusion_list_dic.ContainsKey(flag)) |
| | | continue; |
| | | var conclusionList = _dalScheduleConclusion.GetList(runFlag, tagetHead); |
| | | var conclusionList = _dalScheduleConclusion.GetList(runFlag, target_head); |
| | | conclusion_list_dic[flag] = conclusionList; |
| | | } |
| | | |
| | |
| | | continue; |
| | | fre_combine_list_part1.Add(freCombine); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | if (combine_flag_list_part2.Count > 0) |
| | | { |
| | | var conclusion_list_dic = new Dictionary<int, List<Entity.ScheduleConclusion>>(); |
| | |
| | | var runFlag = GetGFlag(flag); |
| | | if (conclusion_list_dic.ContainsKey(flag)) |
| | | continue; |
| | | var conclusionList = _dalScheduleConclusion.GetList(runFlag, tagetHead); |
| | | var conclusionList = _dalScheduleConclusion.GetList(runFlag, target_head); |
| | | conclusion_list_dic[flag] = conclusionList; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | if (fre_combine_list_part1.Count == 0 && fre_combine_list_part2.Count == 0) |
| | | continue; |
| | | |
| | | var optimalCombine = AnaOptimalCombine(fre_combine_list_part1, fre_combine_list_part2, taget_flow); |
| | | } |
| | | double total_flow_deviation = target_flow;//æ»æµéåå·® |
| | | double total_power = double.MaxValue;//æ»åç |
| | | double total_flow = double.MaxValue;//æ»æµé |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | private OptimalCombine AnaOptimalCombine(List<FreCombine> fre_combine_list_part1, List<FreCombine> fre_combine_list_part2, double target_flow) |
| | | { |
| | | double flow_deviation = target_flow; |
| | | double total_power = double.MaxValue; |
| | | double total_flow = double.MaxValue; |
| | | |
| | | FreCombine optimal_combine_part1 = null; |
| | | FreCombine optimal_combine_part2 = null; |
| | | for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++) |
| | | { |
| | | for (int Index_part2 = 0; Index_part2 < fre_combine_list_part2.Count; Index_part2++) |
| | | { |
| | | var fre_combine1 = fre_combine_list_part1[Index_part1]; |
| | | var fre_combine2 = fre_combine_list_part2[Index_part2]; |
| | | |
| | | var current_flow = fre_combine1.Flow + fre_combine2.Flow; |
| | | var current_power = fre_combine1.Power + fre_combine2.Power; |
| | | |
| | | var diff_flow = Math.Abs(current_flow - target_flow); |
| | | if (diff_flow < flow_deviation) |
| | | FreCombine optimal_combine_part1 = null; |
| | | FreCombine optimal_combine_part2 = null; |
| | | if (fre_combine_list_part1.Count < 1 || fre_combine_list_part2.Count < 1) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | optimal_combine_part2 = fre_combine2; |
| | | total_power = fre_combine1.Power + fre_combine2.Power; |
| | | total_flow = current_flow; |
| | | flow_deviation = diff_flow; |
| | | if (fre_combine_list_part1.Count < 1) |
| | | { |
| | | fre_combine_list_part1 = fre_combine_list_part2; |
| | | } |
| | | for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++) |
| | | { |
| | | var fre_combine1 = fre_combine_list_part1[Index_part1]; |
| | | var current_flow = fre_combine1.Flow; |
| | | var current_power = fre_combine1.Power; |
| | | |
| | | var diff_flow = Math.Abs(current_flow - target_flow); |
| | | if (diff_flow < total_flow_deviation) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | total_power = fre_combine1.Power; |
| | | total_flow = current_flow; |
| | | total_flow_deviation = diff_flow; |
| | | } |
| | | |
| | | if (diff_flow < target_flow * 0.01 && current_power < total_power) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | total_power = fre_combine1.Power; |
| | | total_flow = current_flow; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++) |
| | | { |
| | | for (int Index_part2 = 0; Index_part2 < fre_combine_list_part2.Count; Index_part2++) |
| | | { |
| | | var fre_combine1 = fre_combine_list_part1[Index_part1]; |
| | | var fre_combine2 = fre_combine_list_part2[Index_part2]; |
| | | |
| | | var current_flow = fre_combine1.Flow + fre_combine2.Flow; |
| | | var current_power = fre_combine1.Power + fre_combine2.Power; |
| | | |
| | | var diff_flow = Math.Abs(current_flow - target_flow); |
| | | if (diff_flow < total_flow_deviation) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | optimal_combine_part2 = fre_combine2; |
| | | total_power = fre_combine1.Power + fre_combine2.Power; |
| | | total_flow = current_flow; |
| | | total_flow_deviation = diff_flow; |
| | | } |
| | | |
| | | if (diff_flow < target_flow * 0.01 && current_power < total_power) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | optimal_combine_part2 = fre_combine2; |
| | | total_power = fre_combine1.Power + fre_combine2.Power; |
| | | total_flow = current_flow; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (diff_flow < target_flow * 0.01 && current_power < total_power) |
| | | if (optimal_combine_part1 == null && optimal_combine_part2 == null) |
| | | continue; |
| | | |
| | | var total_flow_deviation_ratio = Math.Abs((1 - Math.Abs((total_flow / target_flow)))); |
| | | if (total_flow_deviation_ratio > _sel_opt_flow_deviation_ratio) |
| | | continue; |
| | | if (total_flow_deviation_ratio > _sel_opt_reasonable_flow_deviation_ratio) |
| | | { |
| | | optimal_combine_part1 = fre_combine1; |
| | | optimal_combine_part2 = fre_combine2; |
| | | total_power = fre_combine1.Power + fre_combine2.Power; |
| | | total_flow = current_flow; |
| | | combine_merit_ratio -= total_flow_deviation_ratio; |
| | | } |
| | | |
| | | |
| | | #region åææä¼ç»åæ¹æ¡ |
| | | |
| | | var optimal_combine = new OptimalCombine(); |
| | | optimal_combine.Combines = new List<FreCombine>(); |
| | | optimal_combine.Flags = new List<int>(); |
| | | if (optimal_combine_part1 != null) |
| | | { |
| | | optimal_combine.Combines.Add(optimal_combine_part1); |
| | | optimal_combine.Flags.AddRange(optimal_combine_part1.Flags); |
| | | } |
| | | if (optimal_combine_part2 != null) |
| | | { |
| | | optimal_combine.Combines.Add(optimal_combine_part2); |
| | | optimal_combine.Flags.AddRange(optimal_combine_part2.Flags); |
| | | } |
| | | optimal_combine.Flow = total_flow; |
| | | optimal_combine.Power = total_power; |
| | | optimal_combine.Flags = optimal_combine.Flags.OrderBy(x => x).ToList(); |
| | | optimal_combine.FlagCount = optimal_combine.Flags.Count; |
| | | optimal_combine.Remark = IntListHelper.ToString(optimal_combine.Flags); |
| | | |
| | | optimal_combine.MeritRatio = combine_merit_ratio; |
| | | optimal_combine.Head = target_head; |
| | | optimal_combine_list.Add(optimal_combine); |
| | | |
| | | #endregion |
| | | } |
| | | } |
| | | if (optimal_combine_part1 == null && optimal_combine_part2 == null) |
| | | return default; |
| | | var optimal_combine = new OptimalCombine(); |
| | | optimal_combine.Combines = new List<FreCombine>(); |
| | | if (optimal_combine_part1 != null) |
| | | |
| | | if (optimal_combine_list.Count < 1) |
| | | return "æ æ¹æ¡"; |
| | | |
| | | var sb = new StringBuilder(); |
| | | optimal_combine_list = optimal_combine_list.OrderByDescending(x => x.MeritRatio).ToList(); |
| | | foreach (var opt in optimal_combine_list) |
| | | { |
| | | optimal_combine.Combines.Add(optimal_combine_part1); |
| | | sb.AppendLine($"MeritRatio:{opt.MeritRatio.ToString("N5")},Flow:{opt.Flow.ToString("N1")},Power:{opt.Power.ToString("N1")}," + |
| | | $"Flags:{opt.Remark};FlowDeviation:{(opt.Flow - target_flow).ToString("N1")}"); |
| | | } |
| | | if (optimal_combine_part2 != null) |
| | | { |
| | | optimal_combine.Combines.Add(optimal_combine_part2); |
| | | } |
| | | optimal_combine.Flow = total_flow; |
| | | optimal_combine.Power = total_power; |
| | | return optimal_combine; |
| | | return sb.ToString(); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | private void InitializeComponent() |
| | | { |
| | | btnAnaCh1Combine = new Button(); |
| | | richTextBox1 = new RichTextBox(); |
| | | txtInfo = new RichTextBox(); |
| | | btnAnaChConclusion = new Button(); |
| | | tableLayoutPanel1 = new TableLayoutPanel(); |
| | | btnAnaCh2Combine = new Button(); |
| | | tableLayoutPanel2 = new TableLayoutPanel(); |
| | | txtFlow = new TextBox(); |
| | | txtHead = new TextBox(); |
| | | btnAna = new Button(); |
| | | txtOpenCombineList = new RichTextBox(); |
| | | splitContainer1 = new SplitContainer(); |
| | | btnAnaCh2Combine = new Button(); |
| | | tableLayoutPanel3 = new TableLayoutPanel(); |
| | | txtMustOpen = new RichTextBox(); |
| | | txtMustNotOpen = new RichTextBox(); |
| | | txtCurrentOpen = new RichTextBox(); |
| | | cmbStation = new ComboBox(); |
| | | tableLayoutPanel1.SuspendLayout(); |
| | | tableLayoutPanel2.SuspendLayout(); |
| | | ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); |
| | | splitContainer1.Panel1.SuspendLayout(); |
| | | splitContainer1.Panel2.SuspendLayout(); |
| | | splitContainer1.SuspendLayout(); |
| | | tableLayoutPanel3.SuspendLayout(); |
| | | SuspendLayout(); |
| | | // |
| | | // btnAnaCh1Combine |
| | | // |
| | | btnAnaCh1Combine.Dock = DockStyle.Fill; |
| | | btnAnaCh1Combine.Location = new Point(3, 3); |
| | | btnAnaCh1Combine.Location = new Point(0, 0); |
| | | btnAnaCh1Combine.Name = "btnAnaCh1Combine"; |
| | | btnAnaCh1Combine.Size = new Size(512, 104); |
| | | btnAnaCh1Combine.Size = new Size(257, 104); |
| | | btnAnaCh1Combine.TabIndex = 0; |
| | | btnAnaCh1Combine.Text = "åæ1è¾æ°´æ³µç»å"; |
| | | btnAnaCh1Combine.UseVisualStyleBackColor = true; |
| | | btnAnaCh1Combine.Click += btnAnaCh1Combine_Click; |
| | | // |
| | | // richTextBox1 |
| | | // txtInfo |
| | | // |
| | | richTextBox1.Dock = DockStyle.Bottom; |
| | | richTextBox1.Location = new Point(0, 221); |
| | | richTextBox1.Name = "richTextBox1"; |
| | | richTextBox1.Size = new Size(1036, 416); |
| | | richTextBox1.TabIndex = 1; |
| | | richTextBox1.Text = ""; |
| | | txtInfo.Dock = DockStyle.Bottom; |
| | | txtInfo.Location = new Point(0, 221); |
| | | txtInfo.Name = "txtInfo"; |
| | | txtInfo.Size = new Size(1036, 416); |
| | | txtInfo.TabIndex = 1; |
| | | txtInfo.Text = ""; |
| | | // |
| | | // btnAnaChConclusion |
| | | // |
| | | btnAnaChConclusion.Location = new Point(3, 113); |
| | | btnAnaChConclusion.Location = new Point(521, 3); |
| | | btnAnaChConclusion.Name = "btnAnaChConclusion"; |
| | | btnAnaChConclusion.Size = new Size(512, 104); |
| | | btnAnaChConclusion.TabIndex = 2; |
| | |
| | | tableLayoutPanel1.ColumnCount = 2; |
| | | tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); |
| | | tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); |
| | | tableLayoutPanel1.Controls.Add(btnAnaCh1Combine, 0, 0); |
| | | tableLayoutPanel1.Controls.Add(btnAnaChConclusion, 0, 1); |
| | | tableLayoutPanel1.Controls.Add(btnAnaCh2Combine, 1, 0); |
| | | tableLayoutPanel1.Controls.Add(tableLayoutPanel2, 1, 1); |
| | | tableLayoutPanel1.Controls.Add(splitContainer1, 0, 0); |
| | | tableLayoutPanel1.Controls.Add(btnAnaChConclusion, 1, 0); |
| | | tableLayoutPanel1.Controls.Add(tableLayoutPanel3, 0, 1); |
| | | tableLayoutPanel1.Dock = DockStyle.Fill; |
| | | tableLayoutPanel1.Location = new Point(0, 0); |
| | | tableLayoutPanel1.Name = "tableLayoutPanel1"; |
| | |
| | | tableLayoutPanel1.Size = new Size(1036, 221); |
| | | tableLayoutPanel1.TabIndex = 3; |
| | | // |
| | | // btnAnaCh2Combine |
| | | // |
| | | btnAnaCh2Combine.Location = new Point(521, 3); |
| | | btnAnaCh2Combine.Name = "btnAnaCh2Combine"; |
| | | btnAnaCh2Combine.Size = new Size(512, 104); |
| | | btnAnaCh2Combine.TabIndex = 3; |
| | | btnAnaCh2Combine.Text = "åæ2è¾æ°´æ³µç»å"; |
| | | btnAnaCh2Combine.UseVisualStyleBackColor = true; |
| | | btnAnaCh2Combine.Click += btnAnaCh2Combine_Click; |
| | | // |
| | | // tableLayoutPanel2 |
| | | // |
| | | tableLayoutPanel2.ColumnCount = 2; |
| | |
| | | tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); |
| | | tableLayoutPanel2.Controls.Add(txtFlow, 0, 0); |
| | | tableLayoutPanel2.Controls.Add(txtHead, 1, 0); |
| | | tableLayoutPanel2.Controls.Add(btnAna, 1, 1); |
| | | tableLayoutPanel2.Controls.Add(txtOpenCombineList, 0, 1); |
| | | tableLayoutPanel2.Controls.Add(btnAna, 0, 1); |
| | | tableLayoutPanel2.Dock = DockStyle.Fill; |
| | | tableLayoutPanel2.Location = new Point(521, 113); |
| | | tableLayoutPanel2.Name = "tableLayoutPanel2"; |
| | | tableLayoutPanel2.RowCount = 2; |
| | | tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Percent, 34.2857132F)); |
| | | tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Percent, 65.71429F)); |
| | | tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F)); |
| | | tableLayoutPanel2.Size = new Size(512, 105); |
| | | tableLayoutPanel2.TabIndex = 4; |
| | | // |
| | |
| | | // |
| | | // btnAna |
| | | // |
| | | tableLayoutPanel2.SetColumnSpan(btnAna, 2); |
| | | btnAna.Dock = DockStyle.Fill; |
| | | btnAna.Location = new Point(259, 39); |
| | | btnAna.Location = new Point(3, 39); |
| | | btnAna.Name = "btnAna"; |
| | | btnAna.Size = new Size(250, 63); |
| | | btnAna.Size = new Size(506, 63); |
| | | btnAna.TabIndex = 3; |
| | | btnAna.Text = "åæ"; |
| | | btnAna.UseVisualStyleBackColor = true; |
| | | btnAna.Click += btnAna_Click; |
| | | // |
| | | // txtOpenCombineList |
| | | // splitContainer1 |
| | | // |
| | | txtOpenCombineList.Dock = DockStyle.Fill; |
| | | txtOpenCombineList.Location = new Point(3, 39); |
| | | txtOpenCombineList.Name = "txtOpenCombineList"; |
| | | txtOpenCombineList.Size = new Size(250, 63); |
| | | txtOpenCombineList.TabIndex = 4; |
| | | txtOpenCombineList.Text = "11,12,13,17"; |
| | | splitContainer1.Dock = DockStyle.Fill; |
| | | splitContainer1.Location = new Point(3, 3); |
| | | splitContainer1.Name = "splitContainer1"; |
| | | // |
| | | // splitContainer1.Panel1 |
| | | // |
| | | splitContainer1.Panel1.Controls.Add(btnAnaCh1Combine); |
| | | // |
| | | // splitContainer1.Panel2 |
| | | // |
| | | splitContainer1.Panel2.Controls.Add(btnAnaCh2Combine); |
| | | splitContainer1.Size = new Size(512, 104); |
| | | splitContainer1.SplitterDistance = 257; |
| | | splitContainer1.TabIndex = 5; |
| | | // |
| | | // btnAnaCh2Combine |
| | | // |
| | | btnAnaCh2Combine.Dock = DockStyle.Fill; |
| | | btnAnaCh2Combine.Location = new Point(0, 0); |
| | | btnAnaCh2Combine.Name = "btnAnaCh2Combine"; |
| | | btnAnaCh2Combine.Size = new Size(251, 104); |
| | | btnAnaCh2Combine.TabIndex = 3; |
| | | btnAnaCh2Combine.Text = "åæ2è¾æ°´æ³µç»å"; |
| | | btnAnaCh2Combine.UseVisualStyleBackColor = true; |
| | | btnAnaCh2Combine.Click += btnAnaCh2Combine_Click; |
| | | // |
| | | // tableLayoutPanel3 |
| | | // |
| | | tableLayoutPanel3.ColumnCount = 2; |
| | | tableLayoutPanel3.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); |
| | | tableLayoutPanel3.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); |
| | | tableLayoutPanel3.Controls.Add(txtMustOpen, 0, 0); |
| | | tableLayoutPanel3.Controls.Add(txtMustNotOpen, 1, 0); |
| | | tableLayoutPanel3.Controls.Add(txtCurrentOpen, 0, 1); |
| | | tableLayoutPanel3.Controls.Add(cmbStation, 1, 1); |
| | | tableLayoutPanel3.Dock = DockStyle.Fill; |
| | | tableLayoutPanel3.Location = new Point(3, 113); |
| | | tableLayoutPanel3.Name = "tableLayoutPanel3"; |
| | | tableLayoutPanel3.RowCount = 2; |
| | | tableLayoutPanel3.RowStyles.Add(new RowStyle(SizeType.Percent, 50F)); |
| | | tableLayoutPanel3.RowStyles.Add(new RowStyle(SizeType.Percent, 50F)); |
| | | tableLayoutPanel3.Size = new Size(512, 105); |
| | | tableLayoutPanel3.TabIndex = 6; |
| | | // |
| | | // txtMustOpen |
| | | // |
| | | txtMustOpen.Dock = DockStyle.Fill; |
| | | txtMustOpen.Location = new Point(3, 3); |
| | | txtMustOpen.Name = "txtMustOpen"; |
| | | txtMustOpen.Size = new Size(250, 46); |
| | | txtMustOpen.TabIndex = 5; |
| | | txtMustOpen.Text = ""; |
| | | // |
| | | // txtMustNotOpen |
| | | // |
| | | txtMustNotOpen.Dock = DockStyle.Fill; |
| | | txtMustNotOpen.Location = new Point(259, 3); |
| | | txtMustNotOpen.Name = "txtMustNotOpen"; |
| | | txtMustNotOpen.Size = new Size(250, 46); |
| | | txtMustNotOpen.TabIndex = 6; |
| | | txtMustNotOpen.Text = ""; |
| | | // |
| | | // txtCurrentOpen |
| | | // |
| | | txtCurrentOpen.Location = new Point(3, 55); |
| | | txtCurrentOpen.Name = "txtCurrentOpen"; |
| | | txtCurrentOpen.Size = new Size(250, 47); |
| | | txtCurrentOpen.TabIndex = 4; |
| | | txtCurrentOpen.Text = "11,12,13,17"; |
| | | // |
| | | // cmbStation |
| | | // |
| | | cmbStation.Dock = DockStyle.Fill; |
| | | cmbStation.FormattingEnabled = true; |
| | | cmbStation.Items.AddRange(new object[] { "ä¸è¾æ°´", "äºè¾æ°´" }); |
| | | cmbStation.Location = new Point(259, 55); |
| | | cmbStation.Name = "cmbStation"; |
| | | cmbStation.Size = new Size(250, 32); |
| | | cmbStation.TabIndex = 7; |
| | | cmbStation.SelectedIndexChanged += cmbStation_SelectedIndexChanged; |
| | | // |
| | | // Form1 |
| | | // |
| | |
| | | AutoScaleMode = AutoScaleMode.Font; |
| | | ClientSize = new Size(1036, 637); |
| | | Controls.Add(tableLayoutPanel1); |
| | | Controls.Add(richTextBox1); |
| | | Controls.Add(txtInfo); |
| | | Name = "Form1"; |
| | | StartPosition = FormStartPosition.CenterScreen; |
| | | Text = "Form1"; |
| | | tableLayoutPanel1.ResumeLayout(false); |
| | | tableLayoutPanel2.ResumeLayout(false); |
| | | tableLayoutPanel2.PerformLayout(); |
| | | splitContainer1.Panel1.ResumeLayout(false); |
| | | splitContainer1.Panel2.ResumeLayout(false); |
| | | ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); |
| | | splitContainer1.ResumeLayout(false); |
| | | tableLayoutPanel3.ResumeLayout(false); |
| | | ResumeLayout(false); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | private Button btnAnaCh1Combine; |
| | | private RichTextBox richTextBox1; |
| | | private RichTextBox txtInfo; |
| | | private Button btnAnaChConclusion; |
| | | private TableLayoutPanel tableLayoutPanel1; |
| | | private Button btnAnaCh2Combine; |
| | |
| | | private TextBox txtFlow; |
| | | private TextBox txtHead; |
| | | private Button btnAna; |
| | | private RichTextBox txtOpenCombineList; |
| | | private RichTextBox txtCurrentOpen; |
| | | private SplitContainer splitContainer1; |
| | | private TableLayoutPanel tableLayoutPanel3; |
| | | private RichTextBox txtMustOpen; |
| | | private RichTextBox txtMustNotOpen; |
| | | private ComboBox cmbStation; |
| | | } |
| | | } |
| | |
| | | { |
| | | System.Diagnostics.Process.GetCurrentProcess().Kill(); |
| | | }; |
| | | this.cmbStation.SelectedIndex = 0; |
| | | } |
| | | |
| | | int _stationIndex = 0; |
| | | string _floder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data"); |
| | | |
| | | private void cmbStation_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | _stationIndex = cmbStation.SelectedIndex; |
| | | if (_stationIndex == 0) |
| | | { |
| | | this.txtFlow.Text = "16406"; |
| | | this.txtHead.Text = "15.92"; |
| | | this.txtCurrentOpen.Text = "11,12,13,17"; |
| | | } |
| | | else |
| | | { |
| | | this.txtFlow.Text = "39,460"; |
| | | this.txtHead.Text = "19.65"; |
| | | this.txtCurrentOpen.Text = "22,23,25,26"; |
| | | } |
| | | |
| | | } |
| | | |
| | | private void btnAnaCombine_Click(object sender, EventArgs e) |
| | | { |
| | | this.richTextBox1.Text += "\r\næ£å¨åææ³µç»å"; |
| | | this.txtInfo.Text += "\r\næ£å¨åææ³µç»å"; |
| | | var ch1 = _floder + "\\" + "éè¡ä¸è¾.json"; |
| | | var ch1_json = File.ReadAllText(ch1); |
| | | var ch1Pumps = JsonHelper.Json2Object<List<Model.Pump>>(ch1_json); |
| | |
| | | helper.AnaCombine(ch1Pumps); |
| | | this.Invoke(() => |
| | | { |
| | | this.richTextBox1.Text += "\r\nåææ³µç»å宿¯"; |
| | | this.txtInfo.Text += "\r\nåææ³µç»å宿¯"; |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | private void btnAnaCh1Combine_Click(object sender, EventArgs e) |
| | | { |
| | | var ch1 = _floder + "\\" + "éè¡ä¸è¾.json"; |
| | | var ch1_json = File.ReadAllText(ch1); |
| | | var ch1Pumps = JsonHelper.Json2Object<List<Model.Pump>>(ch1_json); |
| | | this.richTextBox1.Text += "\r\næ£å¨åæ1è¾æ°´æ³µç»å"; |
| | | this.txtInfo.Text += "\r\næ£å¨åæ1è¾æ°´æ³µç»å"; |
| | | Task.Run(() => |
| | | { |
| | | var helper = new Algorithm.SchedulingAnaHelper(); |
| | | helper.AnaCombine(ch1Pumps); |
| | | this.Invoke(() => |
| | | { |
| | | this.richTextBox1.Text += "\r\nåæ1è¾æ°´æ³µç»å宿¯"; |
| | | this.txtInfo.Text += "\r\nåæ1è¾æ°´æ³µç»å宿¯"; |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | |
| | | private void btnAnaCh2Combine_Click(object sender, EventArgs e) |
| | | { |
| | |
| | | var ch2_json = File.ReadAllText(ch2); |
| | | var ch2Pumps = JsonHelper.Json2Object<List<Model.Pump>>(ch2_json); |
| | | |
| | | this.richTextBox1.Text += "\r\næ£å¨åæ2è¾æ°´æ³µç»å"; |
| | | this.txtInfo.Text += "\r\næ£å¨åæ2è¾æ°´æ³µç»å"; |
| | | Task.Run(() => |
| | | { |
| | | var helper = new Algorithm.SchedulingAnaHelper(); |
| | | helper.AnaCombine(ch2Pumps); |
| | | this.Invoke(() => |
| | | { |
| | | this.richTextBox1.Text += "\r\nåæ2è¾æ°´æ³µç»å宿¯"; |
| | | this.txtInfo.Text += "\r\nåæ2è¾æ°´æ³µç»å宿¯"; |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | |
| | | private void btnAnaChConclusion_Click(object sender, EventArgs e) |
| | | { |
| | | this.richTextBox1.Text += "\r\næ£å¨åæå
¨é¨æ³µç»åç»è®º"; |
| | | this.txtInfo.Text += "\r\næ£å¨åæå
¨é¨æ³µç»åç»è®º"; |
| | | Task.Run(() => |
| | | { |
| | | var helper = new Algorithm.SchedulingAnaHelper(); |
| | | helper.AnaConclusion(); |
| | | this.Invoke(() => |
| | | { |
| | | this.richTextBox1.Text += "\r\nå
¨é¨æ³µç»ååæå®æ¯"; |
| | | this.txtInfo.Text += "\r\nå
¨é¨æ³µç»ååæå®æ¯"; |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | private void btnAna_Click(object sender, EventArgs e) |
| | | { |
| | | this.txtInfo.Text = string.Empty; |
| | | if (!double.TryParse(this.txtFlow.Text, out double targetFlow)) |
| | | { |
| | | MessageBox.Show("请è¾å
¥æµé!"); |
| | |
| | | MessageBox.Show("请è¾å
¥åå!"); |
| | | return; |
| | | } |
| | | var combine = this.txtOpenCombineList.Text.Trim(); |
| | | if (string.IsNullOrEmpty(combine)) |
| | | List<int> current_open_pump_list = new List<int>(); |
| | | List<int> must_open_pump_list = new List<int>(); |
| | | List<int> must_not_open_pump_list = new List<int>(); |
| | | |
| | | var current_open_pump_list_txt = this.txtCurrentOpen.Text.Trim(); |
| | | if (!string.IsNullOrEmpty(current_open_pump_list_txt)) |
| | | { |
| | | MessageBox.Show("请è¾å
¥æ³µç»å!"); |
| | | return; |
| | | current_open_pump_list = IntListHelper.ToList(current_open_pump_list_txt); |
| | | if (current_open_pump_list == null || current_open_pump_list.Count < 1) |
| | | { |
| | | MessageBox.Show("请è¾å
¥æææ³µç»å!\r\n','å·é´é!"); |
| | | return; |
| | | } |
| | | } |
| | | var combineList = IntListHelper.ToList(combine); |
| | | if (combineList == null || combineList.Count < 1) |
| | | |
| | | var must_open_pump_list_txt = this.txtMustOpen.Text.Trim(); |
| | | if (!string.IsNullOrEmpty(must_open_pump_list_txt)) |
| | | { |
| | | MessageBox.Show("请è¾å
¥æææ³µç»å!\r\n','å·é´é!"); |
| | | return; |
| | | must_open_pump_list = IntListHelper.ToList(must_open_pump_list_txt); |
| | | if (must_open_pump_list == null || must_open_pump_list.Count < 1) |
| | | { |
| | | MessageBox.Show("请è¾å
¥æææ³µç»å!\r\n','å·é´é!"); |
| | | return; |
| | | } |
| | | } |
| | | var ch1 = _floder + "\\" + "éè¡ä¸è¾.json"; |
| | | var ch1_json = File.ReadAllText(ch1); |
| | | var ch1Pumps = JsonHelper.Json2Object<List<Model.Pump>>(ch1_json); |
| | | |
| | | var must_not_open_pump_list_txt = this.txtMustNotOpen.Text.Trim(); |
| | | if (!string.IsNullOrEmpty(must_not_open_pump_list_txt)) |
| | | { |
| | | must_not_open_pump_list = IntListHelper.ToList(must_not_open_pump_list_txt); |
| | | if (must_not_open_pump_list == null || must_not_open_pump_list.Count < 1) |
| | | { |
| | | MessageBox.Show("请è¾å
¥æææ³µç»å!\r\n','å·é´é!"); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | List<Model.Pump> pumps; |
| | | List<int> flags_part1, flags_part2; |
| | | if (_stationIndex == 0) |
| | | { |
| | | var filePath = _floder + "\\" + "éè¡ä¸è¾.json"; |
| | | var jsonInfo = File.ReadAllText(filePath); |
| | | pumps = JsonHelper.Json2Object<List<Model.Pump>>(jsonInfo); |
| | | |
| | | flags_part1 = new List<int>() { 11, 12, 13, 14, 16, 17, 18 }; |
| | | flags_part2 = new List<int>() { 15 }; |
| | | } |
| | | else |
| | | { |
| | | var filePath = _floder + "\\" + "éè¡äºè¾.json"; |
| | | var jsonInfo = File.ReadAllText(filePath); |
| | | pumps = JsonHelper.Json2Object<List<Model.Pump>>(jsonInfo); |
| | | |
| | | flags_part1 = new List<int>() { 22, 23, 24, 25, 26 }; |
| | | flags_part2 = new List<int>() { 21, 27 }; |
| | | } |
| | | |
| | | var helper = new Algorithm.SchedulingHelper(); |
| | | helper.Ana(ch1Pumps, targetFlow, targetHead); |
| | | var info = helper.Ana(pumps, flags_part1, flags_part2, targetFlow, targetHead, current_open_pump_list, must_open_pump_list, must_not_open_pump_list); |
| | | |
| | | this.txtInfo.Text = info; |
| | | } |
| | | |
| | | } |
| | | } |