//is the negotiator between agent 5 and agent 1 public double negotiateAG5AG1(double kW, double pricePerHour) { Random randy = new Random(); double µAg5 = ag1_.consumptionHeatedFloorMin() * pricePerHour; double µAg1 = ag1_.consumptionHeatedFloorMax() * pricePerHour; double rand = randy.NextDouble(); double sigmoidAg5 = 1 / (1 + Math.Pow(Math.E, ((kW - µAg5) / slack_))); // buy double sigmoidAg1 = 1 - (1 / ((1 + Math.Pow(Math.E, (kW - µAg5))) / ag1_.Slack)); // sell //if rand is greater than either of the sigmoids then agent5 and agent1 is in agreement if (rand > sigmoidAg5 && rand > sigmoidAg1) { return(kW); } //if kW is greater than µAg1, then kW = µAg5 so that it starts all over again else if (kW > µAg1) { return(kW = µAg5); } // else { slack_ += 0.36; //ag1_.Slack += 0.36; } return(negotiateAG5AG1(kW + 1, pricePerHour)); }
//to contiuously update the label deligate is used private void agentsLabels(int i, int j, bool state) { LabelDayAgent1.Invoke((MethodInvoker)(() => LabelDayAgent1.Text = "Day: " + i)); LabelHourAgent1.Invoke((MethodInvoker)(() => LabelHourAgent1.Text = "Hour: " + j)); LabelStateAgent1.Invoke((MethodInvoker)(() => LabelStateAgent1.Text = "State: " + currentStateIs(state))); LabelConsumptionHeatedFloorAgent1.Invoke((MethodInvoker)(() => LabelConsumptionHeatedFloorAgent1.Text = "Consumption heated floor: " + ag1_.consumptionHeatedFloorMax() + " kW/h")); LabelConsumptionBoilerAgent1.Invoke((MethodInvoker)(() => LabelConsumptionBoilerAgent1.Text = "Consumption boiler: " + ag1_.consumptionBoiler() + " kW/h")); LabelDayAgent2.Invoke((MethodInvoker)(() => LabelDayAgent2.Text = "Day: " + i)); LabelHourAgent2.Invoke((MethodInvoker)(() => LabelHourAgent2.Text = "Hour: " + j)); LabelStateAgent2.Invoke((MethodInvoker)(() => LabelStateAgent2.Text = "State: " + currentStateIs(state))); LabelConsumptionCentralHeatingAgent2.Invoke((MethodInvoker)(() => LabelConsumptionCentralHeatingAgent2.Text = "Consumption central heating: " + ag2_.consumptionCenteralHeaterMax() + " kW/h")); LabelDayAgent3.Invoke((MethodInvoker)(() => LabelDayAgent3.Text = "Day: " + i)); LabelHourAgent3.Invoke((MethodInvoker)(() => LabelHourAgent3.Text = "Hour: " + j)); LabelStateAgent3.Invoke((MethodInvoker)(() => LabelStateAgent3.Text = "State: " + currentStateIs(state))); LabelBatteryLevelAgent3.Invoke((MethodInvoker)(() => LabelBatteryLevelAgent3.Text = "Battery level: " + ag3_.batteryLevel() + " kW")); LabelDayAgent4.Invoke((MethodInvoker)(() => LabelDayAgent4.Text = "Day: " + i)); LabelHourAgent4.Invoke((MethodInvoker)(() => LabelHourAgent4.Text = "Hour: " + j)); LabelStateAgent4.Invoke((MethodInvoker)(() => LabelStateAgent4.Text = "State: " + currentStateIs(state))); LabelDayAgent5.Invoke((MethodInvoker)(() => LabelDayAgent5.Text = "Day: " + i)); LabelHourAgent5.Invoke((MethodInvoker)(() => LabelHourAgent5.Text = "Hour: " + j)); LabelStateAgent5.Invoke((MethodInvoker)(() => LabelStateAgent5.Text = "State: " + currentStateIs(state))); LabelSolarPanelAgent5.Invoke((MethodInvoker)(() => LabelSolarPanelAgent5.Text = "Solar Panel: " + ag5_.solarPanel(j) + " kW/h")); LabelActionAgent5.Invoke((MethodInvoker)(() => LabelActionAgent5.Text = "Action cost: " + ag5_.getBuyNOK(j) + " credit")); }