如何列出邻近集群的pcolors?

时间:2016-05-10 15:28:37

标签: netlogo

我有不同的补丁集群,每个补丁都有不同的颜色,并且有一只乌龟作为政府。 我需要让政府知道邻近集群的人物是什么。

我试图用邻居的颜色ID列出一个列表,但到目前为止我只能列出所有补丁的列表

我使用的相关代码是:

governments-own[
list-neighbors
govcolorid
]

to setup
ask governments [
...
set govcolorid pcolor
...]
end

to find-neighbors
foreach sort governments [
ask ? [
let my-patch patches with [ pcolor = [ govcolorid ] of myself ]
set list-neighbors (list [[pcolor] of neighbors] of my-patch)
]]

此代码打印一个列表邻居,如下所示:

[[[18 92 85 18 92 85 18 18] [85 11 85 85 85 18 85 85] [85 85 85 85 85 18 85 85]]]

但我需要的只是邻近的群集pcolor减去govcolorid(在这种情况下为85):

[18 92 11]

我尝试使用地图,句子和删除重复项,但到目前为止我无法达到任何结果。如果您有任何有用的提示或示例,请分享。

编辑:

根据您的意见,我解决了以下colde的问题:

to find-neighbors-patch
  foreach sort governments [
    ask ? [
  let _c [idgov] of ?
  let _frnds patches with [pcolor = _c]
  let _nmes (patch-set [neighbors] of _frnds) with [pcolor != _c]
  set list-neighbors-clusters remove-duplicates [pcolor] of _nmes
    ]]
end

谢谢

2 个答案:

答案 0 :(得分:2)

要将输出结果与所需输出结果相符,请尝试以下代码: 基本上,将列表列表缩减为单个列表,删除重复项,然后删除所需的值。

set list-neighbors filter [ ? != 85] remove-duplicates reduce [sentence ?1 ?2] (first list-neighbors)

答案 1 :(得分:1)

使用记者程序:

// Select the correct child from the database
$sql_childID = "SELECT id FROM child
                WHERE firstName = '$childFirstName'
                AND lastName = '$childLastName'";
$result = $pdo->query($sql_childID);
$row = $result->fetch();
$var = $row['id'];

// Insert the check out time for the child
$query = "UPDATE checkinout
        SET `out` = :nowTime
        WHERE child_id = $var
        AND `in` IS NOT NULL";
$statement = $pdo->prepare($query);
$statement->bindValue(':nowTime', date("YmjHis"));
$statement->execute();

// Select check in time for specified child
$sql_inTime = "SELECT `in` FROM checkinout
        WHERE child_id = $var";
$inResult = $pdo->query($sql_inTime);
$inRow = $inResult->fetch();
$inTime = strtotime($inRow['in']);

// Select the check out time for specified child
$sql_outTime = "SELECT `out` FROM checkinout
        WHERE child_id = $var";
$outResult = $pdo->query($sql_outTime);
$outRow = $outResult->fetch();
$outTime = strtotime($outRow['out']);

// Find total hours
$totalTime = abs($outTime - $inTime)/(60*60);

// Update totalHours column for specified child
$queryTotalTime = "UPDATE checkinout
                SET totalTime = :totalTime
                WHERE child_id = $var
                AND 'out' IS NOT NULL";
$statement = $pdo->prepare($queryTotalTime);
$statement->bindValue(':totalTime', $totalTime);
$statement->execute();