Winforms 需要确定列表中的最小值
我被一些看似简单但很快就让我头疼的事情困住了: 下面是一个表示我正在使用的结构的类:Winforms 需要确定列表中的最小值,winforms,list,c#-4.0,linq-to-objects,Winforms,List,C# 4.0,Linq To Objects,我被一些看似简单但很快就让我头疼的事情困住了: 下面是一个表示我正在使用的结构的类: public class LocumJobDistanceDifferenceObject { public LocumJobDistanceDifferenceObject(Int64 ALocumID, Int64 AJobID, Decimal ADistanceMiles, Int32 ARateDifference, Boolean AIsDistanceUnderMax) {
public class LocumJobDistanceDifferenceObject {
public LocumJobDistanceDifferenceObject(Int64 ALocumID, Int64 AJobID, Decimal ADistanceMiles, Int32 ARateDifference, Boolean AIsDistanceUnderMax) {
LocumID = ALocumID;
JobID = AJobID;
DistanceMiles = ADistanceMiles;
RateDifference = ARateDifference;
IsDistanceUnderMax = AIsDistanceUnderMax;
}
public Int64 LocumID {
get;
set;
}
public Int64 JobID {
get;
set;
}
public Decimal DistanceMiles {
get;
set;
}
public Int32 RateDifference {
get;
set;
}
public Boolean IsDistanceUnderMax {
get;
set;
}
}
我创建一个列表来存储信息矩阵。洛科姆是一名工人,他需要得到一份工作。我有50份工作,75个房间。我通过运行一个Looms x Jobs算法来构建我的矩阵,该算法存储LoomMid+JobID+确定Loomm和Job之间的距离英里数+确定Job支付/小时和Loomm想要/小时的比率+如果Job的剂量超过Loomm愿意旅行的最大距离
所以,基本上,因为矩阵中的行数是75 x 50
现在,我需要在我的矩阵(我称之为MindMapTier01)上运行一个循环(ForEach),如下所示:
foreach (LocumJobDistanceDifferenceObject LocumJobDistanceDifferenceItem in MindMapTier01.OrderBy(order=>order.JobID)) {
/**
* Build a list (KeyValuePair<JobID, LocumID>) such that for each unique JobID,
* I can assign the Locum closest to that Job. I need to keep in mind that
* once a job is assigned, I dont want that JobID or LocumID for the next iteration
**/
}
foreach(MindMapTier01.OrderBy(order=>order.JobID)中的LoomJobDistanceDifferenceObject LoomJobDistanceDifferenceItem){
/**
*构建一个列表(KeyValuePair),以便对于每个唯一的JobID,
*我可以指定最接近该工作的人员。我需要记住这一点
*一旦分配了一个作业,我就不希望在下一次迭代中使用该JobID或locomid
**/
}
我希望我能解释清楚。我需要在一两个小时内克服这个问题。请帮忙
尊敬。我不知道我是否完全理解您的问题,但如果您希望确保将作业分配给最近的LocOM,则您的代码可能如下所示:
Dictionary<Int64, Int64> dicJobLocum = New Dictionary<Int64, Int64>(); // This is the key value pair list
Dictionary<Int64, Int64> dicJobDistance = New Dictionary<Int64, Decimal>(); // This is to track the distance of the currently assigned locum
foreach (LocumJobDistanceDifferenceObject locum in MindMapTier01) {
if (dicJobDistance.ContainsKey(locum.JobID) {
Decimal distance = dicJobDistance(locum.JobID);
// If the job has been assigned, check if the current locum is closer
if (locum.DistanceMiles < distance) {
dicJobDistance(locum.JobID) = locum.Distance;
dicJobLocum(locum.JobID) = locum.LocumID;
}
}
else {
// If the job has not been assigned yet
dicJobDistance.Add(locum.JobID, locum.DistanceMiles);
dicJobLocum.Add(locum.JobID, locum.LocumID);
}
}
Dictionary dicjoblocom=New Dictionary();//这是键值对列表
Dictionary dicJobDistance=新字典();//这是为了跟踪当前分配的蝗虫的距离
foreach(MindMapTier01中的LoomJ目标距离差异对象Locom){
if(dicJobDistance.ContainsKey(Locom.JobID){
十进制距离=dicJobDistance(Locom.JobID);
//如果已分配作业,请检查当前蝗虫是否更接近
if(房间距离英里数<距离){
dicJobDistance(Locom.JobID)=Locom.Distance;
双若虫(若虫:若虫)=若虫;
}
}
否则{
//如果尚未分配作业
dicJobDistance.Add(Locom.JobID,Locom.DistanceMiles);
添加(蝗虫、蝗虫、蝗虫);
}
}
请原谅任何小的语法错误,我最近没有使用c#。在仔细考虑了您的建议后,我终于得到了结果。谢谢。