Skip to content

Model 1C with Noise…

June 27, 2011

We introduce 50% random noise into Model 1C as follows:

For k = 1 To 5000

            For i = 0 To 99
                If income(i) < demandtotal(i) Then
                    If hours(i) < demandtotal(i) Then
                        hours(i) = hours(i) + 1
                    End If
                    ' work more if income is not enough to meet agents demands
                Else
                    If hours(i) > 0 Then
                        hours(i) = hours(i) - 1
                    End If
                    ' work less if income is enough to meet agents demands
                End If
            Next

            If Rnd() > 0.5 Then

                For i = 0 To 99
                    j = Int(Rnd() * 99)
                    If income(j) > 0 Then
                        If Rnd() > 0.5 Or investmentpot = 0 Then
                            income(j) = income(j) - 1
                        Else
                            investmentpot = investmentpot - 1
                        End If
                        If Rnd() > 0.5 Then
                            j = Int(Rnd() * 99)
                            income(j) = income(j) + 1
                        Else
                            investmentpot = investmentpot + 1
                        End If
                    End If
                Next
            Else

                For i = 0 To 99
                    worstdifference = 0
                    worstoffender = -1
                    bestdifference = 1000
                    bestprovider = -1
                    m = -1
                    n = 0
                    For j = 0 To 99
                        If Int((hours(j) / 100) - demand(i, j)) < 0 And ((hours(j) / 100) - demand(i, j)) ^ 2 = worstdifference ^ 2 And income(j) > 0 Then
                            m = m + 1
                            worstoffenders(m) = j
                        End If

                        If Int((hours(j) / 100) - demand(i, j)) < 0 And ((hours(j) / 100) - demand(i, j)) ^ 2 > worstdifference ^ 2 And income(j) > 0 Then
                            m = 0
                            worstoffenders(0) = j
                            worstdifference = ((hours(j) / 100) - demand(i, j))
                        End If

                        If demand(i, j) > 0 And Int((hours(j) / 100) - demand(i, j)) ^ 2 = Int(bestdifference) ^ 2 Then
                            n = n + 1
                            bestproviders(n) = j
                        End If

                        If demand(i, j) > 0 And Int((hours(j) / 100) - demand(i, j)) ^ 2 < Int(bestdifference) ^ 2 Then
                            n = 0
                            bestproviders(0) = j
                            bestdifference = ((hours(j) / 100) - demand(i, j))
                        End If

                    Next
                    If m > -1 Then
                        worstoffender = worstoffenders(Int(Rnd() * m))
                        bestprovider = bestproviders(Int(Rnd() * n))
                        If (demandtotal(worstoffender) - hours(worstoffender)) > (demandtotal(i) - hours(i)) Or investmentpot = 0 Then
                            income(worstoffender) = income(worstoffender) - 1
                        Else
                            investmentpot = investmentpot - 1
                        End If
                        If income(bestprovider) < income(i) Then
                            income(bestprovider) = income(bestprovider) + 1
                        Else
                            investmentpot = investmentpot + 1
                        End If
                    End If



                Next

            End If

        Next
Leave a Comment

Leave a comment