# Copyright (c) 2009 Tim Freeman # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # (This is the standard MIT License, copied from # http://www.opensource.org/licenses/mit-license.php on 24 Apr 2007.) #desc Various ways to combine together the utilities of all of the agents other #desc than the AI to get the AI's utility. # Selfless_utility_combiner simply adds up all the utilities, so the # AI is completely fair. class Selfless_utility_combiner(object): def ai_utility(self, utility_dict, do_nothing_utility_dict): total_utility = 0.0 for A in utility_dict: total_utility += utility_dict[A] return total_utility # Variable_compassion_uc combines utilities based on a compassion table. # The compassion table maps person-id's to how much the AI cares about # that person. class Compassionate_utility_combiner(object): def __init__(self, compassion_table): self.compassion_table = compassion_table def ai_utility(self, utility_dict, do_nothing_utility_dict): total_utility = 0.0 for A in utility_dict: total_utility += self.compassion_table[A] * utility_dict[A] return total_utility # Respectful_utility_combiner is like Compassionate_utility_combiner, # except we get to say that reducing the other agent's utility (as compared to # the alternative of doing nothing) reduces the AI's computed utility. # respect_table gives the ratio between their reduced utility and our # reduced utility. If the AI has both compassion and respect for # an agent, and the AI is considering a plan that reduces their # utility, then the dysutilities add. # # Typically the values in respect_table will be nonnegative. Negative # respect or negative compassion can plausibly be called "spite". class Respectful_utility_combiner(object): def __init__(self, compassion_table, respect_table): self.compassion_table = compassion_table self.respect_table = respect_table def ai_utility(self, utility_dict, do_nothing_utility_dict): total_utility = 0.0 for A in utility_dict: increment = utility_dict[A] - do_nothing_utility_dict[A] if increment > 0: total_utility += self.compassion_table[A] * increment if increment < 0: # increment is negative, self.respect_table[A] is # typically positive, so if we get here we'll decrease # total_utility. total_utility += self.respect_table[A] * increment return total_utility